Error Accessor#set Assigning an instance of 'esri.geometry.SpatialReference' which is not a subclass of 'esri.geometry.SpatialReference'

3374
3
05-17-2019 09:55 AM
MichailMarinakis1
Occasional Contributor II

Hi all, 

I have the following error when i use the goTo method in a view: Accessor#set Assigning an instance of 'esri.geometry.SpatialReference' which is not a subclass of 'esri.geometry.SpatialReference'.

#The goTo functionality works correct though... The part of the code is here:

require([
"esri/layers/FeatureLayer",
"esri/geometry/SpatialReference"
], function (FeatureLayer, SpatialReference) {

if (nodeFilter == "") {return};

var layerNode = new FeatureLayer({
url: synchProperties.queryUrl,
spatialReference: new SpatialReference(31370),
id: "nodeLayer"
});

var query = layerNode.createQuery();
query.where = nodeFilter;
query.returnGeometry = true;
query.outSpatialReference = new SpatialReference(31370);

layerNode.queryFeatures(query).then(function (response) {

if (response.features.length !== 0) {
currentView.goTo({
target: response.features
});
}
});
});

The service is not publicly available. The spatial reference is the same for the layer, the view and the query. It does correctly go to the queried features and the behavior is as expected but the console log has this error for all the returned features.

Any feedback would be very helpful! 

Thanks in advance. 

Regards,

Michael

0 Kudos
3 Replies
MichaelLev
Occasional Contributor III

Hi Michail Marinakis‌, 

I have same error, in some other context. Please see my question.

Have you found a solution?

Michael

0 Kudos
MichailMarinakis1
Occasional Contributor II

Hi Michael, 

i checked your issue and it is not exactly the same. In our issue, the error message was mentioning that the instance SpatialReference is not a subclass of SpatialReference which doesn't make a lot of sense. 

In your issue, the error message is:"'SceneLayer' which is not a subclass of 'esri.layers.FeatureLayer'" and that makes sense. If you see here, the inheritance is SceneLayer -> Layer ->  Accessor

I guess that somewhere there is a reference to a layer that should be treated as a feature layer and not instantiated as a SceneLayer. That's why the API is complaining. 

In any case, we fix our issue by auto-casting. In our case we create the point and the spatial reference via auto-casting, e.g. something like that

      (relatedMap.view as esri.MapView).center = {
        type: "point"// autocasts as new Point()
        x: (response.features[0].geometry as esri.Point).x,
        y: (response.features[0].geometry as esri.Point).y,
        spatialReference: { wkid: 31370 }
      } as esri.Point;

Hope this helps! Good luck!

0 Kudos
JoelBennett
MVP Regular Contributor

I was receiving this same error today using 4.18, and tracked it down the following problem:  I had code like this:

define(["esri/Geometry/Extent", "esri/layers/FeatureLayer", "esri/tasks/support/Query"], function(Extent, FeatureLayer, Query) {
	//etc
});

 

However, notice the capital "G" in "Geometry". Unfortunately, it took me quite awhile to notice that, but once I fixed it to the following, the error messages stopped:

define(["esri/geometry/Extent", "esri/layers/FeatureLayer", "esri/tasks/support/Query"], function(Extent, FeatureLayer, Query) {
	//etc
});

 

This doesn't appear to be the problem you're having, but if, like me, somebody else ends up here because they're getting this message, hopefully this might help.

 

One other thing to mention, I notice your code has:

query.outSpatialReference = new SpatialReference(31370);

 

However, the documentation doesn't indicate support for passing a number in the constructor.  I have observed that 4.16 - 4.18 do allow this in practice, but considering the date of the original post, maybe you were using an older version of the API that had a problem with it?  To be consistent with the documentation, though, it would be best to pass an object with the wkid property set:

query.outSpatialReference = new SpatialReference({wkid:31370});
0 Kudos