1

I am using the last version of GoogleMaps.Subgurim.NET dll in a C# web forms project. I was wondering how it was possible to obtain the effect of the clearOverlays() method of Google Maps v2, in v3, using that component. Let me give you an example; on the map click event I used to delete all the existing markers and then place a new one with an InfoWindow:

protected string GMap1_Click(object s, GAjaxServerEventArgs e)
        {

            GMarker marker = new GMarker(e.point);
            string strInfoWindow = string.Format(
                                             @"<b>Mytext<br> "lat = {0}<br/>lng = {1}",
                                             e.point.lat,
                                             e.point.lng);
            GInfoWindow window = new GInfoWindow(marker,
                                                 strInfoWindow,
                                                 true);

            return 
                e.map+".clearOverlays();"+
                window.ToString(e.map);
}

The only parts of the code that have to be noted are the three last lines. Could you please tell me how to change my javascript code in this scenario in order to delete all the markers ?

Thank you in advance for any help. Newcomsas

Antelion
  • 155
  • 2
  • 14

1 Answers1

1

I solved the problem. I simply push the markers created via Subgurim component into an array and then call a custom js function attached to the map control that deletes them. Here is the code for attaching the function:

       StringBuilder sb = new StringBuilder();

       sb.Append("var markersArray=[];");
       sb.Append("function clearOverlays() {");
       sb.Append("   for (var i = 0; i < markersArray.length; i++ ) {");
       sb.Append("     markersArray[i].setMap(null);");
       sb.Append("   }");
       sb.Append("   markersArray = [];");
       sb.Append("}");

       GMap1.Add(sb.ToString());

And this is how my Gmap1_Click event looks like now:

protected string GMap1_Click(object s, GAjaxServerEventArgs e)
    {
        GMarker marker = new GMarker(e.point);
        string strInfoWindow = string.Format(
                                         @"point<br />lat = {0}<br/>lng = {1}",
                                         e.point.lat,
                                         e.point.lng);
        GInfoWindow window = new GInfoWindow(marker,
                                             strInfoWindow,
                                             true);
        return
               "clearOverlays();" +
               window.ToString(e.map)+
               "markersArray.push(" + GMap1.getGMapElementById(marker.ID) + ");";
    }

Everything works fine in this way.

Antelion
  • 155
  • 2
  • 14