Last active
December 21, 2015 20:39
-
-
Save odoe/53c72f33523a3509d96f to your computer and use it in GitHub Desktop.
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/services/map.js | |
import Ember from 'ember'; | |
import Map from 'esri/Map'; | |
import GraphicsLayer from 'esri/layers/GraphicsLayer'; | |
import VectorTileLayer from 'esri/layers/VectorTileLayer'; | |
export default Ember.Service.extend({ | |
map: null, | |
loadMap() { | |
let map = this.get('map'); | |
if (map) { | |
return map; | |
} else { | |
let graphicsLayer = new GraphicsLayer({ id: 'graphics' }); | |
let tileLayer = new VectorTileLayer({ | |
url: "https://www.arcgis.com/sharing/rest/content/items/f96366254a564adda1dc468b447ed956/resources/styles/root.json" | |
}); | |
map = new Map({ | |
layers: [tileLayer, graphicsLayer] | |
}); | |
this.set('map', map); | |
return map; | |
} | |
} | |
//-> app/components/esri-map.js | |
import Ember from 'ember'; | |
import MapView from 'esri/views/MapView'; | |
export default Ember.Component.extend({ | |
classNames: ['viewDiv'], | |
mapService: Ember.inject.service('map'), | |
didInsertElement() { | |
let map = this.get('map'); | |
if (!map) { | |
map = this.get('mapService').loadMap(); | |
this.set('map', map); | |
} | |
}, | |
createMap: function() { | |
let map = this.get('map'); | |
let view = new MapView({ | |
map, | |
container: this.elementId, | |
center: [-100.33, 25.69], | |
zoom: 10 | |
}); | |
view.then(x => this.set('view', x)); | |
}.observes('map') | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment