Google Map V3 上下文菜单 [英] Google Map V3 context menu
问题描述
我正在寻找 Google Map V3 上下文菜单库.我在这里找到了一些代码示例
堆栈溢出问题 Google 地图 v3 - 上下文菜单可用吗? 4 月也只是想出了上面的例子.Gmap3 添加一个简单的上下文菜单也是如此.
但也许有人已经将示例封装在一个可重用的库中,或者在此期间找到了一些东西.显然有某事适用于 V2.
-- 更新于 2012-05-31 --
我找到了另一个http://googlemapsmania.blogspot.de/2012/04/create-google-maps-context-menu.html ,但还没有时间测试.
我认为您不需要为此使用库.我会先尝试:
var contextMenu = google.maps.event.addListener(地图,右键点击",功能(事件){//使用 JS Dom 方法创建菜单//使用 event.pixel.x 和 event.pixel.y//将菜单定位在鼠标位置控制台日志(事件);});
这假设您的地图是通过以下方式创建的:
var map = new google.maps.map( { [地图选项] } );
回调中的event
对象有4个属性
latLng
ma
像素
其中 pixel.x
和 pixel.y
是您的点击事件触发的偏移量 - 从包含地图对象的画布的左上角开始计算.>
I am looking for a Google Map V3 context menu library. I have found some code examples here
Stack overflow question Google maps v3 - Contextual menu available? of April also just came up with the above examples. So did Gmap3 adding a simple context menu .
But maybe somebody has encapsulated the examples in a reusable library or found something in the meantime. Obviously there was something for V2.
-- Updated 2012-05-31 --
I have found another one http://googlemapsmania.blogspot.de/2012/04/create-google-maps-context-menu.html , but did not have the time to test it yet.
I don't think you need a library for this. I'd start by trying:
var contextMenu = google.maps.event.addListener(
map,
"rightclick",
function( event ) {
// use JS Dom methods to create the menu
// use event.pixel.x and event.pixel.y
// to position menu at mouse position
console.log( event );
}
);
This assumes your map was created with:
var map = new google.maps.map( { [map options] } );
The event
object inside the callback has 4 properties
latLng
ma
pixel
where pixel.x
and pixel.y
are the offset where your click event triggered - counted from the upper left corner of the canvas holding the map object.
这篇关于Google Map V3 上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!