Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add extraMetadata to profile interface [#794] #795

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd expect the profile to provide defaults, then args to layer on top of that, so let's either reverse this or the behavior of mergeMaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't mapWithBuildInfo just be the planetiler:* metadata? If I define those in my profile (or command line args passed into my profile), they ought to override the defaults, I don't know why someone would do that though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right! Yeah this looks good then. The command-line args get copied in just above this.

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
Loading