Show or hide featues by zoom level and importance

Viewed 53

Using arcgis for JS 4.24 MapView.

I have a feature layer with features of different importance to the user. The importance is defined in an attribute of the feature. What I want to achieve is, that less important features only show on a certain zoom level.

What I tried so far:

  • Clustering: is not what I want since it is grouping on occurrences not importance.
  • Unique Value Renderer: Does not seem to support visibility by zoom level but is otherwise exactly what I would use.
  • Setting the min-max visibility: This applies to all features and cannot be configured by attribute value.

What did I miss? Any other ways to apply custom styles to feature layers?

1 Answers

I guess a simple solution would be to create as many FeatureLayer instances as importances you have. In each of this instances you set,

  1. definitionExpression to the importance level,
  2. maxScale and minScale to constraint the visibility

This solution would work if the number of importance levels are "reasonable" (let say, less than 10 or so, you will have to test it).

Another solution would be to listen for scale changes in the map view (could be the updating event), and then apply a filter (could be definitionExpression again) with the correspondent importance. With this you do not need to have many instances of the same service.

EDIT

The reason for using updating, is to avoid doing stuff while the view is changing, something like this,

view.watch("updating", function (value) {
    if (!value) {
        // now is the moment to check view properties
        // for example
        if (view.scale < MIN_SCALE) {
            doSomething();
        };
    }
});
Related