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

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

问题描述

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

  1. Gizzmo 的博客
  2. Google API 提示
  3. GMap3
  4. 我是怎么得到的..

堆栈溢出问题 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个属性

  1. latLng
  2. ma
  3. 像素

其中 pixel.xpixel.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天全站免登陆