Auto zoom

Mar 17, 2008 at 7:39 PM
Hi velio,
i was asking myself if its possible to zoom the map in a way to display all markers on it.
I changed the RenderMapScript method in GoogelMap.cs in the folloeing way.
When i set Zoom to -1, the bounds of all markers and the ZoomLevel to fit them in get calculated. Have you got a better solution or is it good enough?


{ /// <summary>
/// Renders the init script.
/// </summary>
/// <returns></returns>
protected virtual string RenderMapScript()
{

StringBuilder script = new StringBuilder();
//
script.Append("Artem.Web.GoogleMapManager.initialize();").AppendLine();
RenderMapContructorScript(script);
RenderMapMarkersScript(script);
RenderMapDirectionsScript(script);
RenderMapPolylinesScript(script);
RenderMapPolygonsScript(script);
if (!IsStatic)
script.AppendFormat("{0}.load();", this.ClientMapID);
else
script.AppendFormat("{0}.loadStatic();", this.ClientMapID);
//

if (this.Zoom == -1) // Autozoom
{
if (Markers.Count > 0)
{
string autoZoomScript = "";
foreach (GoogleMarker mark in Markers)
{
autoZoomScript += string.Format("bounds.extend(new GLatLng({0},{1}));", mark.Latitude.ToString(CultureInfo.CreateSpecificCulture("en-GB")), mark.Longitude.ToString(CultureInfo.CreateSpecificCulture("en-GB")));
}

script.AppendLine("var bounds = new GLatLngBounds;")
.Append(autoZoomScript)
.AppendFormat("{0}.gmap.setZoom({1}.gmap.getBoundsZoomLevel(bounds));", this.ClientMapID, this.ClientMapID)
.AppendFormat("{0}._gmap.setCenter(bounds.getCenter());", this.ClientMapID)
;
}
}
return script.ToString();
}

}
Coordinator
Mar 18, 2008 at 7:54 AM
Hi,
I see, good point.
I'll check out the case.

Regards