Gmaps4Rails-自定义信息窗口不起作用
Gmaps4Rails - custom infowindow not working
我在使用Google Maps 4 rails gem在rails上实现自定义信息框时遇到了问题。我已经在页面顶部添加了infobox插件,并尝试了文档中的代码片段,但仍然没有自定义的infobox或infobox窗口上的"黄色"类。
如何将自定义信息框的选项传递给以下生成的标记?
:javascript
handler = Gmaps.build('Google');
handler.buildMap({ provider: {
}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(#{raw @hash.to_json},{builders: {Marker: InfoBoxBuilder}});
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
handler.getMap().setZoom(9);
});
我还在infowindow.js.coffee 中添加了以下代码
class InfoBoxBuilder extends Gmaps.Google.Builders.Marker # inherit from base builder
# override method
create_infowindow: ->
return null unless _.isString @args.infowindow
boxText = document.createElement("div")
boxText.setAttribute("class", 'yellow') #to customize
boxText.innerHTML = @args.infowindow
@infowindow = new InfoBox(@infobox(boxText))
infobox: (boxText)->
content: boxText
pixelOffset: new google.maps.Size(-140, 0)
boxStyle:
width: "280px"
handler = Gmaps.build 'Google', { builders: { Marker: InfoBoxBuilder} }
任何帮助都将不胜感激。非常感谢。
您误读了文档,请替换:
:javascript
handler = Gmaps.build('Google');
handler.buildMap({ provider: {
}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(#{raw @hash.to_json},{builders: {Marker: InfoBoxBuilder}});
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
handler.getMap().setZoom(9);
});
带有:
:javascript
var handler = Gmaps.build('Google', { builders: { Marker: InfoBoxBuilder} });
handler.buildMap({ internal: {id: 'map'}}, function(){
var markers = handler.addMarkers(#{raw @hash.to_json});
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
handler.getMap().setZoom(9);
});
并且class InfoBoxBuilder
应该是class @InfoBoxBuilder
才能在window
对象上访问
基本上,在gem的文档中,映射创建是在与InfoBoxBuilder
类相同的文件中定义的。您没有这样做:您在窗口中创建了处理程序。
相关文章:
- Angular$scope在模式窗口内不起作用
- JS-窗口宽度函数不起作用
- 剑道UI下拉列表在剑道窗口内不起作用
- 执行angularJS窗口警报不起作用
- FB.login有效,但弹出窗口不起作用;t关闭
- PHP变量作为Javascript弹出窗口不起作用
- 弹出窗口不起作用(未打开)Java 小程序
- 为什么简单的 JQuery 对话框/弹出窗口不起作用
- jQuery 模型弹出窗口不起作用
- ExtJS 窗口不起作用
- jQuery弹出窗口不起作用 - 简单的自定义弹出窗口
- Javascript弹出窗口不起作用
- JavaScript 确认弹出窗口不起作用
- 为什么在 Indesign 中关闭窗口不起作用
- Gmaps4Rails-自定义信息窗口不起作用
- window.focus()对父窗口不起作用
- Jquery 弹出窗口将选定的复选框值传递到父窗口不起作用
- 关闭引导弹出窗口不起作用
- 语义 UI 动态弹出窗口不起作用
- 关闭ajax弹出窗口不起作用