我怎样才能听到用户在Google Maps v3中绘制多边形的开始? [英] How can I listen for the start of a user drawing a polygon in Google Maps v3?

查看:107
本文介绍了我怎样才能听到用户在Google Maps v3中绘制多边形的开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个polygoncomplete事件被触发,但我正在寻找一个polygonstart事件。即使是overlaystart事件也适用于我。

There's a polygoncomplete event that is fired, but I'm looking for a polygonstart event. Even an overlaystart event would work for me.

当用户开始绘制多边形时,我想要移除地图上任何现有的多边形。目前,我已经使用polygoncomplete事件实现了该功能。它需要在一开始就发生。

When the user starts to draw a polygon, I want to remove any existing polygon on the map. Currently, I have that functionality implemented using the polygoncomplete event. It needs to happen at the start though.

我的伪代码认为是...

My pseudocode thought is to...


  1. 聆听地图上的点击事件。

  2. onclick,检查选择哪个绘图工具(如果可能的话)。如果选择了多边形工具,请删除所有先前的多边形。

使用polygonstart事件会更容易。

This would be much easier with a polygonstart event.

这是一个类似的问题,但隐藏和显示绘图控件不是此ui的选项。
Google地图制图管理器限制为1个多边形

Here is a similar question, but hiding and showing the drawing controls is not an option for this ui. Google Maps Drawing Manager limit to 1 polygon

推荐答案

我今天正在聆听点击Google Map画布的问题,而且我可能发现了一个丑陋的黑客/ workaround使用jQuery:

I was wrestling with the problem of listening for clicks on the Google Map canvas today, and I may have discovered an ugly hack/workaround using jQuery:

setTimeout( function() {
  var gmDomHackSelect = $('.gm-style').children().eq(0);
  gmDomHackSelect.click(handleMapCanvasClick);
}, 3000);

这段代码来自我的map初始化函数,所以我需要一个计时器来选择元素a稍后。

This fragment of code was from my map initialisation function, so I needed a timer to select the element a little while later.

这个侦听器的优点是它直接在画布上侦听点击,即。点击地图控件(例如缩放)不会触发它。

The advantage of this listener is that it listens for click directly on the canvas, ie. clicks on map controls (eg zoom) do not trigger it.

这篇关于我怎样才能听到用户在Google Maps v3中绘制多边形的开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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