Select to view content in your preferred language

Extent of All Features is... sticking, can't pan or zoom away

835
1
Jump to solution
11-16-2020 08:24 AM
AwesomeEvan
Regular Contributor

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-94F...

 

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/...",
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");
});

 

 

 

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Evan,

 

  Your issue is that the way you have your code every time the layer is done updating it will zoom to the features extent. If you are wanting this to only happen initially them you need to remove the event handler or you could use watch utils to use the whenfalseonce method

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-watchUtils.html#whenFalseOnc...

 

So something like this:

var handle = layerView.watch("updating", function(val) {
  // wait for the layer view to finish updating
  if (!val) {
    layerView.queryExtent().then(function(response) {
      //remove the layer updating watch handler
      handle.remove();
      // go to the extent of all the graphics in the layer view
      view.goTo(response.extent);
    });
  }
});

 

View solution in original post

1 Reply
RobertScheitlin__GISP
MVP Emeritus

Evan,

 

  Your issue is that the way you have your code every time the layer is done updating it will zoom to the features extent. If you are wanting this to only happen initially them you need to remove the event handler or you could use watch utils to use the whenfalseonce method

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-watchUtils.html#whenFalseOnc...

 

So something like this:

var handle = layerView.watch("updating", function(val) {
  // wait for the layer view to finish updating
  if (!val) {
    layerView.queryExtent().then(function(response) {
      //remove the layer updating watch handler
      handle.remove();
      // go to the extent of all the graphics in the layer view
      view.goTo(response.extent);
    });
  }
});