Anonymous user  |  Log in  |  Create Account

GMap.ToString

With the ToString method of the GMap class, you can obtain the Javascript that is going to produce our map.

Thanks to this, we simplified things like getting the Javascript that we are going to use with in a server event.

It is just enough to initialize the GMap class with GMap_Id and add all the desired elements: controls, markers, infowindows, etc. The example is totally academic (click on the map):

Code.aspx
<cc1:GMap ID="GMap1" runat="server" enableServerEvents="True" OnClick="GMap1_Click" />
Code.aspx.cs
protected string GMap1_Click(object s, GAjaxServerEventArgs e)
{
    GMap gmap = new GMap(e.map);

    // GMarker and GInfoWindow
    GMarker marker = new GMarker(e.point);
    GInfoWindow window = new GInfoWindow(marker, "Cool!!", true);
    gmap.Add(window);

    // Movement
    //gmap.Add(new GMove(1000, e.point + new GLatLng(25, 38)));
    //gmap.Add(new GMove(1000, e.point));

    // Controls
    gmap.Add(new GControl(GControl.extraBuilt.MarkCenter));
    gmap.Add(new GControl(GControl.preBuilt.LargeMapControl));
    gmap.Add(new GControl(GControl.preBuilt.MapTypeControl));

    // Polylines
    if (e.point != e.center)
    {
        List<GLatLng> points = new List<GLatLng>();
        points.Add(e.center);
        points.Add(e.point);

        gmap.Add(new GPolyline(points, Color.Yellow));
    }

    // Maybe... anything? ;)
    gmap.enableHookMouseWheelToZoom = false;
    gmap.mapType = GMapType.GTypes.Satellite;

    return gmap.ToString();
}
Powered by Subgurim.NET