[英]Hide marker in google map at zoom level 3
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. 如何在缩放级别3中隐藏谷歌地图中的标记,并在放大时(最多16级)我必须再次显示标记。 I am using Google Maps JavaScript API v3.
我使用的是Google Maps JavaScript API v3。
Note: There is only one marker in the map. 注意:地图中只有一个标记。
Can any one help me to get this done? 任何人都可以帮助我完成这项工作吗?
You will have to add an zoom_changed
event to the map, and check which zoomlevel your map is and act accordingly. 您必须向地图添加一个
zoom_changed
事件,并检查地图的缩放级别并采取相应措施。 See also the API Reference: Map Events and Overlays . 另请参阅API参考: 映射事件和叠加层 。
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);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.