Hello everyone,
I have problems with the FeatureTable widget with featureLayer, does not zoom to select feature and full extents the error that indicates is TypeError: Cannot read property 'targetGeometry' of null
Javascript ver. 4.19
Thank you
Solved! Go to Solution.
Hi there,
What Jose said is correct. The reason you are not able to zoom into selected features and full extent is because the feature layer has a different spatial reference than the view's spatial reference. To solve this issue a few things need to be done in your app.
In order to zoom to the selected features, please set the query.outSpatialReference to match the spatialReference of the view so that the returned results can be located on the map. See below:
query.objectIds = featureIds;
query.returnGeometry = true;
query.outSpatialReference = view.spatialReference;
As for the fullExtent of the FeatureLayer, I'd suggest that you pass in a predefined extent that matches the view's spatialReference. If that is not an option then you can use the projection module's project method to project the fullExtent of your layer to match the spatialReference of the view. But loading projection module for this case only maybe an overkill.
projection.load().then(function () {
projectedFullExtent = projection.project(
featureLayer.fullExtent,
view.spatialReference
);
});
Forgot to mention this initially... You have to reproject the fullExtent of your layer to match the spatial reference of the view because View.goTo does not project the geometries on the fly. We have an enhancement request for this. But for now, you have to project your geometry to match the spatial reference of the view before calling goTo.
Here is an updated simple test app that shows how to zoom to fullExtent and selected features.
Hope this helps,
-Undral
Hello,
I noticed the Spatial Reference of the layer has a wkid of 32613. The basemap you are using is "streets-night-vector" which has a wkid of 102100 (Web Mercator). If you comment out the basemap line of code in the Map constructor and refresh the app, you will notice the layer loads without a basemap, and if you select a record in the FeatureTable, you will now be able to highlight the feature and zoom to the selected feature. Can you verify this? This appears to be an issue caused by the spatial reference of the layer being distinct from the basemap's.
Hi there,
What Jose said is correct. The reason you are not able to zoom into selected features and full extent is because the feature layer has a different spatial reference than the view's spatial reference. To solve this issue a few things need to be done in your app.
In order to zoom to the selected features, please set the query.outSpatialReference to match the spatialReference of the view so that the returned results can be located on the map. See below:
query.objectIds = featureIds;
query.returnGeometry = true;
query.outSpatialReference = view.spatialReference;
As for the fullExtent of the FeatureLayer, I'd suggest that you pass in a predefined extent that matches the view's spatialReference. If that is not an option then you can use the projection module's project method to project the fullExtent of your layer to match the spatialReference of the view. But loading projection module for this case only maybe an overkill.
projection.load().then(function () {
projectedFullExtent = projection.project(
featureLayer.fullExtent,
view.spatialReference
);
});
Forgot to mention this initially... You have to reproject the fullExtent of your layer to match the spatial reference of the view because View.goTo does not project the geometries on the fly. We have an enhancement request for this. But for now, you have to project your geometry to match the spatial reference of the view before calling goTo.
Here is an updated simple test app that shows how to zoom to fullExtent and selected features.
Hope this helps,
-Undral
Thank you UndralBatsukh, JoseBanuelos1and UndralBatsukh for taking the time to resolve my error