Help us translate this website and improve this translation and earn free licenses!
Anonymous user  |  Log in  |  Create Account

Custom Javascript

We will use "CustomJavascript" to add our own Javascript.

The CustomJavascript handles events and modifies the map after events. That is to say, with the CustomJavascript we will add the Javascript that will be executed (for example) to respond to a button click. However, the Javascript added will never be executed when loading the map itself: for that we have CustomInsideJavascript

To use CustomJavascript, we will have to use the method "ToString()" to output elements of our control in Javascript for the Google API. For example, the GMarker.

We can see it better in the example. In this example, we can add icons to the center of the map, erase the last icon added, or erase all the icons that are there.




Code.aspx
<cc1:GMap ID="GMap1" runat="server" />
<input type="button" id="Button1" value="Añadir icono" onclick="subgurim_Add()" />
<input type="button" id="Button2" value="Borrar último icono" onclick="subgurim_Delete()" />
<input type="button" id="Button3" value="Borrar todos los iconos" onclick="subgurim_Remove()" />
Code.aspx.cs
System.Text.StringBuilder sb = new System.Text.StringBuilder();

GLatLng center = new GLatLng(44, 5);
GMap1.setCenter(center);

sb.Append("var active;");
sb.Append("function subgurim_Add()");
sb.Append("{");
GMarker marker = new GMarker(GMap1.GMap_Id + ".getCenter()");
sb.Append(marker.ToString(GMap1.GMap_Id));
sb.AppendFormat("active = {0};", marker.ID);
sb.Append("}");

sb.Append("function subgurim_Delete()");
sb.Append("{");
sb.AppendFormat("{0}.removeOverlay(active);", GMap1.GMap_Id);
sb.Append("active = false;");
sb.Append("}");

sb.Append("function subgurim_Remove()");
sb.Append("{");
sb.AppendFormat("{0}.clearOverlays();", GMap1.GMap_Id);
sb.Append("active = false;");
sb.Append("}");

GMap1.Add(sb.ToString());
Powered by Subgurim.NET