我正在使用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
发布评论