I'm using the follow snippet of code to zoom to the extent of graphics in a featurelayer. It works great when the map starts at the full extent. If I remove some graphics and add new graphics that are in an area that is not currently visible on the map, the queryExtent returns a null extent. However, if I add code to zoom to the full extent of the map first, then the queryExtent returns the extent. Anyone know how I can get this to work without zooming home each time I want to zoom to the extent of the layer?
The LayerView only has features that are currently displayed in the browser. When you query the extent of them, it only has the information to calculate the extent of displayed features. If you need the true extent of the data source, you can use the layer.queryExtentI() method or if defined, layer.fullExtent property of the layer.
Glad to have that explanation. I'm not sure I can switch to using layer.queryExtent because I'm working with a client side FeatureLayer. According to the documentation:
"Note that when working with client-side FeatureLayers, you will need to call queryExtent() on the FeatureLayerView to see the expected behavior."
Any other suggestions?
Thanks,
Jennifer
Are you using applyEdits to add features to the layer or adding them via source when creating it? If that's the case, you can still use layer.queryExtent() and it will work. It's still client-side.
Hi there,
@ReneRubalcava is 100% correct. Please use the FeatureLayer.queryExtent() to zoom to the full extent of all features stored in your client-side feature collection especially if the features are being added or removed.
I will update the sample description accordingly since it is outdated.
-Undral