maplibre / maplibre-style-spec

MapLibre Style Specification & Utilities
https://maplibre.org/maplibre-style-spec/
Other
75 stars 62 forks source link

Change example "measure" from using `in` to something else #665

Open tordans opened 4 months ago

tordans commented 4 months ago

The https://maplibre.org/maplibre-gl-js/docs/examples/measure/ example is referenced in https://maplibre.org/maplibre-style-spec/expressions/#in as a good way to learn how in works.

However, the code it shows filter: ['in', '$type', 'Point'] does not represent a good case for in. It is a simple "match" condition, not an array lookup nor a substring match.

Can we change this example to using ["all", ["match", ["geometry-type"], ["Polygon"], true, false]] or ["all", "$type", ["Polygon"], true, false]] or ["==", "$type", "Polygon"] or something like this?

See also https://github.com/maplibre/maplibre-style-spec/pull/664


This would mean we don't have an in example anymore (which I would argue we don't have now, either). I would consider something like https://visgl.github.io/react-map-gl/examples/filter (Code) a better fit. But even better would be a case with a ['literal', ['array']] IMO.

1ec5 commented 2 months ago

However, the code it shows filter: ['in', '$type', 'Point'] does not represent a good case for in. It is a simple "match" condition, not an array lookup nor a substring match.

This appears to be an example of the legacy in filter, which is incompatible with expressions. So it’s ironic that it’s being given as an example of how to use the in expression operator.

HarelM commented 1 month ago

Feel free to submit a PR, either to this repo or maplibre gl where the example is.