Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/update esri loader #1

Merged
merged 2 commits into from Feb 1, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

update to esri-loader 2.0.0 (with annotated code comments)

  • Loading branch information...
tomwayson committed Jan 14, 2018
commit 4cb6413c0ea31fdd09e94f3a0ce0d1669a9fd5ad
@@ -5,7 +5,7 @@
"author": "rene rubalcava <rrubalcava@esri.com>",
"private": true,
"dependencies": {
"esri-loader": "^0.1.3",
"esri-loader": "^2.0.0",
"nuxt": "latest"
},
"scripts": {
@@ -17,7 +17,10 @@
</section>
</template>
<script>
import * as esriLoader from 'esri-loader'
// import * as esriLoader from 'esri-loader'
// now we only need the loadModules() function
import { loadModules } from 'esri-loader'
export default {
data ({ req }) {
@@ -34,11 +37,22 @@ export default {
console.log('map: mounted')
const createMap = () => {
// first, we use Dojo's loader to require the map class
esriLoader.dojoRequire([
// esriLoader.dojoRequire([
// now we use loadModules() instead of dojoRequire()
loadModules([
'esri/Map',
'esri/views/SceneView',
'esri/core/watchUtils'
], (EsriMap, SceneView, watchUtils) => {
],
// now we include the options we would have passed to bootstrap()
// as the second argument to loadModules
{
// use a specific version instead of latest 4.x
url: 'https://js.arcgis.com/4.2/'
}
// now loadModules returns a promise so the callback gets passed to .then()
).then(([EsriMap, SceneView, watchUtils]) => {
// create map with the given options at a DOM node w/ id 'mapNode'
let map
if (!this.$store.state.map) {
@@ -61,27 +75,36 @@ export default {
this.$store.state.camera = camera.clone().toJSON()
})
return view
// NOTE: important: now that we're using a promise
// your callback must NOT return any v4.x classes that resolve to promises
// this will cause a hole in the space-time continum that will kill us all
// return view
})
}
// now with loadModules() we no longer need any of this business
// has the ArcGIS API been added to the page?
if (!esriLoader.isLoaded()) {
// no, lazy load it the ArcGIS API before using its classes
esriLoader.bootstrap((err) => {
if (err) {
console.error(err)
}
// once it's loaded, create the map
createMap()
}, {
// use a specific version instead of latest 4.x
url: 'https://js.arcgis.com/4.2/'
})
} else {
// ArcGIS API is already loaded, just create the map
createMap()
}
// if (!esriLoader.isLoaded()) {
// // no, lazy load it the ArcGIS API before using its classes
// esriLoader.bootstrap((err) => {
// if (err) {
// console.error(err)
// }
// // once it's loaded, create the map
// createMap()
// }, {
// // use a specific version instead of latest 4.x
// url: 'https://js.arcgis.com/4.2/'
// })
// } else {
// // ArcGIS API is already loaded, just create the map
// createMap()
// }
// instead we just call createMap()
// in fact, createMap() is no longer needed
// we could have just called loadModules()
createMap()
},
beforeDestroy () {
console.log('map: beforeDestroy')
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.