Skip to content

Commit

Permalink
use setMinPixelSizeBelowZoom() instead of uniAreaToMinZoom()
Browse files Browse the repository at this point in the history
  • Loading branch information
phanecak-maptiler committed Dec 19, 2023
1 parent 3b0959b commit 69393d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 68 deletions.
23 changes: 4 additions & 19 deletions src/main/java/org/openmaptiles/layers/Poi.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ public class Poi implements
private static final Comparator<Tables.OsmPoiPoint> BY_SUBCLASS = Comparator
.comparingInt(s -> AGG_STOP_SUBCLASS_ORDER.indexOf(s.subclass()));
private static final Set<String> BRAND_OPERATOR_REF_SUBCLASSES = Set.of("charging_station", "parcel_locker");
private static final double LOG2 = Math.log(2);
private static final double SQRT10 = Math.sqrt(10);
private final MultiExpression.Index<String> classMapping;
private final Translations translations;
private final Stats stats;
Expand Down Expand Up @@ -154,14 +152,6 @@ private int minzoom(String subclass, String mappingKey) {
return lowZoom ? 12 : 14;
}

public static int uniAreaToMinZoom(double areaWorld) {
double oneSideWorld = Math.sqrt(areaWorld);
double zoom = -(Math.log(oneSideWorld * SQRT10) / LOG2);
int result = (int) Math.floor(zoom - 0.1e-10) + 1;

return Math.clamp(result, 10, 14);
}

@Override
public void release() {
aggStops.clear();
Expand Down Expand Up @@ -308,16 +298,11 @@ private <T extends Tables.WithSubclass & Tables.WithStation & Tables.WithFunicul
int poiClassRank = poiClassRank(poiClass);
int rankOrder = poiClassRank + ((nullOrEmpty(name)) ? 2000 : 0);

int minzoom;
int minzoom = minzoom(element.subclass(), element.mappingKey());
if (UNIVERSITY_POI_SUBCLASSES.contains(rawSubclass)) {
minzoom = 14;
try {
minzoom = uniAreaToMinZoom(element.source().area());
} catch (GeometryException e) {
e.log(stats, "omt_poi_polygon", "Unable to get geometry for university polygon " + element.source().id());
}
} else {
minzoom = minzoom(element.subclass(), element.mappingKey());
// universities that are at least 10% of a tile may appear from Z10
output.setMinPixelSizeBelowZoom(13, 80); // 80x80px is ~10% of a 256x256px tile
minzoom = 10;
}

output.setBufferPixels(BUFFER_SIZE)
Expand Down
49 changes: 0 additions & 49 deletions src/test/java/org/openmaptiles/layers/PoiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,53 +465,4 @@ void testChargingStation() {
))));
}

private record TestEntry(
SourceFeature feature,
int expectedZoom
) {}

private void createUniAreaForMinZoomTest(List<TestEntry> testEntries, double area, int expectedZoom, String name) {
var feature = polygonFeatureWithArea(area, Map.of(
"name", name,
"amenity", "university"
));
testEntries.add(new TestEntry(
feature,
Math.clamp(expectedZoom, 10, 14)
));
}

@Test
void testUniAreaToMinZoom() throws GeometryException {
// threshold is 1/10 of tile area, hence ...
// ... side is 1/sqrt(10) tile side: from pixels to world coord, for say Z14 ...
//final double PORTION_OF_TILE_SIDE = (256d / Math.sqrt(10)) / Math.pow(2d, 14d + 8d);
// ... and then for some lower zoom:
//double testAreaSide = PORTION_OF_TILE_SIDE * Math.pow(2, 14 - zoom);
// all this then simplified to `testArea` calculation bellow

final List<TestEntry> testEntries = new ArrayList<>();
for (int zoom = 14; zoom >= 0; zoom--) {
double testArea = Math.pow(4, -zoom) / 10;

// slightly bellow the threshold
createUniAreaForMinZoomTest(testEntries, testArea * 0.999, zoom + 1, "uni-");
// precisely at the threshold
createUniAreaForMinZoomTest(testEntries, testArea, zoom, "uni=");
// slightly over the threshold
createUniAreaForMinZoomTest(testEntries, testArea * 1.001, zoom, "uni+");
}

for (var entry : testEntries) {
assertFeatures(14, List.of(Map.of(
"_layer", "landuse",
"class", "university"
), Map.of(
"_layer", "poi",
"_type", "point",
"_minzoom", entry.expectedZoom,
"_maxzoom", 14
)), process(entry.feature));
}
}
}

0 comments on commit 69393d0

Please sign in to comment.