Reputation: 1763
Is it possible to zoom in by increments of 2 and zoom out by increments of 3? Essentially, I am trying to skip a certain zoom level. Example: http://jsfiddle.net/j1sr3zho/
I am trying to detect when zoom in and out events occur so I can get to what I want, but I get the Uncaught RangeError: Maximum call stack size exceeded
error.
google.maps.event.addListener(map, 'zoom_changed', function () {
if (map.getZoom() > zoom) {
map.setZoom(map.getZoom() + 2);
console.log("zoomed in");
} else if (map.getZoom() < zoom) {
map.setZoom(map.getZoom() - 3);
console.log("zoomed out");
});
If possible, I need it to work on mobile version of Google Maps too.
Upvotes: 0
Views: 112
Reputation: 4784
The problem here is the zoom_changed
listener is triggered even when you do setZoom on maps. You should try to detect if the zoom_changed is trigged by a mouse event or set a flag to prevent recursions.
Look at this updated jsfiddle, where prevent recursions by setting a flag:
{
if (flag){
flag=false;
//zoom logic
map.setZoom(newZoomLevel);
}
flag=true;
}
Upvotes: 2