+ * If you need more flexibility, use {@link #getMinZoomForPixelSize(double)} directly, or create a
+ * {@link ZoomFunction} that calculates {@link #getPixelSizeAtZoom(int)} and applies a custom threshold based on the
+ * zoom level.
+ */
+ public Feature setAttrWithMinSize(String key, Object value, double minPixelSize, int minZoomIfBigEnough,
+ int minZoomToShowAlways) {
+ return setAttrWithMinzoom(key, value,
+ Math.clamp(getMinZoomForPixelSize(minPixelSize), minZoomIfBigEnough, minZoomToShowAlways));
+ }
+
/**
* Inserts all key/value pairs in {@code attrs} into the set of attribute to emit on the output feature at or above
* {@code minzoom}.
@@ -735,6 +780,14 @@ public class FeatureCollector implements Iterable
+ * The result will be clamped to the range [0, {@link PlanetilerConfig#MAX_MAXZOOM}].
+ */
+ public static int minZoomForPixelSize(double worldGeometrySize, double minPixelSize) {
+ double worldPixels = worldGeometrySize * 256;
+ return Math.clamp((int) Math.ceil(Math.log(minPixelSize / worldPixels) / LOG2), 0,
+ PlanetilerConfig.MAX_MAXZOOM);
+ }
+
/** Helper class to sort polygons by area of their outer shell. */
private record PolyAndArea(Polygon poly, double area) implements Comparable