gpt4 book ai didi

javascript - 缩小时如何隐藏标记?

转载 作者:行者123 更新时间:2023-11-29 15:43:45 26 4
gpt4 key购买 nike

我正在通过 JavaScript 开发 android 应用程序,我想知道当我使用 Google map 缩小小于 15 时如何隐藏 map 标记,这是我使用的代码:

function success1(position) {
var bangalore = { lat: 24.7511, lng: 46.6568 };
var gift = { lat: 24.7906, lng: 46.6312 };
var map = new google.maps.Map(document.getElementById('mapp'), {
zoom: 17,
streetViewControl: false,
panControl: false,
disableDoubleClickZoom: true,
TiltGestures: false,
AllGestures: false,
ZoomGestures: false,
ScrollGestures: false,
zoomControl: false,
scrollwheel: false,
center: bangalore
});
var image = 'http://iconbug.com/download/size/32/icon/7605/yellow-gift-box/';
zoom = map.getZoom();
var zoom = map.getZoom();
var beachMarker = new google.maps.Marker({
position: gift,
map: map,
icon: image,
});
}

最佳答案

删除/隐藏 marker从 map 调用 setMap() 方法,将 null 作为参数传递。

marker.setMap(null);

.setMap(null) 函数将阻止标记显示在 map 上。您还可以使用它来隐藏多边形和多段线。

google.maps.event.addListener(map, 'zoom_changed', function() { 
var zoom = map.getZoom();
if (zoom <= 15) {
marker.setMap(null);
} else {
marker.setMap(map);
}
});

Note that the above method does not delete the marker. It simply removes the marker from the map. If instead you wish to delete the marker, you should remove it from the map, and then set the marker itself to null.

关于javascript - 缩小时如何隐藏标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36244982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com