【发布时间】:2024-01-16 02:44:01
【问题描述】:
我能够以这种格式在 index.html.erb 文件中添加标记簇。当我决定添加 infowindows 时,我的地图开始崩溃。
<script type = "text/javascript">
handler = Gmaps.build('Google',
{markers:
{clusterer: {
gridSize: 60,
maxZoom: 20,
styles: [ {
textSize: 10,
textColor: '#ff0000',
url: 'assets/creative/m1.png',
height: 60,
width: 60 }
, {
textSize: 14,
textColor: '#ffff00',
url:'assets/creative/m2.png',
height: 60,
width: 60 }
, {
textSize: 18,
textColor: '#0000ff',
url: 'assets/creative/m3.png',
width: 60,
height: 60}
]}}}
);
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
当我将 infowindows 添加到我的 custom.js.coffee 文件下的 Web 应用程序时
class InfoBoxBuilder extends Gmaps.Google.Builders.Marker
create_infowindow: ->
return null unless _.isString @args.infowindow
boxText = document.createElement("div")
boxText.setAttribute('class', 'panel panel-green')
boxText.innerHTML = @args.infowindow
@infowindow = new InfoBox(@infobox(boxText))
infobox: (boxText)->
content: boxText
pixelOffset: new google.maps.Size(-140, 0)
boxStyle:
width: "280px"
@buildMap = (markers)->
handler = Gmaps.build 'Google', { builders: { Marker: InfoBoxBuilder}
}
handler = Gmaps.build 'Google', { builders: { markers:
{clusterer: {
gridSize: 60,
maxZoom: 20,
styles: [ {
textSize: 10,
textColor: '#ff0000',
url: 'assets/creative/m1.png',
height: 60,
width: 60 }
, {
textSize: 14,
textColor: '#ffff00',
url:'assets/creative/m2.png',
height: 60,
width: 60 }
, {
textSize: 18,
textColor: '#0000ff',
url: 'assets/creative/m3.png',
width: 60,
height: 60}
]}}} } #dependency injection
handler.buildMap { provider: {}, internal: {id: 'map'} }, ->
markers = handler.addMarkers(markers)
handler.bounds.extendWith(markers)
handler.fitMapToBounds()
我让标记集群正常工作,但我丢失了信息窗口格式。如何将 infowwindow 和标记群集代码注入 custom.coffee.js 文件。
【问题讨论】:
-
请阅读Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - 总结是这不是解决志愿者的理想方式,并且可能会适得其反。请不要将此添加到您的问题中。
标签: javascript ruby-on-rails google-maps coffeescript gmaps4rails