[英]GMaps.js setContextMenu
我设法按照下面的示例使用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());
}
}]
});
但是,我似乎无法向标记添加上下文菜单。
有人可以发布如何执行此操作
谢谢
您的意思是这里演示的infoWindow吗? http://hpneo.github.com/gmaps/examples/markers.html
如果您查看该页面的源代码,将会看到您只需要添加
infoWindow: {
content: '<p>HTML Content</p>'
}
到您的addMarker位,即。 标题下方。 真的很简单! :)
这段代码对我来说是完美的,如果您看不到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());
}
}]
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.