Skip to content

Commit

Permalink
add extraMetadata to profile interface [onthegomap#794]
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Jan 16, 2024
1 parent 0cb2645 commit 88c0746
Show file tree
Hide file tree
Showing 3 changed files with 41 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> extraMetadata() { 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,8 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;
import org.slf4j.Logger;
Expand Down Expand Up @@ -93,7 +95,7 @@ public TileArchiveMetadata(Profile profile, PlanetilerConfig config, List<LayerA
config.minzoom(),
config.maxzoom(),
vectorLayers == null ? null : new TileArchiveMetadataJson(vectorLayers),
mapWithBuildInfo(),
mergeMaps(mapWithBuildInfo(),profile.extraMetadata()),
config.tileCompression()
);
}
Expand Down Expand Up @@ -175,6 +177,14 @@ 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) {
return Stream.concat(m1.entrySet().stream(), m2.entrySet().stream())
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(value1, value2) -> value2));
}

@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> extraMetadata() {
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 88c0746

Please sign in to comment.