Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Last active January 3, 2016 03:29
Show Gist options
  • Save StevenLangbroek/8402369 to your computer and use it in GitHub Desktop.
Save StevenLangbroek/8402369 to your computer and use it in GitHub Desktop.
Maps for MarionetteJS (not production ready, will probably refactor a couple of times)
@App.module 'MapApp', (MapApp, App, Backbone, Marionette, $, _) ->
@startWithParent = false
API =
showMap: ->
new MapApp.List.Controller
@on 'start', ->
API.showMap()
@App.module 'MapApp.List', (List, App, Backbone, Marionette, $, _) ->
class List.Controller extends Marionette.Controller
initialize: ->
App.request 'offices:entities', (offices) =>
@listOffices offices
getListOffices: (offices) ->
new List.View
collection: offices
listOffices: (offices) ->
view = @getListOffices(offices)
App.mapsRegion.show view
@App.module 'MapApp.List', (List, App, Backbone, Marionette, $, _) ->
class List.Marker extends Marionette.ItemView
template: ''
render: ->
App.vent.trigger 'maps:add:marker', @model
class List.View extends Marionette.CollectionView
template: ''
itemView: List.Marker
itemViewEventPrefix: 'marker'
initialize: (options) ->
@map = new google.maps.Map document.getElementById('maps_region'),
zoom: 2
center: new google.maps.LatLng(0, 0)
mapTypeId: google.maps.MapTypeId.ROADMAP
@infoWindow = new google.maps.InfoWindow()
@listenTo App.vent, 'maps:add:marker', (model) =>
@placeMarker model
placeMarker: (model) ->
latLng = new google.maps.LatLng model.get('lat'), model.get('long')
marker = new google.maps.Marker
position: latLng
map: @map
title: model.get 'title'
google.maps.event.addListener marker, 'click', (e) ->
window.location.href = model.get 'url'
@App.module 'Entities', (Entities, App, Backbone, Marionette, $, _) ->
class Entities.Office extends Backbone.Model
urlRoot: '/json/office'
class Entities.Offices extends Backbone.Collection
model: Entities.Office
url: '/json/offices'
API =
getOffices: (callback) ->
offices = new Entities.Offices
offices.fetch
success: ->
callback(offices)
App.reqres.setHandler 'offices:entities', (callback) ->
API.getOffices callback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment