From 67d530a5262c8c10271d116a69e0122d57040c6c Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Wed, 17 Jan 2024 19:03:17 +0800 Subject: [PATCH] add extraMetadata to profile interface [#794] (#795) --- .../com/onthegomap/planetiler/Profile.java | 3 +++ .../archive/TileArchiveMetadata.java | 9 ++++++- .../archive/TileArchiveMetadataTest.java | 27 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/Profile.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/Profile.java index 8bb2977bbe..3a2a517b01 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/Profile.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/Profile.java @@ -7,6 +7,7 @@ import com.onthegomap.planetiler.reader.osm.OsmRelationInfo; import com.onthegomap.planetiler.util.Wikidata; import java.util.List; +import java.util.Map; import java.util.function.Consumer; /** @@ -157,6 +158,8 @@ default boolean isOverlay() { return false; } + default Map extraArchiveMetadata() { return Map.of(); } + /** * Defines whether {@link Wikidata} should fetch wikidata translations for the input element. *

diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/archive/TileArchiveMetadata.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/archive/TileArchiveMetadata.java index 1c5c83a14f..fc0d4eca3b 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/archive/TileArchiveMetadata.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/archive/TileArchiveMetadata.java @@ -17,6 +17,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Envelope; import org.slf4j.Logger; @@ -93,7 +94,7 @@ public TileArchiveMetadata(Profile profile, PlanetilerConfig config, List mergeMaps(Map m1, Map m2) { + var result = new TreeMap<>(m1); + result.putAll(m2); + return result; + } + @JsonAnySetter private void putUnknownFieldsToOthers(String name, String value) { others.put(name, value); diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/archive/TileArchiveMetadataTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/archive/TileArchiveMetadataTest.java index e672934b7d..848cadc072 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/archive/TileArchiveMetadataTest.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/archive/TileArchiveMetadataTest.java @@ -6,11 +6,14 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.onthegomap.planetiler.FeatureCollector; import com.onthegomap.planetiler.Profile; import com.onthegomap.planetiler.TestUtils; +import com.onthegomap.planetiler.VectorTile; import com.onthegomap.planetiler.config.Arguments; import com.onthegomap.planetiler.config.PlanetilerConfig; import com.onthegomap.planetiler.geo.GeoUtils; +import com.onthegomap.planetiler.reader.SourceFeature; import com.onthegomap.planetiler.util.LayerAttrStats; import java.util.List; import java.util.Map; @@ -191,6 +194,30 @@ void testAddMetadataSmallBounds() { assertEquals(7, Math.ceil(metadata.zoom())); } + @Test + void testAddExtraMetadata() { + class TestingProfile extends Profile.NullProfile { + + @Override + public String name() { + return "My Name"; + } + + @Override + public Map extraArchiveMetadata() { + return Map.of("FooVersion","2.0"); + } + } + + var metadata = new TileArchiveMetadata(new TestingProfile(), PlanetilerConfig.from(Arguments.of(Map.of( + "bounds", "-73.6632,41.1274,-69.7598,43.0185" + )))); + + var map = new TreeMap<>(metadata.toMap()); + assertEquals("My Name", map.get("name")); + assertEquals("2.0", map.get("FooVersion")); + } + @Test void testToMap() throws JsonProcessingException { var bounds = "-73.6632,41.1274,-69.7598,43.0185";