Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps API V3: Zoom out breaks pan limitation; workaround?
    primarykey
    data
    text
    <pre><code>function initialize() { var latlng = new google.maps.LatLng(37.7702429, -122.4245789); var myOptions = { zoom: 3, center: latlng, disableDefaultUI: false, mapTypeId: google.maps.MapTypeId.TERRAIN, }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); // Limit panning // Latitude bounds for map, longitude not important var southWest = new google.maps.LatLng(-85.000, -122.591); var northEast = new google.maps.LatLng(85.000, -122.333); var allowedBounds = new google.maps.LatLngBounds(southWest, northEast); // Add a move listener to restrict the bounds range google.maps.event.addListener(map, "center_changed", function() {checkBounds(); }); //If zoom out at bound limit then map breaks; center doesn't change but bounds get broken. Listen for zoom event and try to correct bound break. **Doesn't Work** google.maps.event.addListener(map, 'zoom_changed', function() {checkBounds(); }); // If the map position is out of range, move it back function checkBounds() { // Perform the check and return if OK if ((allowedBounds.getNorthEast().lat()&gt;(map.getBounds().getNorthEast().lat()))&amp;&amp;(allowedBounds.getSouthWest().lat()&lt;(map.getBounds().getSouthWest().lat()))) { lastValidCenter = map.getCenter(); lastValidZoom = map.getZoom(); return; } // not valid anymore =&gt; return to last valid position map.panTo(lastValidCenter); map.setZoom(lastValidZoom); } } </code></pre> <p>Basically I don't want the user to be able to see anything outside of the map, so I have restricted the latitudinal bounds. Works normally.</p> <p>The issue is that if a user we to be viewing close to the bound limits and then zooms out so that the center doesn't change, but now the view-port bounds are outside of the bound limit, it does not correct and the map becomes unpannable.</p> <p>Any help you geniuses can offer is mucho appreciated .</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload