locked
webpart google maps RRS feed

  • Question

  • Hello,
    I created a VS .Net site to display points on a google map fed from a data source. I have re-worked it to work within a webpart but it never renders. I get no errors and when I debug it all seems to work. when I view source all of the JS seems to be there. I think that the problem I am having is that although the JS is there it never gets fired, I have thrown in alerts that never get hit.
    Anyway I am new to SP and I just think I am missing something. I do all the work .net side and then at the end I call this: (which I have based on code from http://www.codeproject.com/KB/web-image/Google_map.aspx?msg=3236146#xx3236146xx )

       String Locations = "";
       int count = 0;
    
       foreach (DataRow r in tbl.Rows)
       {
           string Latitude = r["Latitude"].ToString();
           string Longitude = r["Longitude"].ToString();
           string City = r["City"].ToString();
    
           Locations += Environment.NewLine + " var point" + count.ToString() + " = new GLatLng(" + Latitude + "," + Longitude + "); var marker" + count.ToString() + " = createMarker(point" + count.ToString() + ",'Dam it..... work bubble!!!!<br>And the city is: '" + "+'" + City + "'" + "); map.addOverlay(marker" + count.ToString() + ");";                
    
       }
       // create the final script and put it in a label
    js.Text = @"<script type='text/javascript'> function initialize()
    {
    <br />alert('never get here'); if (GBrowserIsCompatible())
    { var map = new GMap2(document.getElementById('map_canvas')); map.setCenter(new GLatLng(60,-95), 3); "
    + Locations + @" map.setUIToDefault(); } } function createMarker(point,html)
    {
    var marker = new GMarker(point); GEvent.addListener(marker, "
    + '"' + "click" + '"' + ", function() { marker.openInfoWindowHtml(html); }); return marker; }
    </script> "
    ;

    Thanks

    Friday, October 16, 2009 5:41 PM

Answers

  • You have to let know sharepoint to call your javascript Initialize method. To do this you need to do the following:

    <script language="javascript">  
        _spBodyOnLoadFunctionNames.push("FunctionName");    
    </script>  
    _spBodyOnLoadFunctionNames.push(func_name);
    What it does is it tells sharepoint to execute the func_name after the page load has been completed.

    You can add the above script to the master page of your sharepoint site.
    Srinivas Varukala
    • Marked as answer by daNewGuy Friday, October 16, 2009 7:19 PM
    Friday, October 16, 2009 5:59 PM

All replies

  • You have to let know sharepoint to call your javascript Initialize method. To do this you need to do the following:

    <script language="javascript">  
        _spBodyOnLoadFunctionNames.push("FunctionName");    
    </script>  
    _spBodyOnLoadFunctionNames.push(func_name);
    What it does is it tells sharepoint to execute the func_name after the page load has been completed.

    You can add the above script to the master page of your sharepoint site.
    Srinivas Varukala
    • Marked as answer by daNewGuy Friday, October 16, 2009 7:19 PM
    Friday, October 16, 2009 5:59 PM
  • Thank you! you have no idea how long I have been working on this.
    Friday, October 16, 2009 7:20 PM