Skip to content

Commit

Permalink
working multi pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
jumski committed Sep 14, 2012
1 parent 2b683e8 commit 7c3a6b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/views/map.js.coffee
Expand Up @@ -3,7 +3,7 @@ class Backbone.Widgets.Map extends Backbone.View
className: 'map'

markers: []
isInfoBoxPinned: false
pinnedMarker: null

initialize: (opts) =>
@lat = opts.lat
Expand Down Expand Up @@ -44,6 +44,13 @@ class Backbone.Widgets.Map extends Backbone.View
marker.render()
@markers.push marker

pinMarker: (marker) =>
if @pinnedMarker
@pinnedMarker.unpin()

@pinnedMarker = marker
@pinnedMarker.pin()

getBounds: =>
bounds = @gmap.getBounds()

Expand Down
27 changes: 17 additions & 10 deletions src/views/map_marker.js.coffee
Expand Up @@ -15,6 +15,8 @@ class Backbone.Widgets.MapMarker extends Backbone.View
isHidden: false
enableEventPropagation: false

pinned: false

initialize: (opts) =>
@title = opts.title
@lat = opts.lat
Expand All @@ -31,7 +33,7 @@ class Backbone.Widgets.MapMarker extends Backbone.View
getInfoBoxOpts: =>
opts = _.extend({}, @infoBoxDefaults, @infoBoxOpts)

if @map.isInfoBoxPinned
if @map.pinnedInfoBox
opts.content = @infoBoxOpts.pinnedContent
else
opts.content = @infoBoxOpts.unpinnedContent
Expand Down Expand Up @@ -68,7 +70,7 @@ class Backbone.Widgets.MapMarker extends Backbone.View
if @infoBoxOpts
opts = @getInfoBoxOpts()
@infoBox = new InfoBox(opts)
google.maps.event.addListener(@marker, 'click', @toggleInfoBoxPinned)
google.maps.event.addListener(@marker, 'click', @pinOnMap)
google.maps.event.addListener(@marker, 'mouseover', @onMouseOver)
google.maps.event.addListener(@marker, 'mouseout', @onMouseOut)

Expand All @@ -82,20 +84,25 @@ class Backbone.Widgets.MapMarker extends Backbone.View
delete @marker

onMouseOver: =>
return if @map.isInfoBoxPinned
return if @map.pinnedInfoBox
@showInfoBox()

onMouseOut: =>
return if @map.isInfoBoxPinned
return if @map.pinnedInfoBox
@hideInfoBox()

toggleInfoBoxPinned: =>
@map.isInfoBoxPinned = ! @map.isInfoBoxPinned
pinOnMap: =>
return if @pinned

if @map.isInfoBoxPinned
@infoBox.setContent @getInfoBoxOpts().content
else
@infoBox.setContent @getInfoBoxOpts().content
@map.pinMarker(@)

pin: =>
@pinned = true
@infoBox.setContent @getInfoBoxOpts().pinnedContent

unpin: =>
@pinned = false
@infoBox.setContent @getInfoBoxOpts().unpinnedContent

close: =>
@closeMarker()
Expand Down

0 comments on commit 7c3a6b5

Please sign in to comment.