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 house numbers layer #336

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions styles/src/base_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,24 @@ export function labels_layers(
script?: string,
): LayerSpecification[] {
return [
{
id: "housenumbers_label",
type: "symbol",
source: source,
"source-layer": "housenumbers",
minzoom: 13,
layout: {
"symbol-placement": "point", // Places the text at a point location
"text-font": [t.italic || "Noto Sans Italic"],
"text-field": ["get", "housenumber"], // Retrieves the text from the 'housenumber' property in the source
"text-size": 12 // Adjust text size as needed
},
paint: {
"text-color": "red", // Set text color to red
"text-halo-color": "white", // Optional: adds a halo around the text for better visibility
"text-halo-width": 1 // Optional: defines the width of the halo
}
},
{
id: "water_waterway_label",
type: "symbol",
Expand Down
5 changes: 5 additions & 0 deletions tiles/src/main/java/com/protomaps/basemap/Basemap.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.protomaps.basemap.layers.Roads;
import com.protomaps.basemap.layers.Transit;
import com.protomaps.basemap.layers.Water;
import com.protomaps.basemap.layers.Housenumbers;
import com.protomaps.basemap.text.FontRegistry;
import java.nio.file.Path;
import java.util.HashMap;
Expand All @@ -36,6 +37,10 @@ public Basemap(NaturalEarthDb naturalEarthDb, QrankDb qrankDb) {
registerHandler(buildings);
registerSourceHandler("osm", buildings::processOsm);

var housenumbers = new Housenumbers();
registerHandler(housenumbers);
registerSourceHandler("osm", housenumbers::processOsm);

var landuse = new Landuse();
registerHandler(landuse);
registerSourceHandler("osm", landuse::processOsm);
Expand Down
34 changes: 34 additions & 0 deletions tiles/src/main/java/com/protomaps/basemap/layers/Housenumbers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.protomaps.basemap.layers;

import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.ForwardingProfile;
import com.onthegomap.planetiler.VectorTile;
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.reader.SourceFeature;
import com.protomaps.basemap.feature.FeatureId;

import java.util.List;

public class Housenumbers implements ForwardingProfile.LayerPostProcesser {
public void processOsm(SourceFeature sf, FeatureCollector features) {
if (sf.hasTag("addr:housenumber")) {
if (sf.isPoint()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also a lot of ways in osm have a house number: https://taginfo.openstreetmap.org/keys/addr%3Ahousenumber#overview

Copy link
Author

Choose a reason for hiding this comment

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

Yep, I agree. As I mentioned in PR description I wanted to handle them as well, but wanted to first agree on the general approach. Do you think such implementation does have a chance to be eventually merged? 😀 Ofc after handling all the cases, adding tests etc...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is a good idea to add house numbers.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, then I'll continue working on that PR :)

Copy link
Member

Choose a reason for hiding this comment

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

This looks like a great start! We should align the layer name and properties to conform with the Tilezen docs: https://tilezen.readthedocs.io/en/latest/layers/#buildings-and-addresses

so it should be points included in the buildings layer with a property called addr_housenumber

features.point(this.name())
.setId(FeatureId.create(sf))
.setAttr("housenumber", sf.getString("addr:housenumber"))
.setZoomRange(10, 17);
Copy link
Member

Choose a reason for hiding this comment

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

We should limit the house numbers to exist only in the zoom 15 tiles, in order to not bloat the tile size. A visual reference we use for deciding what data goes in what zoom is http://tangrams.github.io/bubble-wrap - house numbers only appear above zoom ~18 which means we can put them in our tileset at 15 and define the style to appear > 18, etc. Is that zoom level good enough for your use case?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I think so :)

}
}
}

@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) throws GeometryException {
return items;
}

@Override
public String name() {
return "housenumbers";
}

}