-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathawmconfig.js
More file actions
313 lines (285 loc) · 9.01 KB
/
awmconfig.js
File metadata and controls
313 lines (285 loc) · 9.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
const fs = require("fs");
const pry = require("pryjs");
const epsg4326 = "+proj=longlat +datum=WGS84 +no_defs";
const epsg3573 = "+proj=laea +lat_0=90 +lon_0=-100 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs";
// maximum extent of EPSG:3573 projection
const extent3573 = [
-20037508,
-20037508,
20037508,
20037508
];
// clipped extent of EPSG:3573 projection for this map
const clipped3573 = [
-4167630.8211728190071881,
-5397732.1324295047670603,
5396780.7497062487527728,
937306.5764416041783988
];
// TODO: Create a DSL/API to clean this up.
// AddAfter, Remove, CreateLayer, etc.
exports.LocalConfig = function (localizer, project) {
/*
* PROJECT RECONFIGURATION
*/
project.mml.name = "ArcticWebMap";
project.mml.center = [0, 0, 3];
project.mml.bounds = extent3573;
// Use EPSG:3573 PROJ4 string
project.mml.srs = epsg3573;
// extents from ne_10m_land projected into EPSG:3573
project.mml["maximum-extent"] = clipped3573;
// Cache features in RAM. Uses a lot of RAM that would better be
// used by Postgres.
// localizer.where("Layer")
// .then({
// "cache-features": "on"
// });
/*
* LAYER REMOVALS
*/
// remove antarctic layers - projection issues
// remove coasts - high-zoom coastline not needed
// remove country names - only Kalaallit Nunaat/France/Île Verte are
// displayed, which may look like favouritism to those regions
function remove(searchID) {
let index = project.mml.Layer.findIndex((l) => (l.id === searchID));
project.mml.Layer.splice(index, 1);
};
removedIDs = [
"coast-poly",
"country-names",
"icesheet-outlines",
"icesheet-poly"
].forEach((id) => { remove(id) });
/*
* LAYER EDITS
*/
// Change database name, details, projection
localizer.where("Layer")
.if({"Datasource.type": "postgis"})
.then({
"Datasource.dbname": "osm_3573",
"Datasource.password": "",
"Datasource.user": "",
"Datasource.host": "",
"Datasource.persist_connection": true,
"Datasource.estimate_extent": true,
// extent should be in database SRS
"Datasource.extent": clipped3573.join(", "),
"srs-name": "EPSG:3573",
"srs": epsg3573
});
// Use natural earth 10m for land instead of OSM
localizer.where("Layer")
.if({"Datasource.file": "data/simplified-land-polygons-complete-3857/simplified_land_polygons.shp"})
.then({
"Datasource.file": "data/ne_10m_land/ne_10m_land.shp"
});
/*
* MINZOOM ADJUSTMENTS
*/
// Adjust minzoom on water-areas
localizer.where("Layer")
.if({"id": "water-areas"})
.then({
"properties.minzoom": 5
});
// Adjust minzoom on landcover-low-zoom
localizer.where("Layer")
.if({"id": "landcover-low-zoom"})
.then({
"properties.minzoom": 7
});
// Adjust minzoom on landcover-area-symbols
localizer.where("Layer")
.if({"id": "landcover-area-symbols"})
.then({
"properties.minzoom": 7
});
// Adjust minzoom on text-poly-low-zoom
localizer.where("Layer")
.if({"id": "text-poly-low-zoom"})
.then({
"properties.minzoom": 5
});
// Adjust minzoom on capital-names
localizer.where("Layer")
.if({"id": "capital-names"})
.then({
"properties.minzoom": 5
});
// Adjust bias for cities, towns, and villages north of 60˚N.
// For places in that region:
// 1. classify in "city" category
// 2. multiply population by 100
// 3. Include villages in this layer
localizer.where("Layer")
.if({"id": "placenames-medium"})
.then({"Datasource.table":
`(SELECT
way,
name,
score,
CASE
WHEN (place = 'city') THEN 1
WHEN (ST_Covers(ST_MakeEnvelope(-180,60,0,90,4326), ST_Transform(way, 4326))) THEN 1
WHEN (place = 'town') THEN 2
ELSE 3
END as category,
round(ascii(md5(osm_id::text)) / 55) AS dir -- base direction factor on geometry to be consistent across metatiles
FROM
(SELECT
osm_id,
way,
place,
name,
(
(CASE
WHEN (tags->'population' ~ '^[0-9]{1,8}$') THEN (tags->'population')::INTEGER
WHEN (place = 'city') THEN 100000
WHEN (place = 'town') THEN 1000
WHEN (place = 'village') THEN 100
ELSE 1
END)
*
(CASE
WHEN (ST_Covers(ST_MakeEnvelope(-180,60,0,90,4326), ST_Transform(way, 4326))) THEN 100
WHEN (tags @> 'capital=>4') THEN 2
ELSE 1
END)
) AS score
FROM planet_osm_point
WHERE place IN ('city', 'town', 'village')
AND name IS NOT NULL
AND NOT (tags @> 'capital=>yes')
) as p
ORDER BY score DESC, length(name) DESC, name
) AS placenames_medium`,
"properties.minzoom": 5});
// Adjust shapefile layer file location, source projection
localizer.where("Layer")
.if({"Datasource.type": "shape"})
.then((obj) => {
obj["srs-name"] = "EPSG:3573";
obj["srs"] = epsg3573;
obj.extent = clipped3573;
obj.Datasource.extent = clipped3573;
obj.Datasource.file = obj.Datasource.file.replace(/^data/, "data/awm");
return obj;
});
/*
* LAYER ADDITIONS
*/
// Add a layer to the Layer list after the layer with id `searchID`
function addAfter(searchID, layer) {
let index = project.mml.Layer.findIndex(l => (l.id === searchID));
project.mml.Layer.splice(index+1, 0, layer);
}
// Sample layer format:
// {
// "id": "world",
// "geometry": "polygon",
// "extent": [
// -20037508,
// -20037508,
// 20037508,
// 20037508
// ],
// "srs-name": "EPSG:3573",
// "srs": "+proj=laea +lat_0=90 +lon_0=-100 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs",
// "Datasource": {
// "file": "data/awm/ne_10m_land/ne_10m_land.shp",
// "type": "shape",
// "extent": [
// -20037508,
// -20037508,
// 20037508,
// 20037508
// ]
// },
// "properties": {
// "maxzoom": 9
// }
// }
addAfter("world", {
id: "world-tint",
geometry: "raster",
"srs-name": "EPSG:3573",
srs: epsg3573,
Datasource: {
file: "data/awm/HYP_HR_SR/HYP_HR_SR.tif",
type: "gdal",
band: -1
},
properties: {
maxzoom: 12
}
});
addAfter("necountries", {
id: "lakes-low",
geometry: "polygon",
"srs-name": "EPSG:3573",
srs: epsg3573,
Datasource: {
file: "data/awm/ne_10m_lakes/ne_10m_lakes.shp",
type: "shape"
},
properties: {
maxzoom: 7
}
});
// Add bathymetry layers
let bathymetry = {
"bathymetry-10km": "ne_10m_bathymetry_A_10000",
"bathymetry-9km": "ne_10m_bathymetry_B_9000",
"bathymetry-8km": "ne_10m_bathymetry_C_8000",
"bathymetry-7km": "ne_10m_bathymetry_D_7000",
"bathymetry-6km": "ne_10m_bathymetry_E_6000",
"bathymetry-5km": "ne_10m_bathymetry_F_5000",
"bathymetry-4km": "ne_10m_bathymetry_G_4000",
"bathymetry-3km": "ne_10m_bathymetry_H_3000",
"bathymetry-2km": "ne_10m_bathymetry_I_2000",
"bathymetry-1km": "ne_10m_bathymetry_J_1000",
"bathymetry-200m": "ne_10m_bathymetry_K_200",
"bathymetry-0m": "ne_10m_bathymetry_L_0"
}
Object.keys(bathymetry).forEach((id) => {
let filename = bathymetry[id];
addAfter("necountries", {
id: id,
geometry: "polygon",
"srs-name": "EPSG:3573",
srs: epsg3573,
Datasource: {
file: `data/awm/ne_10m_bathymetry_all/${filename}.shp`,
type: "shape"
},
properties: {
maxzoom: 9
}
});
});
// Add high-quality water layer for mid and high zoom levels
addAfter("bathymetry-0m", {
id: "water-poly",
geometry: "polygon",
"srs-name": "EPSG:4326",
srs: epsg4326,
Datasource: {
file: "data/water_polygons/water-polygons-split-4326/water_polygons.shp",
type: "shape"
},
properties: {
minzoom: 10
}
});
/*
* STYLESHEET ADDITIONS
*/
// Add to stylesheets
project.mml.Stylesheet.push({
id: "../arcticwebmap.mss",
data: fs.readFileSync("./arcticwebmap.mss").toString()
});
};