Google地图“裁剪” [英] Google Maps "cropping"

查看:122
本文介绍了Google地图“裁剪”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这可能听起来像一个疯狂的问题,但我在网站上有一个谷歌地图(API v3),有时我在地图上有大量的标记。是否有任何插件存在,或者编写一个(初学者代码?)会有多困难,这会让我让用户说控制命令+鼠标左键单击并按住并使其能够选择部分地图。之后当他们释放鼠标左键时,我可以启动一个可以更新我的谷歌地图以重置缩放的功能,并且只在用户选择区域内包含标记。



我真的很想尝试这个,有没有人有任何指点或想法可以帮助我?

更新



好的,这有可能吗? :)

解决方案

我相信这是可能的,但我认为有一个更好的方法来解决您的问题,即使用集群



对于裁剪,您可以:使用事件addDomListener来实现
$ b


  1. 在地图上听取'mousedown'。检查传递给处理程序的事件对象以查看是否按下了ctrl键(e.ctrlKey)。


  2. 将鼠标单击的xy坐标转换为lat lng(在地图投影中使用fromPointToLatLng)。在该位置创建一个矩形。


  3. 在地图上添加addDomListener mousemove处理程序。在处理程序中,使用setBounds调整矩形的大小。


  4. 在地图上添加addDomListener鼠标处理程序。在处理程序中抓住矩形的边界,移除矩形并调用map.fitBounds。


我还没有尝试了上述内容,但毕竟打字我会建议先尝试群集,看看它是否满足您的需求。


Okay so this may sound like a crazy question, but I have a Google Map (API v3) on a website, and at times I have a large number of markers on the map. Are there any plugins that exist, or how difficult would it be to write one, (starter code?) that would allow me to let the user say hit contrl + left mouse click and hold and enable them to "select" a portion of the map. After which when they release the left mouse button, I could fire an off a function that could update my google map to reset the zoom and only include the markers within the users selection area.

I'm really really wanting to try this, does anyone have any pointers or ideas that could help me?

UPDATE

Okay, is it even possible? :)

解决方案

I believe it is possible however I think there is a better way to solve your problem which is to use clustering.

For the cropping you could:

  1. Use event addDomListener to listen for 'mousedown' on the map. Check the event object passed to the handler to see if the ctrl key is pressed (e.ctrlKey).

  2. Convert the x y coordinates for the mouse click into a lat lng (use fromPointToLatLng on the map projection). Create a rectangle at the position.

  3. Add a addDomListener mousemove handler on the map. In the handler resize the rectangle using setBounds.

  4. Add a addDomListener mouseup handler on the map. In the handler grab the bounds of the rectangle, remove the rectangle and call map.fitBounds.

I haven't tried the above but after all that typing I would recommend trying out clustering first to see if it satisfies your needs.

这篇关于Google地图“裁剪”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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