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

How to...

ToString

As you have seen in several examples, sometimes the the ToString method of several components of the GoogleMaps.Subgurim.NET is used (GMarker, GInfoWindow, GLatLng, etc.). In fact, in the source code of the control, it is used continuously.

Mainly, what we get with the ToString method of each element is to write the equivalent Javascript from the official Google API.

You might use these methods when calling GMaps.Subgirum.Net "client events", "server events" or "custom Javascript". When it is necessary to use the actual Javascript of a component, the ToString method of each element will allow you to avoid learning the Javascript of the Google API, diminishing the necessary Javascript. In addition, and this is very important, this avoids to have to find out the Javascript ID of each element.

For example, if we wanted to recreate the infoWindow with icon from the example "InfoWindow with icon", we have two options:

Using Javascript
var marker_subgurim_Id = new GMarker(new GLatLng(10.2,22));
my_GMapSubgurim_Id.addOverlay(marker_subgurim_Id);
GEvent.addListener(marker_subgurim_Id, "to mouseover", function() {marker_subgurim_Id.openInfoWindowHtml('Example of < b>infoWindow</b >');});
my_GMapSubgurim_Id.openInfoWindowHtml('Example of < b>infoWindow</b > ');


Using the ToString method
GInfoWindow window = new GInfoWindow(
    new GMarker(new GLatLng(10.2, 22)), "Example of < b>infoWindow</b >",
    true, GListener.Event.mouseover);
string result = window.ToString(GMap1.GMap_Id);


As we see, we saved ourselves the need to learn the corresponding Javascript, we make use of IntelliSense (which makes writing code very fast) and avoided finding out the Javascript IDs of the objects...

Absolutely all the elements that can be found in the GoogleMaps.Subgurim.NET have the ToString method, and its functionality is always the same: to translate the component to Javascript.

Finally, it is extremely important to review that to use the ToString method, it is necessary to pass the ID of the source to which they are assigned. Usually it is the host Google Map, usually it is GMap1.GMap_Id.
Powered by Subgurim.NET and Comunactivo