Skip to content

Instantly share code, notes, and snippets.

@nommuna2
Last active April 26, 2019 22:06
Show Gist options
  • Save nommuna2/78881d9e28df591837d9f54e272072dd to your computer and use it in GitHub Desktop.
Save nommuna2/78881d9e28df591837d9f54e272072dd to your computer and use it in GitHub Desktop.
(ArcGIS API for JavaScript) Sample of using promises and the goTo method
require([
"esri/Map",
"esri/views/SceneView",
"esri/layers/FeatureLayer",
"dojo/domReady!"
],
function (Map, SceneView, FeatureLayer) {
// Code to create the map and view will go here
var featureLayer = new FeatureLayer({
url: "url to feature layer"
});
var map = new Map({
basemap: "dark-gray",
ground: "world-elevation"
});
var view = new SceneView({
container: "viewDiv",
map: map
});
view.then(function (result) { //wait for the view to load
featureLayer.load().then(function (e) { //wait for the feature layer to load
map.add(featureLayer); //add the layer after the view and featurelayer instances have loaded
view.goTo({
center: [e.fullExtent.center.longitude, e.fullExtent.center.latitude], //Grab the center from the featurelayer instance
heading: 0, // set the heading to point South
tilt: 0, // maintain tilt value
});
});
}, function (err) {
console.log(err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment