Gmaps4Rails中的多边形infowindows

编程入门 行业动态 更新时间:2024-10-27 16:39:23
本文介绍了Gmaps4Rails中的多边形infowindows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用gmap4rails绘制一些相当复杂的多边形作为区域边界。我有两件事情需要帮助:

首先,我想将点击时的信息窗口与这些多边形相关联。这是我用例的一个例子: https:// google -developers.appspot/maps/documentation/javascript/examples/polygon-arrays

我试过在gmap的回调中注册一个click事件处理函数但它不起作用,我不认为这是正确的方法。

Gmaps.map.callback = function() { console.log('sup ); var infowindow = new google.maps.InfoWindow ({ content:'you clicked me!', suppressMapPan:true }); google.maps.event.addListener(Gmaps.map.polygons [0],'click',function() { console.log(click event fired); infowindow.open(map,Gmaps.map.polygons [0]); }); }

其次,我希望能够更改在某些用户事件上通过jQuery填充这些多边形的颜色(例如,用户点击复选框)。

解决方案

将您的方法替换为:

Gmaps.map.callback = function() { console.log('sup); Gmaps.map.polygons [0] .infowindow = new google.maps.InfoWindow ({ content:'you clicked me!'}); google.maps.event.addListener(Gmaps.map.polygons [0] .serviceObject,'click',function(event) { console.log(the点击事件触发); infowindow = Gmaps.map.polygons [0] .infowindow; infowindow.setPosition(event.latLng); infowindow.open(Gmaps.map.map) ; });

然后更改这个gem的js行换成真实的而不是假的。由于我不喜欢光标更改,因此我设置为false。无论如何,它应该在配置选项。请在github上创建一个问题,以便我记得修复它。

I'm using gmap4rails to draw a bunch of fairly complicated polygons that serve as district boundaries. I've got two things i would like help with:

Firstly, I want to associate an info window on click with these polygons. This is an example of my use-case: google-developers.appspot/maps/documentation/javascript/examples/polygon-arrays

I've tried registering a click event handler in the gmap's callback but it doesn't work and I don't think it's the right approach.

Gmaps.map.callback = function() { console.log("'sup"); var infowindow = new google.maps.InfoWindow ({ content: 'you clicked me!', suppressMapPan:true }); google.maps.event.addListener(Gmaps.map.polygons[0], 'click', function() { console.log("the click event fired"); infowindow.open(map, Gmaps.map.polygons[0]); }); }

Secondly, I'd like to be able to change the fill-color of these polygons via jquery on some user-events (user clicks a checkbox for example). How would I go about that using the gem?

解决方案

Replace your method with:

Gmaps.map.callback = function() { console.log("'sup"); Gmaps.map.polygons[0].infowindow = new google.maps.InfoWindow ({ content: 'you clicked me!' }); google.maps.event.addListener(Gmaps.map.polygons[0].serviceObject, 'click', function(event) { console.log("the click event fired"); infowindow = Gmaps.map.polygons[0].infowindow; infowindow.setPosition(event.latLng); infowindow.open(Gmaps.map.map); }); }

And change this gem's js line to put true instead of false. I did set to false since I didn't like the cursor change. Anyway it should be in configuration options. Please create an issue on github so that I remember to fix it.

更多推荐

Gmaps4Rails中的多边形infowindows

本文发布于:2023-08-02 00:08:55,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多边形   Gmaps4Rails   infowindows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!