I created logic by this example in my Angular 8 app:
Zoom to extent of all features | ArcGIS API for JavaScript 4.15
But in method the method goTo throws exception: Cannot read property 'targetGeometry' of null. I can't understand the reason of exception. I found some solution to move scene to point and it works:
But I would like to use view.goTo(response.extent) it is more native and clear.
One more thing: coordinates in sweref 99 format. Could it be a reason of the issue?
Solved! Go to Solution.
The geometry that you are zooming to needs to be in the same spatial reference as the view. In your queryExtent you can provide a query class and set the outSpatialReference to the view.spatialReference.
The geometry that you are zooming to needs to be in the same spatial reference as the view. In your queryExtent you can provide a query class and set the outSpatialReference to the view.spatialReference.
Thank you for your help. It makes sense.
But I got another error:
Difficult to understand the reason. I found temporary solution with zoom. It is not so clear but works quite well. Coefficient 8 is selected approximately Maybe this will help someone.
The issue with your
this._featureLayer.queryExtent({outSpatialReference: this._view.spatialReference}).then
is that you are passing a simple Object and not an actual Query Class.
It works! Thank you!
this.zoomToExtentFunc = function () {
var query = this._featureLayer.createQuery();
query.outSpatialReference = this._view.spatialReference
this._featureLayer.queryExtent(query).then(response => {
this._view.goTo(response.extent ).catch(function (error) {
console.error(error);
});
});
}