Skip to content

Commit 8361051

Browse files
committed
Sea fixes
1 parent 227300c commit 8361051

File tree

1 file changed

+65
-54
lines changed
  • tiles/src/main/java/com/protomaps/basemap/layers

1 file changed

+65
-54
lines changed

tiles/src/main/java/com/protomaps/basemap/layers/Water.java

+65-54
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,55 @@ public class Water implements ForwardingProfile.LayerPostProcessor {
189189
),
190190
rule(
191191
with("place", "sea"),
192+
with("_can_be_polygon"),
193+
use("kind", "sea"),
194+
use("keepPolygon", false)
195+
),
196+
rule(
197+
with("place", "sea"),
198+
with("_can_be_polygon"),
199+
with("""
200+
name:en
201+
Caspian Sea
202+
Red Sea
203+
Persian Gulf
204+
Sea of Oman
205+
Gulf of Aden
206+
Gulf of Thailand
207+
Sea of Japan
208+
"""),
209+
use("minZoom", 5)
210+
),
211+
rule(
212+
with("place", "sea"),
213+
with("_can_be_polygon"),
214+
with("""
215+
name:en
216+
Arabian Sea
217+
Bay of Bengal
218+
Black Sea
219+
"""),
220+
use("minZoom", 3)
221+
),
222+
rule(
223+
with("place", "sea"),
224+
with("_can_be_polygon"),
225+
with("""
226+
name:en
227+
Black Sea
228+
Caspian Sea
229+
"""),
230+
use("nameOverride", fromTag("name:en"))
231+
),
232+
rule(
233+
with("place", "sea"),
234+
with("_is_point"),
192235
use("kind", "sea"),
193-
use("keepPolygon", false),
194236
use("minZoom", 6)
195237
),
196238
rule(
197239
with("place", "sea"),
240+
with("_is_point"),
198241
with("""
199242
name:en
200243
North Atlantic Ocean
@@ -216,18 +259,16 @@ public class Water implements ForwardingProfile.LayerPostProcessor {
216259
Gulf of Alaska
217260
Gulf of Guinea
218261
"""),
262+
use("kind", "sea"),
219263
use("minZoom", 3)
220264
),
221265
rule(
222266
with("place", "ocean"),
223267
use("kind", "ocean"),
224-
use("keepPolygon", false),
225268
use("minZoom", 0)
226269
)
227270
)).index();
228271

229-
230-
231272
@Override
232273
public String name() {
233274
return LAYER_NAME;
@@ -272,21 +313,16 @@ public void processNe(SourceFeature sf, FeatureCollector features) {
272313
.setMinPixelSize(1.0)
273314
.setBufferPixels(8);
274315
}
275-
276-
if (sf.getSourceLayer().equals("ne_10m_lakes") && sf.hasTag("min_label") && sf.hasTag("name")) {
277-
int minZoom = (int) Math.round(Double.parseDouble(sf.getString("min_label")));
278-
var waterLabelPosition = features.pointOnSurface(LAYER_NAME)
279-
.setAttr("kind", kind)
280-
.setAttr("min_zoom", minZoom + 1)
281-
.setZoomRange(minZoom + 1, 5)
282-
.setSortKey(minZoom)
283-
.setBufferPixels(128);
284-
285-
NeNames.setNeNames(waterLabelPosition, sf, 0);
286-
}
287316
}
288317

289318
public void processOsm(SourceFeature sf, FeatureCollector features) {
319+
if (!sf.tags().isEmpty() && sf.isPoint()) {
320+
sf.setTag("_is_point", "yes");
321+
}
322+
323+
if (!sf.tags().isEmpty() && sf.canBePolygon()) {
324+
sf.setTag("_can_be_polygon", "yes");
325+
}
290326

291327
var matches = osmIndex.getMatches(sf);
292328
if (matches.isEmpty()) {
@@ -298,6 +334,11 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
298334
return;
299335
}
300336

337+
String nameOverride = getString(sf, matches, "nameOverride", null);
338+
if (nameOverride != null) {
339+
sf.setTag("name", nameOverride);
340+
}
341+
301342
String kindDetail = getString(sf, matches, "kindDetail", null);
302343
boolean keepPolygon = getBoolean(sf, matches, "keepPolygon", true);
303344

@@ -333,19 +374,6 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
333374
.setPixelTolerance(0)
334375
.setMinZoom(minZoom);
335376

336-
// Set "brunnel" (bridge / tunnel) property where "level" = 1 is a bridge, 0 is ground level, and -1 is a tunnel
337-
// Because of MapLibre performance and draw order limitations, generally the boolean is sufficient
338-
// See also: "layer" for more complicated ±6 layering for more sophisticated graphics libraries
339-
if (sf.hasTag("bridge") && !sf.hasTag("bridge", "no")) {
340-
feat.setAttrWithMinzoom("level", 1, extraAttrMinzoom);
341-
} else if (sf.hasTag("tunnel") && !sf.hasTag("tunnel", "no")) {
342-
feat.setAttrWithMinzoom("level", -1, extraAttrMinzoom);
343-
} else if (sf.hasTag("layer", "-6", "-5", "-4", "-3", "-2", "-1")) {
344-
feat.setAttrWithMinzoom("level", -1, extraAttrMinzoom);
345-
} else {
346-
feat.setAttrWithMinzoom("level", 0, extraAttrMinzoom);
347-
}
348-
349377
OsmNames.setOsmNames(feat, sf, 0);
350378
}
351379

@@ -356,7 +384,7 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
356384
var feat = features.point(LAYER_NAME)
357385
.setId(FeatureId.create(sf))
358386
.setAttr("kind", kind)
359-
.setAttr("min_zoom", minZoom)
387+
.setAttr("min_zoom", minZoom + 1)
360388
.setSortKey(minZoom)
361389
.setMinZoom(minZoom);
362390

@@ -374,39 +402,22 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
374402
e.log("Exception in way area calculation");
375403
}
376404

377-
// We don't want to show too many water labels at early zooms else it crowds the map
378-
// TODO: (nvkelso 20230621) These numbers are super wonky, they should instead be sq meters in web mercator prj
379-
// Zoom 5 and earlier from Natural Earth instead (see above)
380-
if (wayArea > 25000) { //500000000
381-
nameMinZoom = 6;
382-
} else if (wayArea > 8000) { //500000000
383-
nameMinZoom = 7;
384-
} else if (wayArea > 3000) { //200000000
385-
nameMinZoom = 8;
386-
} else if (wayArea > 500) { //40000000
387-
nameMinZoom = 9;
388-
} else if (wayArea > 200) { //8000000
389-
nameMinZoom = 10;
390-
} else if (wayArea > 30) { //1000000
391-
nameMinZoom = 11;
392-
} else if (wayArea > 25) { //500000
393-
nameMinZoom = 12;
394-
} else if (wayArea > 0.5) { //50000
395-
nameMinZoom = 13;
396-
} else if (wayArea > 0.05) { //10000
397-
nameMinZoom = 14;
405+
for (int i = 6; i < 15; ++i) {
406+
if (wayArea > Math.pow(4, 15 - i)) {
407+
nameMinZoom = i;
408+
break;
409+
}
398410
}
399411

412+
nameMinZoom = getInteger(sf, matches, "minZoom", nameMinZoom);
413+
400414
var waterLabelPosition = features.pointOnSurface(LAYER_NAME)
401415
.setAttr("kind", kind)
402416
.setAttr("kind_detail", kindDetail)
403417
// While other layers don't need min_zoom, physical point labels do for more
404418
// predictable client-side label collisions
405419
// 512 px zooms versus 256 px logical zooms
406420
.setAttr("min_zoom", nameMinZoom + 1)
407-
.setAttrWithMinzoom("bridge", sf.getString("bridge"), extraAttrMinzoom)
408-
.setAttrWithMinzoom("tunnel", sf.getString("tunnel"), extraAttrMinzoom)
409-
.setAttrWithMinzoom("layer", Parse.parseIntOrNull(sf.getString("layer")), extraAttrMinzoom)
410421
.setMinZoom(nameMinZoom)
411422
.setAttr("sort_rank", 200)
412423
.setSortKey(nameMinZoom)

0 commit comments

Comments
 (0)