4
Vote

Request Access to Google getBoundsZoomLevel

description

I see that the getBoundsZoomLevel function exists in the ArtemGoogle.js file, however it is not accessible from the control. I'm not quite sure how to add this functionality, but I think that many people would find it useful. Can you please help me get this working?

Oh, and fantastic product! Keep up the good work.

Cheers.

comments

ryan_ca1 wrote Jun 24, 2010 at 5:39 AM

I was able to get this to work after a few hours of banging my head on the desk, so I'm sharing in case anyone else is stuck.

My control is named map.



// set the center
map.Latitude = latCenter;
map.Longitude = lonCenter;

// set the map to call zoomMap javascriptFunction
map.OnClientMapLoad = "zoomMap";

// build zoomMap javascript function. I already know what my bounds are
StringBuilder script = new StringBuilder();
script.AppendFormat("").AppendLine();
script.Append("function zoomMap() {").AppendLine();
script.AppendFormat("var sw = new GLatLng({0}, {1});", latMin, lonMin).AppendLine();
script.AppendFormat("var ne = new GLatLng({0}, {1});", latMax, lonMax).AppendLine();
script.AppendFormat("var bounds = new GLatLngBounds(sw, ne);").AppendLine();
script.AppendFormat("var zoomLevel = map.GMap.getBoundsZoomLevel(bounds);").AppendLine();
script.AppendFormat("map.GMap.setZoom(zoomLevel);", map.ClientID).AppendLine();
script.Append("}").AppendLine();
script.AppendFormat("").AppendLine();


Page.RegisterClientScriptBlock("map", script.ToString());



Thats it, the map will call the javascript after it loads and it will be automatically zoomed to the bounds.