Created
September 22, 2013 15:58
-
-
Save jgwhite/6661299 to your computer and use it in GitHub Desktop.
Leaflet map component
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 = Ember.Application.create(); | |
App.ApplicationController = Ember.Controller.extend({ | |
latitude: 0, | |
longitude: 0, | |
zoom: 1 | |
}); | |
App.LeafletMapComponent = Ember.Component.extend({ | |
attributeBindings: ['style'], | |
width: '600px', | |
height: '400px', | |
latitude: 0, | |
longitude: 0, | |
zoom: 1, | |
style: function() { | |
return [ | |
'width:' + this.get('width'), | |
'height:' + this.get('height') | |
].join(';'); | |
}.property('width', 'height'), | |
setView: function() { | |
var map = this.get('map'), | |
center = [this.get('latitude'), this.get('longitude')], | |
zoom = this.get('zoom'); | |
map.setView(center, zoom); | |
}.observes('latitude', 'longitude', 'zoom'), | |
didInsertElement: function() { | |
var map = L.map(this.get('element')); | |
this.set('map', map); | |
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { | |
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | |
}).addTo(map); | |
this.setView(); | |
map.on('move', this.mapDidMove, this); | |
map.invalidateSize(); | |
}, | |
willRemoveElement: function() { | |
var map = this.get('map'); | |
if (map) map.remove(); | |
}, | |
mapDidMove: function() { | |
var map = this.get('map'), | |
center = map.getCenter(), | |
zoom = map.getZoom(); | |
this.setProperties({ | |
latitude: center.lat, | |
longitude: center.lng, | |
zoom: zoom | |
}); | |
} | |
}); |
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
body { | |
padding: 1em; | |
} | |
nav { | |
margin: 1em 0; | |
} | |
nav .active { | |
font-weight: bold; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jgwhite Have you confirmed that this works? I'm having some issues: