Good day
If I have a view with 200 features in it, but only 150 features are shown because 50 of them are too small, after setting a definition expression, is there a method to select them all, even the non-visible ones, using the Sketch Widget "Draw a Rectangle" tool?
My current logic is:
Processng the "Draw"
this._sketchWidget.on("create", async (event) => {
if (event.state === "complete") {
this._view.graphics.removeAll();
const geometries = this.sketchLayer.graphics.map((graphic) => {
return graphic.geometry
});
const queryGeometry = await geometryEngineAsync.union(geometries.toArray());
this.selectFeatures(queryGeometry);
}
});
Running the query:
private selectFeatures(geometry): void {
const query = {
geometry: geometry,
outFields: ["*"],
returnGeometry: true,
};
this._view.graphics.removeAll();
this.sketchLayer.graphics.removeAll();
this._view.map.layers.forEach((layer) => {
if (layer.type === 'feature') {
this._view.whenLayerView(layer).then((layerView) => {
layerView.queryFeatures(query).then((results: IQueryFeaturesResponse) => {
this.blah = [];
results.features.forEach((result) => {
this.blah.push(result.attributes.objectId);
const graphic = new Graphic(<GraphicProperties>result.geometry);
this._view.graphics.add(graphic);
})
}).catch((queryError) => {
console.log('Query Error');
console.log(queryError);
})
})
}
})
}
Is there a query parameter I can use to make sure everything, no matter its size, is selected?
Thanks
If a FeatureLayer has a definitionExpression set, then features that don't match will not exist on the client. Therefore the associated FeatureLayerView can't return those features on a query because it just plain doesn't have them. In that case, your query will need to go to the server instead, like the following:
if (layer.type === 'feature') {
layer.queryFeatures(query).then((results: IQueryFeaturesResponse) => {
this.blah = [];
results.features.forEach((result) => {
this.blah.push(result.attributes.objectId);
const graphic = new Graphic(<GraphicProperties>result.geometry);
this._view.graphics.add(graphic);
})
}).catch((queryError) => {
console.log('Query Error');
console.log(queryError);
})
}
Good Day
I know that you shouldn't query for things outside the DE, but assuming I want to select everything from the DE using the Sketch Widget selection tools, can I select things that aren't visible due to their size? This can happen if the feature becomes too small to render.
Thanks
I see what you mean. I don't see a clear answer in the documentation, so I suppose the best approach is through experimentation. If you query an area where you know features exist, but aren't drawn, do you get them in the results? If not, do you get them from a non-spatial query to the layerview? If they come back in a non-spatial query, perhaps you could filter them yourself using geometryEngine.intersects.
However, I think there's a larger consideration here. Your workflow is to query these features, and then add them to the view's graphics layer. If some features are too small to be drawn, we might wonder if adding them to the view's graphics really matters, since they won't be visible anyways. If the thought is that they'll be there if the user zooms in, the problem there would be that those geometries would be highly inaccurate, because the FeatureLayerView only has quantized geometries (i.e. generalized geometries that look the same at the present scale), and not the actual geometries stored in the database. If you want the true geometry, you'll have to query the server.
Ya, experimentation lead me to the community forum! This is a pickle, I don't think there's a good way around this, since everything is generated client side. Luckily, there's another way to access these features and select them, but you can't do it on the map.