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 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
21 changes: 21 additions & 0 deletions styles/src/base_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ export function nolabels_layers(
type: "fill",
source: source,
"source-layer": "buildings",
filter: ["!=", "kind", "address"],
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be an opt-in instead of an opt-out, e.g. kind in building or building_part

paint: {
"fill-color": t.buildings,
"fill-opacity": 0.5,
Expand Down Expand Up @@ -1373,6 +1374,26 @@ export function labels_layers(
script?: string,
): LayerSpecification[] {
return [
{
id: "housenumbers_label",
type: "symbol",
source: source,
"source-layer": "buildings",
minzoom: 18,
filter: ["==", "kind", "address"],
layout: {
"symbol-placement": "point",
"text-font": [t.italic || "Noto Sans Italic"],
"text-field": ["get", "addr_housenumber"],
"text-size": 12
},
paint: {
"text-color": t.housenumbers_label,
"text-halo-color": t.house_numbers_label_halo,
"text-halo-width": 1,
"text-halo-blur": 1,
}
},
{
id: "water_waterway_label",
type: "symbol",
Expand Down
21 changes: 21 additions & 0 deletions styles/src/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export interface Theme {
state_label_halo: string;
country_label: string;

housenumbers_label: string;
house_numbers_label_halo: string;

regular?: string;
bold?: string;
italic?: string;
Expand Down Expand Up @@ -188,6 +191,9 @@ export const CONTRAST: Theme = {
state_label: "#777777",
state_label_halo: "#ffffff",
country_label: "#9590aa",

housenumbers_label: "#91888b",
Copy link
Author

Choose a reason for hiding this comment

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

I used the same values as roads_label_minor for all themes... Looks okay on my taste...
Screenshot 2024-12-14 at 09 53 14

house_numbers_label_halo: "#ffffff",
Copy link
Member

Choose a reason for hiding this comment

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

maybe housenumbers one word instead of with _?

};

export const LIGHT: Theme = {
Expand Down Expand Up @@ -270,6 +276,9 @@ export const LIGHT: Theme = {
state_label_halo: "#e0e0e0",
country_label: "#a3a3a3",

housenumbers_label: "#91888b",
house_numbers_label_halo: "#ffffff",

pois: {
blue: "#1A8CBD",
green: "#20834D",
Expand Down Expand Up @@ -372,6 +381,9 @@ export const DARK: Theme = {
state_label_halo: "#1f1f1f",
country_label: "#5c5c5c",

housenumbers_label: "#525252",
house_numbers_label_halo: "#1f1f1f",

pois: {
blue: "#4299BB",
green: "#30C573",
Expand Down Expand Up @@ -473,6 +485,9 @@ export const WHITE: Theme = {
state_label: "#b3b3b3",
state_label_halo: "#ffffff",
country_label: "#b8b8b8",

housenumbers_label: "#adadad",
house_numbers_label_halo: "#ffffff",
};

export const GRAYSCALE: Theme = {
Expand Down Expand Up @@ -554,6 +569,9 @@ export const GRAYSCALE: Theme = {
state_label: "#999999",
state_label_halo: "#cccccc",
country_label: "#858585",

housenumbers_label: "#999999",
house_numbers_label_halo: "#e0e0e0",
};

export const BLACK: Theme = {
Expand Down Expand Up @@ -635,6 +653,9 @@ export const BLACK: Theme = {
state_label: "#3d3d3d",
state_label_halo: "#141414",
country_label: "#707070",

housenumbers_label: "#525252",
house_numbers_label_halo: "#141414",
};

const themes: Record<string, Theme> = {
Expand Down
41 changes: 39 additions & 2 deletions tiles/src/main/java/com/protomaps/basemap/layers/Buildings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
import com.onthegomap.planetiler.util.Parse;
import com.protomaps.basemap.feature.FeatureId;
import com.protomaps.basemap.postprocess.Area;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Pattern;

public class Buildings implements ForwardingProfile.LayerPostProcesser {
Expand Down Expand Up @@ -93,13 +98,46 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
// Names should mostly just be for POIs
// Sometimes building name and address are useful items, but only at zoom 17+
//OsmNames.setOsmNames(feature, sf, 13);
} else if (sf.hasTag("addr:housenumber")) {
FeatureCollector.Feature feature = null;
if (sf.isPoint()) {
feature = features.point(this.name());
} else if (sf.canBePolygon()) {
feature = features.centroid(this.name());
}
if (feature != null) {
feature
.setId(FeatureId.create(sf))
.setAttr("addr_housenumber", sf.getString("addr:housenumber"))
.setAttr("addr_street", sf.getString("addr:street"))
.setAttr("kind", "address")
.setMinZoom(15);
}
}
}

@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) throws GeometryException {
if (zoom == 15) {
return items;
List<VectorTile.Feature> buildings = new ArrayList<>();

// deduplicate addresses
HashMap<Map<String, Object>, List<VectorTile.Feature>> groupedAddresses = new LinkedHashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to address one building that is labeled twice on the map? Is there a specific place in the world where that problem is pervasive or is it an edge case where maybe it's a data problem in OSM?

Copy link
Member

Choose a reason for hiding this comment

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

NVM, I see the issue is that it also includes POIs that have an addr:housenumber in OSM. I think for the first pass we should limit the house number displays to just those tagged on buildings and not POIs, because de-duplicating them in post-process is going to lead to non-deterministic results potentially, and ideally POIs will be labeled by an icon symbology instead of just a housenumber. What do you think? Labeling on OSM Carto seems to be focused on the building addr:housenumber too.

for (VectorTile.Feature item : items) {
if (item.tags().containsKey("addr_housenumber")) {
groupedAddresses.computeIfAbsent(item.tags(), k -> new ArrayList<>()).add(item);
} else {
buildings.add(item);
}
}

for (var address : groupedAddresses.values()) {
var feature = address.get(0);
feature.tags().remove("addr_street");
bdon marked this conversation as resolved.
Show resolved Hide resolved
buildings.add(feature);
}

return buildings;
}
items = Area.filterArea(items, 0);

Expand Down Expand Up @@ -151,7 +189,6 @@ public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> i
}
}
}

return FeatureMerge.mergeNearbyPolygons(items, 3.125, 3.125, 0.5, 0.5);
}
}
Loading