使用CoffeeScript为谷歌地图提供多个InfoWindows
Multiple InfoWindows for Google maps with CoffeeScript
我似乎无法让信息窗口与coffeescript一起工作。我的初始化代码创建了一个类,构造函数创建了一张谷歌地图,然后根据用户界面的需要,如果需要,我使用类的方法,如"addSingleMarkers",在地图上放置标记。标记可以正常工作,它们会正确地显示在地图上,但当我尝试为每个标记放置infoWindows时,它失败了。使用此代码一次,并且仅在第一次单击任何标记时显示一次infoWindow,其中包含该标记的正确信息,如果此infoWindow关闭,则无法再次打开。我有一系列关于javascript的红色帖子,但就是不能让它与coffeescript一起工作。我做错了什么?
class window.GoogleMap
constructor: (@canvasID = "#google_map",
@searchID = "#google_map_search",
@rectBounds = "#google_map_rect") ->
mapOptions = {
center: new google.maps.LatLng(38, 23.5),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
@gmap = new google.maps.Map($(@canvasID)[0], mapOptions) if $(@canvasID).length
true
addSingleMarkers: (data) ->
for coordinates, text of data
point_length = coordinates.length
data_array =
coordinates.substring(6,point_length).
replace('(','').replace(')','').split(" ")
point = new google.maps.LatLng(data_array[1],data_array[0])
marker = new google.maps.Marker(
position: point
map: @gmap
title: text)
@bindInfoW marker, text
bindInfoW : (marker, contentString) ->
google.maps.event.addListener marker, "click", ->
infowindow = new google.maps.InfoWindow
infowindow.setContent contentString
infowindow.open @gmap, marker
问题出在这行:google.maps.event.addListener marker, "click", ->
,它本应该是google.maps.event.addListener marker, "click", =>
。此外,我创建了一个单独的方法调用,只创建了InfoWindow的一个实例。->和=>之间存在差异。后者创建一个临时变量var_this=this,稍后将其与infoWindow 一起使用
相关文章:
- 有可能在谷歌地图api中为一个标记打开多个infoWindows吗
- Javascript中的多个标记InfoWindows
- InfoWindows正在打开而无需点击
- 如何将单独的infoWindows添加到多个谷歌地图标记
- 使用尽可能多的Google Maps infoWindows创建多个KML层
- 带有Infowindows的多个标记在谷歌地图中是不合适的
- InfoWindows with OpenLayers
- 动态添加InfoWindows和标记在谷歌地图V3
- 谷歌地图-多个InfoWindows
- 谷歌地图Javascript与InfoWindows
- 谷歌地图:多个InfoWindows总是显示最后的值
- 在Google Maps API v3中显示多个标记和方向变量的infoWindows问题
- 谷歌地图-将InfoWindows附加到数组中的多边形
- JavaScript的问题?谷歌地图.infoWindows
- 使用CoffeeScript为谷歌地图提供多个InfoWindows
- AngularJS, Google Maps and InfoWindows