I thought I was implementing a simple "zoom to extent" function, which works... but it also doesnt let you zoom away from the area... I didnt think this was the intention of this code. Can someone advise. I would prefer to zoom on load and then let the use zoom away afterward.
Here is the page... try to pan or zoom away just a little on the inset map... you'll see
https://data.orangeville.ca/Apps/PlanningApplications/property.html?gid={B85BF5C1-2EF2-4E98-9F4B-94FBC4D15708}
This is my reference
https://developers.arcgis.com/javascript/latest/sample-code/featurelayer-queryextent/index.html
Here is the code for the map (4.16),
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/widgets/BasemapToggle"
], function (Map, MapView, FeatureLayer, BasemapToggle) {
// Create the Map with an initial basemap
var map = new Map({
basemap: "topo-vector"
});
// Create the MapView and reference the Map in the instance
var view = new MapView({
container: "map",
map: map,
center: [-80.106,43.916],
zoom: 13
});
var defexp = 'GlobalID = \'' + getUrlParameter('gid') + '\''
var featureLayer = new FeatureLayer({ url: "https://gis.orangeville.ca/arcgis/rest/services/PlanningCadastre/PlanningApplications/FeatureServer/0",
definitionExpression: defexp
});
map.add(featureLayer);
view.whenLayerView(featureLayer).then(function(layerView) {
layerView.watch("updating", function(val) {
// wait for the layer view to finish updating
if (!val) {
layerView.queryExtent().then(function(response) {
// go to the extent of all the graphics in the layer view
view.goTo(response.extent);
});
}
});
});
// Makes the layer 50% transparent
featureLayer.opacity = 0.5;
// 1 - Create the widget
var toggle = new BasemapToggle({
// 2 - Set properties
view: view, // view that provides access to the map's 'topo-vector' basemap
nextBasemap: "satellite" // allows for toggling to the 'hybrid' basemap
});
// Add widget to the top right corner of the view
view.ui.add(toggle, "top-right");
});