Google Map V3上下文菜单 [英] Google Map V3 context menu

查看:138
本文介绍了Google Map V3上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找Google Map V3上下文菜单库。我在这里找到了一些代码示例


  1. Gizzmo的博客

  2. Google API提示

  3. GMap3

  4. 我是怎么得到的。 。

堆栈溢出问题 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个物业


  1. latLng

  2. ma

  3. 像素

其中 pixel.x pixel.y 是您点击的偏移量触发的事件 - 从拿着地图对象的画布的左上角计数。


I am looking for a Google Map V3 context menu library. I have found some code examples here

  1. Gizzmo's blog
  2. Google API tips
  3. GMap3
  4. How I got ..

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

  1. latLng
  2. ma
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆