Skip to content

Commit e48d912

Browse files
committed
fixes protomaps#287 to pre-collide places layer point features and reduce density / overlap
1 parent dec9f03 commit e48d912

File tree

1 file changed

+38
-19
lines changed
  • tiles/src/main/java/com/protomaps/basemap/layers

1 file changed

+38
-19
lines changed

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

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ static int getSortKey(double minZoom, int kindRank, int populationRank, long pop
3636
// (nvkelso 20230803) floats with significant single decimal precision
3737
// but results in "Too many possible values"
3838
// Order ASCENDING (smaller manually curated Natural Earth min_zoom win over larger values, across kinds)
39-
.orderByInt((int) minZoom, 0, 15)
39+
// minZoom is a float with 1 significant digit for manually curated places
40+
.orderByInt((int)(minZoom * 10), 0, 150)
4041
// Order ASCENDING (smaller values win, countries then locality then neighbourhood, breaks ties for same minZoom)
41-
.thenByInt(kindRank, 0, 6)
42+
.thenByInt(kindRank, 0, 12)
4243
// Order DESCENDING (larger values win, San Francisco rank 11 wins over Oakland rank 10)
43-
.thenByInt(populationRank, 15, 0)
44+
// Disabled to allow population log to have larger range
45+
//.thenByInt(populationRank, 15, 0)
4446
// Order DESCENDING (larger values win, Millbrea 40k wins over San Bruno 20k, both rank 7)
45-
.thenByLog(population, 1000000000, 1, 100)
47+
.thenByLog(population, 40000000, 1, 100)
4648
// Order ASCENDING (shorter strings are better than longer strings for map display and adds predictability)
4749
.thenByInt(name == null ? 0 : name.length(), 0, 31)
4850
.get();
@@ -55,15 +57,30 @@ static int getSortKey(double minZoom, int kindRank, int populationRank, long pop
5557

5658
private static final ZoomFunction<Number> LOCALITY_GRID_SIZE_ZOOM_FUNCTION =
5759
ZoomFunction.fromMaxZoomThresholds(Map.of(
58-
6, 32,
59-
7, 64
60+
3, 24,
61+
4, 24,
62+
5, 24,
63+
7, 24,
64+
8, 32,
65+
9, 32,
66+
10, 32,
67+
11, 24,
68+
14, 24,
69+
15, 16
6070
), 0);
6171

6272
private static final ZoomFunction<Number> LOCALITY_GRID_LIMIT_ZOOM_FUNCTION =
6373
ZoomFunction.fromMaxZoomThresholds(Map.of(
64-
6, 8,
65-
7, 6,
66-
9, 4
74+
3, 1,
75+
4, 1,
76+
5, 1,
77+
6, 1,
78+
8, 1,
79+
9, 1,
80+
10, 1,
81+
11, 1,
82+
14, 2,
83+
15, 3
6784
), 0);
6885

6986
public void processOsm(SourceFeature sf, FeatureCollector features) {
@@ -148,7 +165,7 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
148165
// This minZoom can be changed to smaller value in the NE data join step below
149166
minZoom = 11.0f;
150167
maxZoom = 15.0f;
151-
kindRank = 3;
168+
kindRank = 4;
152169
if (population == 0) {
153170
minZoom = 12.0f;
154171
population = 1000;
@@ -159,7 +176,7 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
159176
// This minZoom can be changed to smaller value in the NE data join step below
160177
minZoom = 11.0f;
161178
maxZoom = 15.0f;
162-
kindRank = 3;
179+
kindRank = 5;
163180
if (population == 0) {
164181
minZoom = 12.0f;
165182
population = 200;
@@ -170,7 +187,7 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
170187
// This minZoom can be changed to smaller value in the NE data join step below
171188
minZoom = 13.0f;
172189
maxZoom = 15.0f;
173-
kindRank = 3;
190+
kindRank = 6;
174191
if (population == 0) {
175192
minZoom = 14.0f;
176193
population = 100;
@@ -181,7 +198,7 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
181198
// This minZoom can be changed to smaller value in the NE data join step below
182199
minZoom = 13.0f;
183200
maxZoom = 15.0f;
184-
kindRank = 3;
201+
kindRank = 7;
185202
if (population == 0) {
186203
minZoom = 14.0f;
187204
population = 50;
@@ -193,7 +210,7 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
193210
// This minZoom can be changed to smaller value in the NE data join step below
194211
minZoom = 13.0f;
195212
maxZoom = 15.0f;
196-
kindRank = 3;
213+
kindRank = 8;
197214
if (population == 0) {
198215
minZoom = 14.0f;
199216
population = 1000;
@@ -204,19 +221,19 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
204221
kind = "neighbourhood";
205222
minZoom = 11.0f;
206223
maxZoom = 15.0f;
207-
kindRank = 4;
224+
kindRank = 9;
208225
break;
209226
case "quarter":
210227
kind = "macrohood";
211228
minZoom = 10.0f;
212229
maxZoom = 15.0f;
213-
kindRank = 5;
230+
kindRank = 10;
214231
break;
215232
case "neighbourhood":
216233
kind = "neighbourhood";
217234
minZoom = 12.0f;
218235
maxZoom = 15.0f;
219-
kindRank = 6;
236+
kindRank = 11;
220237
break;
221238
}
222239

@@ -287,12 +304,14 @@ public void processOsm(SourceFeature sf, FeatureCollector features) {
287304
//feat.setSortKey(minZoom * 1000 + 400 - populationRank * 200 + placeNumber.incrementAndGet());
288305
feat.setSortKey(getSortKey(minZoom, kindRank, populationRank, population, sf.getString("name")));
289306

307+
// This is only necessary when prepping for raster renderers
308+
feat.setBufferPixels(16);
309+
290310
// We set the sort keys so the label grid can be sorted predictably (bonus: tile features also sorted)
291311
// NOTE: The buffer needs to be consistent with the innteral grid pixel sizes
292312
//feat.setPointLabelGridSizeAndLimit(13, 64, 4); // each cell in the 4x4 grid can have 4 items
293313
feat.setPointLabelGridPixelSize(LOCALITY_GRID_SIZE_ZOOM_FUNCTION)
294-
.setPointLabelGridLimit(LOCALITY_GRID_LIMIT_ZOOM_FUNCTION)
295-
.setBufferPixels(64);
314+
.setPointLabelGridLimit(LOCALITY_GRID_LIMIT_ZOOM_FUNCTION);
296315

297316
// and also whenever you set a label grid size limit, make sure you increase the buffer size so no
298317
// label grid squares will be the consistent between adjacent tiles

0 commit comments

Comments
 (0)