Last active
January 3, 2016 03:29
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@App.module 'MapApp', (MapApp, App, Backbone, Marionette, $, _) -> | |
@startWithParent = false | |
API = | |
showMap: -> | |
new MapApp.List.Controller | |
@on 'start', -> | |
API.showMap() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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