-1

I have polygons features on a Mapbox map. Their sizes vary a lot (some are big as streets, others are as little as a tree).

Each polygon has an a point feature on it (a circle) that acts as an handle to open a popup related to the polygon data.

But depending on the zoom level, the circle/point is sometimes bigger than the polygon itself; since the polygon "sticks" to the map while the circle size remains unchanged.

What I would like to achieve is to hide the polygon (and its handle) if the polygon size in pixels is smaller than the circle :

  • when zoom changes
  • get the size in pixels of a bouding box containing the polygon
  • compare it to the size of the circle
  • hide both of them if circle radius > polygon smaller side.

I think I'm capable of coding this, but then... how can I hide the features ?

There is a minzoom / maxzoom setting for sources and layers, but how can I achieve this per-feature ?

Thanks!

gordie
  • 1,637
  • 3
  • 21
  • 41

1 Answers1

0

Within the Style Specification, there's no way to access a feature's size. https://docs.mapbox.com/mapbox-gl-js/style-spec/

How many features do you have on your map? Is it possible to precompute the size of the feature and use that to style when it's visible?