Google Map API script on load

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
1/29/2011 9:08:57 AM
Gravatar
Total Posts 32

Google Map API script on load

Dear members,

for a specific custom module we create a Google Map which we populate with markers from our database.

These markers have EventListerner so when a user click on it more info is shown.

This all works fine in a normal web project however as module in Mojo we have the problem that we need some script to be started in the body load method how can we do this without changing the core?

In a normal aspx page

<head runat="server">
    <title>Untitled Page</title>
     <%--Google API reference--%>
    <script src="http://maps.google.com/maps?file=api&amp;v=3&amp;sensor=false
                 &amp;key=abcdefg" type="text/javascript">
    </script>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body onload="initialize()" onunload="GUnload()">

Last part of the script we create and need to insert

 js.Text = @"<script type='text/javascript'>
                            function initialize() {
                              if (GBrowserIsCompatible()) {
                                var map = new GMap2(document.getElementById('map_canvas'));
                                map.setCenter(new GLatLng(45.05,7.6667), 2);
                                " + Locations + @"
                                map.setUIToDefault();
                              }
                            }
                            </script> ";

 

Any suggestions?

Peter

1/30/2011 7:49:50 AM
Gravatar
Total Posts 18439

Re: Google Map API script on load

There are a number of ways to do it. You could use ClientScript.RegisterStartupScript, or you could use jQuery like this:

$(document).ready(function() {
  // call your method here.
});

Hope it helps,

Joe

You must sign in to post in the forums. This thread is closed to new posts.