Set visibility of geometry/feature from specific layer for JavaScript

08-24-2021 08:44 AM
New Contributor


I have a set layers loaded in the scene and it depends of the selected layer, I would like to be able to set the visible property to false or true of each geometry/feature, is it possible?

All information that I found is related to the layer, but at this point the layer contains geometries/features and my goal is to interact with these and leave the layer at the top of visibility to true.

I used the following lines

function setGeometriesVisibility(layer, ids) {
   //ids => contains an array of keys id
   let query = layer.createQuery();
   layer.queryFeatures(query).then(function (response) {
   response.features.forEach((f) => {
     //GisId => a custom property that defines an id
     f.visible = ids.indexOf(f.attributes.GisId) > -1 ? true : false;
     layer.applyEdits({ updateFeatures: [f] }).then(function (results) {
         //Do nothing
     }).catch(error => console.log(error));

I had an error that describes "Layer does not support updating features."

is there any functionality that allows to set the visibility of the geometry/feature?

Thanks in advance for any kind of help



0 Kudos
2 Replies
Frequent Contributor II

You don't set the visibility of individual features in a layer. You can set a definitionExpression to filter our features. This will limit what data is downloaded from the service. You can also apply filters on the LayerView if you still want the features downloaded for other purposes, but just don't want them to display.

New Contributor


I used the filter to approach my goal

0 Kudos