首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GMaps.js setContextMenu

GMaps.js setContextMenu
EN

Stack Overflow用户
提问于 2012-12-13 04:01:22
回答 2查看 1.3K关注 0票数 0

根据下面的示例,我已经成功地使用GMaps.js向地图添加了快捷菜单

代码语言:javascript
复制
map.setContextMenu({
  control: 'map',
    options: [{
        title: 'Add marker',
        name: 'add_marker',
        action: function(e) {
            this.addMarker({
              lat: e.latLng.lat(),
              lng: e.latLng.lng(),
              title: 'New marker'
            });
        }
    }, {
        title: 'Center here',
        name: 'center_here',
        action: function(e) {
        this.setCenter(e.latLng.lat(), e.latLng.lng());
    }
  }]
});

但是,我似乎不能向标记添加上下文菜单。

有没有人能告诉我怎么做?

谢谢

EN

回答 2

Stack Overflow用户

发布于 2015-09-17 13:01:39

这段代码非常适合我,如果你看不到contextMenu,也许你应该试试右击它会出现菜单!!

代码语言:javascript
复制
map.setContextMenu({
        control: 'map',
        options: [{
            title: 'Add marker',
            name: 'add_marker',
            action: function(e){
                this.addMarker({
                    lat: e.latLng.lat(),
                    lng: e.latLng.lng(),
                    animation: google.maps.Animation.DROP,
                    draggable:true,
                    title: 'New Marker'
                });
                this.hideContextMenu();
            }
        }, {
            title: 'Center here',
            name: 'center_here',
            action: function(e){
                this.setCenter(e.latLng.lat(), e.latLng.lng());
            }
        }]
    });
    map.setContextMenu({
        control: 'marker',
        options: [{
            title: 'Center here',
            name: 'center_here',
            action: function(e){
                this.setCenter(e.latLng.lat(), e.latLng.lng());
            }
        }]
    });

票数 1
EN

Stack Overflow用户

发布于 2012-12-14 19:50:35

你指的是这里演示的infoWindow吗?http://hpneo.github.com/gmaps/examples/markers.html

如果您查看该页面的源代码,您会发现您只需要添加

代码语言:javascript
复制
infoWindow: {
    content: '<p>HTML Content</p>'
}

到你的addMarker位,即。在标题下面。真的很简单!:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13847637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档