本文介绍了我可以只删除 Google Maps API v3 中 POI 的弹出气泡吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

map = new google.maps.Map(document.getElementById("map"), {中心:新 google.maps.LatLng(default_latitude,default_longitude),缩放:11,mapTypeId:google.maps.MapTypeId.ROADMAP,地图类型控制:假,平移控制:假});

我知道您可以完全删除 POI.这是我的代码:

map = new google.maps.Map(document.getElementById("map"),{中心:新 google.maps.LatLng(default_latitude,default_longitude),缩放:11,mapTypeId:google.maps.MapTypeId.ROADMAP,地图类型控制:假,泛控制:假,样式:[{特征类型:poi",元素类型:标签",造型师:[{可见性:关闭"}]}]});

这完全消除了一切,我仍然希望看到标签,因为我认为它们带来了价值,但只是认为泡沫太分散注意力了.

参考这里是我要删除的气泡:

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

解决方案

编者注:此答案适用于 3.23 版之前.从 2016 年发布的 3.24 版本开始,您可以使用 clickableIcons 地图选项.查看 xomena 的回答.>

版本 ~3.12 修复.演示

这是一个再次起作用的新补丁.我已经用 3.14 版测试过了.

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

function fixInfoWindow() {//这里我们重新定义了 set() 方法.//如果地图选项调用它,我们隐藏信息窗口,如果noSuppress"//选项不正确.由于谷歌地图不知道这个选项,//它的 InfoWindows 将不会被打开.var set = google.maps.InfoWindow.prototype.set;google.maps.InfoWindow.prototype.set = function (key, val) {if (key === 'map' && ! this.get('noSuppress')) {console.warn('这个信息窗口被抑制了.');console.log('要启用它,请将noSuppress"选项设置为 true.');返回;}set.apply(this, arguments);}}

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

var popup = new google.maps.InfoWindow({内容:'砰!',noSuppress: 真});popup.setPosition(new google.maps.LatLng(-34.397, 150.644));弹出窗口(地图);

或:

var popup = new google.maps.InfoWindow({内容:'砰!',});popup.set('noSuppress', true);popup.setPosition(new google.maps.LatLng(-34.397, 150.644));弹出窗口(地图);

So I'm working on a new web app that has a big focus on maps. Using Google Maps API v3 and really happy with it but noticed that the points of interest (POI's) have automatically bubbles with more details and a link to the Google Places page. I don't want these. Here is my code:

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
});

I know you can remove the POI's entirely. Here is my code for that:

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"
        }]
    }]
});

This removes everything entirely and I still would like to see the labels as I think they bring value but just think the bubbles are too much of a distraction.

For reference here is the bubble I want to remove:

And here is the same map with POI's removed entirely:

解决方案

Editor's note: this answer was applicable until version 3.23. Since version 3.24 released in 2016, you can use clickableIcons map option. See xomena's answer.

Here is a new patch that works again. I have tested it with version 3.14.

Now we gonna patch set() instead of 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);
    }
}

What you have to do is set option noSuppress to true for your own InfoWindow's in order to open them, for example:

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

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

popup.open(map);

or:

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);

这篇关于我可以只删除 Google Maps API v3 中 POI 的弹出气泡吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:48