javascript - Update bounds based on zoom level for Google Maps API - Revised -


I am creating a custom map and setting boundaries on its edge, but when the zoom level was changed I have tried to solve those edges, but I have tried to solve them, but they have the same problem.

You can see the same issues from @Aiken from this Bela, you can just pan over one edge and then zoom in some time, the map will start cutting on the edges.

P> Here is my code:

  var map; window.onload = function () {// our custom map types var customMapType = Define new google.maps.ImageMapType ({getTileUrl: function (coord, zoom) {var normalizedCoord = getNormalizedCoord (coord, zoom), if (normalizedCoord & Amp; amp; (normalizedCoord.x & lt; Math.pow (2, zoom)) & amp; amp; (normalizedCoord.x> -1) & amp; (normalizedCoord.y & LT; Math.pow (2, zoom)) & amp; Amp; (generalized code. A & gt; -1)) {return zoom + '_' + normalized code.x + '_' + normalized code.i + ' .jpg ';} and' Return 'empty.jpg';}}, tile size: new google.maps.size (256, 256), max zoom: 4, name: 'title'}); New google.maps.LatLng (0, 0), zoom: 2, minZoom: 2, streetViewControl: false, mapTypeControl: false, mapTypeControlOptions: our maps bridesmaid myOptions = {// basic options for center {mapTypeIds: [ "custom" ]}}; // Enter the map and map our custom map type to it map = new google.maps.Map (document.getElementById ('map'), myOptions); Map.mapTypes.set ('custom', customMapType); Map.setMapTypeId ('custom'); // force went permitted desired area limits = new google.maps.LatLngBounds (new google.maps.LatLng (-75.716, -90), New google.maps.LatLng (75.716, 90)); On boundLimits = {maxLat :. AllowedBounds.getNorthEast () lat (), maxLng: allowedBounds.getNorthEast () LNG (), minLat :. AllowedBounds.getSouthWest () lat (), minLng: .. AllowedBounds.getSouthWest () LNG ()}; Var lastValidCenter = map.getCenter (); Var newLat, newLng; GooglekmapskeventkaddListener (map, 'center_changed', function () {Center = MapkgetCenter (); if (Allowed Bengal Kansents (Center)) {// still within legal limits, the final legal status Save lastValidCenter = map.getCenter (); return;} newLat = lastValidCenter.lat (); newLng = lastValidCenter.lng (); if & (center.lng () gt; boundLimits.minLng & amp; & amp; center.lng () of & lt; boundLimits .maxLng) {newLng = center.lng ();} if (center.lat () & gt; boundLimits.minLat & amp; & amp; center.lat () of & lt; boundLimits. MaxLat) {newLat = center.lat ();} Map.panTo (new google.maps.LatLng (newLat, newLng))}); // warning (map.getCenter ()); } Function getBoundsM () {warning (map.getBounds ()); }  Edit : The map that I had finished was changing to a small size and added around the original map and background. It gave the impression that there was no need to pan beyond the bounds of the search area, more than a 'smoke and mirror' things, but it works for my needs.   

Your script map center to stay inside a latitude / lawn boundary It depends on the zoom level, how many maps you can see about . If the map spans 1000 km in the underlined for a given zoom level, then you can see the east-most point allowed forces. Genthanh East (). Lng () + 500km . If you reduce the zoomed and spanned area by up to 500 km, then the east-most point becomes allowing Bounds.getNorthEast (). Lng () + 250 km and more.

You think that the user is able to see what is enabled, i.e. to restrict the location of the map's boundary rather than its center. For this, you have to check whether the map.getBounds (). GetNorthEast () and map.getBounds (). GetSouthWest () are within permissions limits.

This is an updated JS field that does this note that you can still zoom out in an area which is larger than approved bonus , but now at that zoom level Will not be able to go:


Comments