Skip to content

Commit

Permalink
add extraMetadata to profile interface [#794] (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon authored Jan 17, 2024
1 parent fdb9ea6 commit 67d530a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -157,6 +158,8 @@ default boolean isOverlay() {
return false;
}

default Map<String,String> extraArchiveMetadata() { return Map.of(); }

/**
* Defines whether {@link Wikidata} should fetch wikidata translations for the input element.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,7 +94,7 @@ public TileArchiveMetadata(Profile profile, PlanetilerConfig config, List<LayerA
config.minzoom(),
config.maxzoom(),
vectorLayers == null ? null : new TileArchiveMetadataJson(vectorLayers),
mapWithBuildInfo(),
mergeMaps(mapWithBuildInfo(),profile.extraArchiveMetadata()),
config.tileCompression()
);
}
Expand Down Expand Up @@ -175,6 +176,12 @@ public TileArchiveMetadata withJson(TileArchiveMetadataJson json) {
* https://github.com/FasterXML/jackson-databind/issues/3439
*/

private static Map<String,String> mergeMaps(Map<String,String> m1, Map<String,String> m2) {
var result = new TreeMap<>(m1);
result.putAll(m2);
return result;
}

@JsonAnySetter
private void putUnknownFieldsToOthers(String name, String value) {
others.put(name, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String,String> 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";
Expand Down

0 comments on commit 67d530a

Please sign in to comment.