getBoundsZoomLevel is missing. How to...

Jul 6, 2009 at 12:18 PM

It looks like the useful getBoundsZoomLevel function is missing in this control, so I wonder if anyone has a suggestion how to get the correct zoom level to show a given GoogleBounds.

Any ideas?

Thanks!

Coordinator
Jul 7, 2009 at 11:50 AM
Edited Jul 7, 2009 at 11:50 AM

Hi,

It is not really missing if there is not implemented a wrapper function getBoundsZoomLevel of Artem.Web.GoogleMap JS class.
Just I have implemted a wrapper function at some point and till there I have not actualize them.
But at any time you can use the origin Google Map API object wrapped by Artem.Web.GoogleMap - GMap and invoke that function.

For example if your GoogleMap has ID GoogleMap1 on you page you could use a JS code like:

GoogleMap1.GMap.getBoundsZoomLevel();

Regards

Jun 24, 2010 at 4:37 AM
Edited Jun 24, 2010 at 4:38 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("<script>").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("</script>").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.
Jan 27, 2011 at 2:59 PM
ryan_ca1 wrote:
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("<script>").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("</script>").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.

Thanks to ryan_ca1, I was able to easily get this going...  First thing is to make sure you're getting your Min/Max Lat/Long (named ndMinLat, etc below)...

Also, I added it to the OnClientMapLoad rather than a separate call/function and fixed some little issues I found with his script (if your control isn't named map).  Just change "GoogleMap1" to your map id below and you're set!) have been fixed below in a VB version:

                Dim sbZoomMapScript As New StringBuilder
                With sbZoomMapScript
                    .AppendFormat("var sw = new GLatLng({0}, {1});", ndMinLat, ndMinLong).AppendLine()
                    .AppendFormat("var ne = new GLatLng({0}, {1});", ndMaxLat, ndMaxLong).AppendLine()
                    .AppendFormat("var bounds = new GLatLngBounds(sw, ne);").AppendLine()
                    .AppendFormat("var zoomLevel = {0}.GMap.getBoundsZoomLevel(bounds);", GoogleMap1.ClientID).AppendLine()
                    .AppendFormat("{0}.GMap.setZoom(zoomLevel);", GoogleMap1.ClientID).AppendLine()
                End With

                '\\ set the map to call zoomMap javascriptFunction
                Me.GoogleMap1.OnClientMapLoad &= sbZoomMapScript.ToString