백본, coffescript 및 Google지도 API로 작업하려고합니다. 지도를 렌더링하고 가운데 표식을 추가 할 수 있습니다. 지도에 마커가있는 위치 컬렉션을 추가하는 데 문제가 있습니다. 아래의 @map 객체를 응용 프로그램의 다른 부분이나 다른 부분과 공유하려면 어떻게해야합니까?백본/커피의 다른보기 기능에서 @ 맵 개체에 어떻게 액세스합니까?
addMarker에서 @map은 정의되지 않았습니다.
render: ->
$(@el).html(@template())
primary = @collection.at(@collection.length - 1)
if primary
latlng = {}
@collection.each(@appendLocation)
latlng['latitude'] = primary.attributes.latitude;
latlng['longitude'] = primary.attributes.longitude;
@renderMap(latlng)
this
renderMap: (latlng) ->
view = new Bone.Views.Map()
$('#map').append(view.render().el)
latlng = new google.maps.LatLng(latlng['latitude'], latlng['longitude'])
myOptions =
zoom: 12
center: latlng
mapTypeId: google.maps.MapTypeId.ROADMAP
@map = new google.maps.Map(view.render().el, myOptions)
marker = new google.maps.Marker({
position: latlng,
animation: google.maps.Animation.DROP,
map: @map,
title:"Hello World!"
})
@collection.each(@addMarker)
addMarker: (location)->
console.log(@map) <-----UNDEFINED
latlng = new google.maps.LatLng(location.attributes.latitude, location.attributes.longitude)
console.log location.attributes.latitude
location_marker = new google.maps.Marker({
position: latlng,
animation: google.maps.Animation.DROP,
map: @map,
title:"Hello World!"
})