简体   繁体   English

GMaps.js setContextMenu

[英]GMaps.js setContextMenu

I have managed to add a context menu to a map using GMaps.js as per their example below 我设法按照下面的示例使用GMaps.js向地图添加上下文菜单

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

However I cannot seem to add a context menu to a marker. 但是,我似乎无法向标记添加上下文菜单。

Could someone post how to do this 有人可以发布如何执行此操作

Thanks 谢谢

Do you mean an infoWindow as demoed here? 您的意思是这里演示的infoWindow吗? http://hpneo.github.com/gmaps/examples/markers.html http://hpneo.github.com/gmaps/examples/markers.html

If you look at the source for that page, you'll see you just need to add 如果您查看该页面的源代码,将会看到您只需要添加

infoWindow: {
    content: '<p>HTML Content</p>'
}

to your addMarker bit, ie. 到您的addMarker位,即。 below the title. 标题下方。 It's real easy! 真的很简单! :) :)

This code work perfect for me, also if you can't see the contextMenu maybe you should try with right click it shows up the menu !! 这段代码对我来说是完美的,如果您看不到contextMenu,也可以右键单击它以显示菜单!

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

右键点击带有gmaps的地图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM