Zoom to extent error

2188
4
Jump to solution
05-26-2020 12:32 AM
EvryIndustries_Sweden
New Contributor

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?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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.

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

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.

EvryIndustries_Sweden
New Contributor


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.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
EvryIndustries_Sweden
New Contributor

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);
          });
        });
      }
0 Kudos