Google Map V3上下文菜单 [英] Google Map V3 context menu
问题描述
我正在寻找Google Map V3上下文菜单库。我在这里找到了一些代码示例
堆栈溢出问题 4月份的谷歌地图v3 - 上下文菜单可用?也只是提出了上述例子。因此, Gmap3添加了一个简单的上下文菜单。
但也许有人将这些例子封装在可重用的库中,或者在此期间找到了某些东西。显然有 为V2。
- 更新2012-05-31 -
我发现另一个 http://googlemapsmania.blogspot.de/2012/04/ create-google-maps-context-menu.html ,但没有时间去测试它。 解决方案
我不认为你需要一个这样的图书馆。我开始尝试:
var contextMenu = google.maps.event.addListener(
map,
rightclick,
function(event){
//使用JS Dom方法创建菜单
//使用event.pixel.x和event.pixel.y
//将菜单定位在鼠标位置
console.log(event);
}
);
假设您的地图是使用以下方式创建的:
var map = new google.maps.map({[map options]});
回调中的事件
对象有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屋!