jmelosegui / GooglemapMvc

The control wraps Google maps API simplifying the use of Google maps in ASP.NET MVC applications.
MIT License
116 stars 61 forks source link

How to set map bounds #138

Open Pugglewuggle opened 7 years ago

Pugglewuggle commented 7 years ago

Is there a way to set the map bounds like you can in the Gmaps JS API? I have a set of bounds... can I set the map to use those instead of setting a static zoom level and center?

jmelosegui commented 7 years ago

does this sample help?

http://www.jmelosegui.com/map/marker/FitToMarkersBounds

Pugglewuggle commented 7 years ago

Hi, Isn't that only for markers? I actually need to set the bounds to set of coordinates - though there will be no markers on the map for the coordinates.

Pugglewuggle commented 7 years ago

I've tested and confirmed that this only works on markers. If there is a way to do it with a polygon I can always just make a transparent polygon to do it with.

Pugglewuggle commented 7 years ago

Or, is there a way to toggle marker visibility but still have the fit to marker bounds work? Or should I just use a custom icon with a transparent 1x1 png for the bounds markers to mark each corner?

Pugglewuggle commented 7 years ago

Well, this actually doesn't work very well (the invisible marker method) because I have markers that exist slightly outside the bounds box - since the fit to bounds doesn't actually set the view port of the map to the same as the bounds box - it adds padding.

Pugglewuggle commented 7 years ago

This is what I'm looking for - the ability to define custom bounds to the map.

var latlngbounds = new google.maps.LatLngBounds();
            for (var i = 0; i < cwc2011_country_data.length; i++) {
                for (var j = 0; j < cwc2011_country_data[i].latlngs.length; j++) {
                    latlngbounds.extend(cwc2011_country_data[i].latlngs[j]);
                }
            }
            map.fitBounds(latlngbounds);
Pugglewuggle commented 7 years ago

I got around this by using the Google JS API calls instead of doing it through this control. This functionality would still be nice though.