我正在努力尝试将爬行器https://github.com/jawj/OverlappingMarkerSpiderfier与https://github.com/apneadiving/Google-Maps-for-Rails集成在一起
在我的map.html.haml中:
= gmaps(:markers => {:data => @map, :options => { "rich_marker" => true, :raw => '{ animation: google.maps.Animation.DROP }' } }, :map_options => { :draggable => true, :auto_zoom => false, :zoom => 9, :disableDefaultUI => false, :scrollwheel => true, :disableDoubleClickZoom => true, :custom_infowindow_class => "province" })
- content_for :scripts do
:javascript
Gmaps.map.infobox = function(boxText) {
return {
content: boxText
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-140, -50)
,alignBottom: true
,zIndex: 999
,hideCloseButton: false
,boxStyle: {
background: "white"
,width: "280px"
,padding: "10px"
,border: "1px solid #b2b2b2"
,arrowStyle: 0
,arrowPosition: 50
,arrowSize: 20
}
,infoBoxClearance: new google.maps.Size(10, 10)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
}};这很好用,但是如何集成爬行器https://github.com/jawj/OverlappingMarkerSpiderfier#how-to-use呢?
发布于 2015-03-16 23:28:11
这是一个使用旧版本的Gmap 4 Rails的老问题,但是对于任何对在最新版本中使用这两个库感兴趣的人来说,这里是如何做到这一点的。
此示例基于documentation sample code
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers([
{
"lat": 0,
"lng": 0,
"picture": {
"url": "https://addons.cdn.mozilla.net/img/uploads/addon_icons/13/13028-64.png",
"width": 36,
"height": 36
},
"infowindow": "hello!"
}
]);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
// Create a OverlappingMarkerSpiderfier instance
var oms = new OverlappingMarkerSpiderfier(handler.getMap(), {
keepSpiderfied: true
// Other options you need
});
// Track each marker with OMS
_.each(markers, function(marker) {
oms.addMarker(marker.getServiceObject());
});
});这里最重要的是深入了解Gmaps4Rails包装在自己的类中的原生Google对象。
如果您需要在标记上使用单击事件,请按照in the doc的说明向oms添加一个处理程序。
https://stackoverflow.com/questions/17868290
复制相似问题