How do I detect when a user is at the maximum zoom level? (google maps v3)
I am clustering my markers together. When a user zooms in to the highest level I need to break the clusters up so that the user can view information for individual items. Given that the number of zoom levels is different depending on the type of map used and that 'maxZoom' may have been explicitly set in mapOptions, how do I detect when the user cannot zoom any further (i.e. the zoom slider is at its highest point)? Is there just a zoom level number I can use for this (21 perhaps)? Or is this number variable depending on diffe开发者_开发问答rent scenarios? What would these scenarios be?
I do not need to know this value prior to zooming in: only when the user REACHES the max level.
google maps api have a service for that, you could use it like that:
(new google.maps.MaxZoomService()).getMaxZoomAtLatLng(map.getCenter(), function(response) {
if (response.status != google.maps.MaxZoomStatus.OK) {
alert("Error in MaxZoomService");
return;
} else {
if (map.getZoom() >= response.zoom) {
//do sth with your clusterer
//probably markerClusterer.setMaxZoom(response.zoom - 1);
//or markerClusterer.setMap(null);
}
}
});
EDIT: there is also a solution I found in markerclusterer.js (from google maps utility library), but it recently started to cause errors and I am not sure if it is reliable:
map.mapTypes[map.getMapTypeId()].maxZoom;
From a quick test, looks like z=19 is the most zoomed in before you get to street view level. Tested in a couple of countries, it hasn't changed.
Most city maps will zoom to 18, but some go beyond that, and there are isolated satellite views up to level 23.
精彩评论