gpt4 book ai didi

javascript - 我可以只删除 Google Maps API v3 中 POI 的弹出气泡吗?

转载 作者:IT王子 更新时间:2023-10-29 03:16:57 26 4
gpt4 key购买 nike

所以我正在开发一个新的网络应用程序,该应用程序主要关注 map 。使用 Google Maps API v3 并非常满意,但注意到兴趣点 (POI) 会自动显示更多详细信息和指向 Google Places 页面的链接。我不要这些这是我的代码:

map = new google.maps.Map(document.getElementById("map"), {
center:new google.maps.LatLng(default_latitude,default_longitude),
zoom:11,
mapTypeId:google.maps.MapTypeId.ROADMAP,
mapTypeControl:false,
panControl:false
});

我知道您可以完全删除兴趣点。这是我的代码:

map = new google.maps.Map(document.getElementById("map"),{
center:new google.maps.LatLng(default_latitude,default_longitude),
zoom:11,
mapTypeId:google.maps.MapTypeId.ROADMAP,
mapTypeControl:false,
panControl:false,
styles:[{
featureType:"poi",
elementType:"labels",
stylers:[{
visibility:"off"
}]
}]
});

这完全消除了所有内容,我仍然希望看到标签,因为我认为它们带来了值(value),但我只是认为气泡太分散注意力了。

供引用,这里是我要删除的气泡:

Example

这是完全删除了 POI 的同一张 map :

Example

最佳答案

编者注:此答案适用于版本 3.23。自 2016 年发布 3.24 版本以来,您可以使用 clickableIcons map 选项。 See xomena's answer .

Version ~3.12 fix. Demo

这是一个可以再次使用的新补丁。我已经用 3.14 版本测试过了。

现在我们要修补 set() 而不是 open()

function fixInfoWindow() {
// Here we redefine the set() method.
// If it is called for map option, we hide the InfoWindow, if "noSuppress"
// option is not true. As Google Maps does not know about this option,
// its InfoWindows will not be opened.

var set = google.maps.InfoWindow.prototype.set;

google.maps.InfoWindow.prototype.set = function (key, val) {
if (key === 'map' && ! this.get('noSuppress')) {
console.warn('This InfoWindow is suppressed.');
console.log('To enable it, set "noSuppress" option to true.');
return;
}

set.apply(this, arguments);
}
}

您需要做的是将您自己的InfoWindow 的选项noSuppress 设置为true 以打开它们,例如:

var popup = new google.maps.InfoWindow({
content: 'Bang!',
noSuppress: true
});

popup.setPosition(new google.maps.LatLng(-34.397, 150.644));

popup.open(map);

或:

var popup = new google.maps.InfoWindow({
content: 'Bang!',
});

popup.set('noSuppress', true);
popup.setPosition(new google.maps.LatLng(-34.397, 150.644));

popup.open(map);

关于javascript - 我可以只删除 Google Maps API v3 中 POI 的弹出气泡吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7950030/

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