在缩放级别3的Google地图中隐藏标记 [英] Hide marker in google map at zoom level 3
问题描述
如何在缩放级别3的Google地图中隐藏标记,并且在放大(最高16级)时,我必须再次显示标记.我正在使用Google Maps JavaScript API v3.
How to hide marker in a google map in zoom level 3, and while zooming in (for upto 16th level) I have to show the marker again. I am using Google Maps JavaScript API v3.
注意:地图中只有一个标记.
Note: There is only one marker in the map.
任何人都可以帮助我完成这项工作吗?
Can any one help me to get this done?
推荐答案
您将不得不向地图添加一个 zoom_changed
事件,并检查您的地图处于哪个缩放级别并采取相应的措施.另请参阅API参考:地图事件和
You will have to add an zoom_changed
event to the map, and check which zoomlevel your map is and act accordingly. See also the API Reference: Map Events and Overlays.
部分代码(您可能要在这里或那里更新/添加一些内容):
Partial code (you might want to update / add something here and there):
var marker = new google.maps.Marker({
position: location,
map: map
});
google.maps.event.addListener(map, 'zoom_changed', function() {
var zoom = map.getZoom();
// Update May 2017
// You can now use setVisible() on a marker instead of
// setting the map to a null value.
if (zoom <= 3) {
marker.setMap(null);
} else {
marker.setMap(map);
}
});
这篇关于在缩放级别3的Google地图中隐藏标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!