-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
LayerConfigJson.ts
604 lines (569 loc) · 24.8 KB
/
LayerConfigJson.ts
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
import { TagConfigJson } from "./TagConfigJson"
import { TagRenderingConfigJson } from "./TagRenderingConfigJson"
import FilterConfigJson from "./FilterConfigJson"
import { DeleteConfigJson } from "./DeleteConfigJson"
import UnitConfigJson from "./UnitConfigJson"
import MoveConfigJson from "./MoveConfigJson"
import PointRenderingConfigJson from "./PointRenderingConfigJson"
import LineRenderingConfigJson from "./LineRenderingConfigJson"
import { QuestionableTagRenderingConfigJson } from "./QuestionableTagRenderingConfigJson"
import RewritableConfigJson from "./RewritableConfigJson"
import { Translatable } from "./Translatable"
/**
* Configuration for a single layer
*/
export interface LayerConfigJson {
/**
* question: What is the identifier of this layer?
*
* This should be a simple, lowercase, human readable string that is used to identify the layer.
* A good ID is:
* - a noun
* - written in singular
* - describes the object
* - in english
* - only has lowercase letters, numbers or underscores. Do not use a space or a dash
*
* type: id
* group: Basic
*/
id: string
/**
* Used in the layer control panel to toggle a layer on and of.
*
* ifunset: This will hide the layer in the layer control, making it not filterable and not toggleable
*
* group: Basic
* question: What is the name of this layer?
*/
name?: Translatable
/**
* question: How would you describe the features that are shown on this layer?
*
* A description for the features shown in this layer.
* This often resembles the introduction of the wiki.osm.org-page for this feature.
*
* group: Basic
*/
description?: Translatable
/**
* question: What are some other terms used to describe these objects?
*
* This is used in the search functionality
*/
searchTerms?: Record<string, string[]>
/**
* Question: Where should the data be fetched from?
* title: Data Source
*
* This determines where the data for the layer is fetched: from OSM or from an external geojson dataset.
*
* If no 'geojson' is defined, data will be fetched from overpass and the OSM-API.
*
* Every source _must_ define which tags _must_ be present in order to be picked up.
*
* Note: a source must always be defined. 'special' is only allowed if this is a builtin-layer
*
* types: Load data with specific tags from OpenStreetMap ; Load data from an external geojson source ;
* typesdefault: 0
* ifunset: Determine the tags automatically based on the presets
* group: Basic
*/
source:
| undefined
| "special"
| "special:library"
| {
/**
* question: Which tags must be present on the feature to show it in this layer?
* Every source must set which tags have to be present in order to load the given layer.
*/
osmTags: TagConfigJson
}
| {
/**
* The actual source of the data to load, if loaded via geojson.
*
* # A single geojson-file
* source: {geoJson: "https://my.source.net/some-geo-data.geojson"}
* fetches a geojson from a third party source
*
* # A tiled geojson source
* source: {geoJson: "https://my.source.net/some-tile-geojson-{layer}-{z}-{x}-{y}.geojson", geoJsonZoomLevel: 14}
* to use a tiled geojson source. The web server must offer multiple geojsons. {z}, {x} and {y} are substituted by the location; {layer} is substituted with the id of the loaded layer
*
* Some API's use a BBOX instead of a tile, this can be used by specifying {y_min}, {y_max}, {x_min} and {x_max}
*
* question: What is the URL of the geojson?
* type: url
*/
geoJson: string
/**
* To load a tiled geojson layer, set the zoomlevel of the tiles
*
* question: If using a tiled geojson, what is the zoomlevel of the tiles?
* ifunset: This is not a tiled geojson
*/
geoJsonZoomLevel?: number
/**
* Some API's use a mercator-projection (EPSG:900913) instead of WGS84. Set the flag `mercatorCrs: true` in the source for this
*
* question: Does this geojson use EPSG:900913 instead of WGS84 as projection?
* iftrue: This geojson uses EPSG:900913 instead of WGS84
* ifunset: This geojson uses WGS84 just like most geojson (default)
*/
mercatorCrs?: boolean
/**
* Some API's have an id-field, but give it a different name.
* Setting this key will rename this field into 'id'
*
* ifunset: An id with key `id` will be assigned automatically if no attribute `id` is set
* inline: This geojson uses <b>{value}</b> as attribute to set the id
* question: What is the name of the attribute containing the ID of the object?
*/
idKey?: string
}
/**
*
* A list of extra tags to calculate, specified as "keyToAssignTo=javascript-expression".
* There are a few extra functions available. Refer to <a>Docs/CalculatedTags.md</a> for more information
* The functions will be run in order, e.g.
* [
* "_max_overlap_m2=Math.max(...feat.overlapsWith("someOtherLayer").map(o => o.overlap))
* "_max_overlap_ratio=Number(feat._max_overlap_m2)/feat.area
* ]
*
* The specified tags are evaluated lazily. E.g. if a calculated tag is only used in the popup (e.g. the number of nearby features),
* the expensive calculation will only be performed then for that feature. This avoids clogging up the contributors PC when all features are loaded.
*
* If a tag has to be evaluated strictly, use ':=' instead:
*
* [
* "_some_key:=some_javascript_expression"
* ]
*
* See the full documentation on [https://github.com/pietervdvn/MapComplete/blob/master/Docs/CalculatedTags.md]
*
* group: expert
* question: What extra attributes should be calculated with javascript?
*
*/
calculatedTags?: string[]
/**
* If set, only features matching this extra tag will be shown.
* This is useful to hide certain features from view based on a calculated tag or if the features are provided by a different layer.
*
* question: What other tags should features match for being shown?
* group: advanced
* ifunset: all features which match the 'source'-specification are shown.
*/
isShown?: TagConfigJson
/**
* question: should this layer be included in the summary counts?
*
* The layer server can give summary counts for a tile.
* This should however be disabled for some layers, e.g. because there are too many features (walls_and_buildings) or because the count is irrelevant.
*
* ifunset: Do count
* iffalse: Do not include the counts
* iftrue: Do include the count
*/
isCounted?: true | boolean
/**
* The minimum needed zoomlevel required to start loading and displaying the data.
* This can be used to only show common features (e.g. a bicycle parking) only when the map is zoomed in very much (17).
* This prevents cluttering the map with thousands of parkings if one is looking to an entire city.
*
* Default: 0
* group: Basic
* type: nat
* question: At what zoom level should features of the layer be shown?
* ifunset: Always load this layer, even if the entire world is in view.
*/
minzoom?: number
/**
* Indicates if this layer is shown by default;
* can be used to hide a layer from start, or to load the layer but only to show it when appropriate (e.g. for advanced users)
*
* question: Should this layer be enabled when opening the map for the first time?
* iftrue: the layer is enabled when opening the map
* iffalse: the layer is hidden until the contributor enables it. (If the filter-popup is disabled, this might never get enabled nor loaded)
* default: true
* group: advanced
*/
shownByDefault?: true | boolean
/**
* The zoom level at which point the data is hidden again
* Default: 100 (thus: always visible
*
* group: expert
*/
minzoomVisible?: number
/**
* question: Edit the popup title
* The title shown in a popup for elements of this layer.
*
* group: title
* types: use a fixed translation ; Use a dynamic tagRendering ; hidden
* typesdefault: 1
* type: translation
* inline: {translated{value}}
*/
title?: TagRenderingConfigJson | Translatable
/**
*
* Question: Should the information for this layer be shown in the sidebar or in a splash screen?
*
* If set, open the selectedElementView in a floatOver instead of on the right.
*
* iftrue: show the infobox in the splashscreen floating over the entire UI; hide the title bar
* iffalse: show the infobox in a sidebar on the right
* suggestions: return [{if: "value=title", then: "Show in a floatover and show the title bar"}]
* group: advanced
* default: sidebar
*/
popupInFloatover?: boolean | "title" | string
/**
* Small icons shown next to the title.
* If not specified, the OsmLink and wikipedia links will be used by default.
* Use an empty array to hide them.
* Note that "defaults" will insert all the default titleIcons (which are added automatically)
*
* Use `auto:<tagrenderingId>` to automatically create an icon based on a tagRendering which has icons
*
* Type: icon[]
* group: infobox
*/
titleIcons?: (string | (TagRenderingConfigJson & { id?: string }))[] | ["defaults"]
/**
* Creates points to render on the map.
* This can render points for point-objects, lineobjects or areaobjects; use 'location' to indicate where it should be rendered.
*
* Note that all attributes - including [the calculated tags](https://github.com/pietervdvn/MapComplete/blob/develop/Docs/CalculatedTags.md) can be used to create the markers and lines
*
* group: pointrendering
*/
pointRendering: PointRenderingConfigJson[]
/**
* Creates lines and areas to render on the map
* group: linerendering
*/
lineRendering?: LineRenderingConfigJson[]
/**
* If set, this layer will pass all the features it receives onto the next layer.
* This is ideal for decoration, e.g. directions on cameras
* iftrue: Make the features from this layer also available to the other layer; might result in this object being rendered by multiple layers
* iffalse: normal behaviour: don't pass features allong
* question: should this layer pass features to the next layers?
* group: expert
*/
passAllFeatures?: boolean
/**
* If set, this layer will not query overpass; but it'll still match the tags above which are by chance returned by other layers.
* Works well together with 'passAllFeatures', to add decoration
* The opposite of `forceLoad`
*
* iftrue: Do not attempt to query the data for this layer from overpass/the OSM API
* iffalse: download the data as usual
* group: expert
* question: Should this layer be downloaded or is the data provided by a different layer (which has 'passAllFeatures'-set)?
* default: false
*/
doNotDownload?: boolean
/**
* Advanced option - might be set by the theme compiler
*
* If true, this data will _always_ be loaded, even if the theme is disabled by a filter or hidden.
* The opposite of `doNotDownload`
*
* question: Should this layer be forcibly loaded?
* ifftrue: always download this layer, even if it is disabled
* iffalse: only download data for this layer when needed (default)
* default: false
* group: expert
*/
forceLoad?: false | boolean
/**
* <div class='flex'>
* <div>
* Presets for this layer.
*
* A preset consists of one or more attributes (tags), a title and optionally a description and optionally example images.
*
* When the contributor wishes to add a point to OpenStreetMap, they'll:
*
* 1. Press the 'add new point'-button
* 2. Choose a preset from the list of all presets
* 3. Confirm the choice. In this step, the `description` (if set) and `exampleImages` (if given) will be shown
* 4. Confirm the location
* 5. A new point will be created with the attributes that were defined in the preset
*
* If no presets are defined, the button which invites to add a new preset will not be shown.
*</div>
* <video controls autoplay muted src='./Docs/Screenshots/AddNewItemScreencast.webm' class='w-64'/>
*</div>
*
* group: presets
* title: value.title
*/
presets?: {
/**
* The title - shown on the 'add-new'-button.
*
* This should include the article of the noun, e.g. 'a hydrant', 'a bicycle pump'.
* This text will be inserted into `Add {category} here`, becoming `Add a hydrant here`.
*
* Do _not_ indicate 'new': 'add a new shop here' is incorrect, as the shop might have existed forever, it could just be unmapped!
*
* question: What is the word to describe this object?
* inline: Add {translated(value)::font-bold} here
*/
title: Translatable
/**
* A single tag (encoded as <code>key=value</code>) out of all the tags to add onto the newly created point.
* Note that the icon in the UI will be chosen automatically based on the tags provided here.
*
* question: What tag should be added to the new object?
* type: simple_tag
* typeHelper: uploadableOnly
*/
tags: string[]
/**
* An extra explanation of what the feature is, if it is not immediately clear from the title alone.
*
* The _first sentence_ of the description is shown on the button of the `add` menu.
* The full description is shown in the confirmation dialog.
*
* (The first sentence is until the first '.'-character in the description)
*
* question: How would you describe this feature?
* ifunset: No extra description is given. This can be used to further explain the preset
*/
description?: Translatable
/**
* The URL of an example image which shows a real-life example of what such a feature might look like.
*
* Type: image
* question: What is the URL of an image showing such a feature?
*/
exampleImages?: string[]
/**
* question: Should the created point be snapped to a line layer?
*
* If specified, these layers will be shown in the precise location picker and the new point will be snapped towards it.
* For example, this can be used to snap against `walls_and_buildings` (e.g. to attach a defibrillator, an entrance, an artwork, ... to the wall)
* or to snap an obstacle (such as a bollard) to the `cycleways_and_roads`.
*
* suggestions: return Array.from(layers.keys()).map(key => ({if: "value="+key, then: key+" - "+layers.get(key).description}))
*/
snapToLayer?: string[]
/**
* question: What is the maximum distance in the location-input that a point can be moved to be snapped to a way?
*
* inline: a point is snapped if the location input is at most <b>{value}m</b> away from an object
*
* If specified, a new point will only be snapped if it is within this range.
* If further away, it'll be placed in the center of the location input
* Distance in meter
*
* ifunset: Do not snap to a layer
*/
maxSnapDistance?: number
}[]
/**
* question: Edit this way this attributed is displayed or queried
*
* A tag rendering is a block that either shows the known value or asks a question.
*
* Refer to the class `TagRenderingConfigJson` to see the possibilities.
*
* Note that we can also use a string here - where the string refers to a tag rendering defined in `assets/questions/questions.json`,
* where a few very general questions are defined e.g. website, phone number, ...
* Furthermore, _all_ the questions of another layer can be reused with `otherlayer.*`
* If you need only a single of the tagRenderings, use `otherlayer.tagrenderingId`
* If one or more questions have a 'group' or 'label' set, select all the entries with the corresponding group or label with `otherlayer.*group`
* Remark: if a tagRendering is 'lent' from another layer, the 'source'-tags are copied and added as condition.
* If they are not wanted, remove them with an override
*
* A special value is 'questions', which indicates the location of the questions box. If not specified, it'll be appended to the bottom of the featureInfobox.
*
* At last, one can define a group of renderings where parts of all strings will be replaced by multiple other strings.
* This is mainly create questions for a 'left' and a 'right' side of the road.
* These will be grouped and questions will be asked together
*
* type: tagrendering[]
* group: tagrenderings
*
*/
tagRenderings?: (
| string
| {
id?: string
builtin: string | string[]
override: Partial<QuestionableTagRenderingConfigJson>
}
| QuestionableTagRenderingConfigJson
| (RewritableConfigJson<
(
| string
| { builtin: string; override: Partial<QuestionableTagRenderingConfigJson> }
| QuestionableTagRenderingConfigJson
)[]
> & { id: string })
)[]
/**
* All the extra questions for filtering.
* If a string is given, mapComplete will search in
* 1. The tagrenderings for a match on ID and use the mappings as options
* 2. search 'filters.json' for the appropriate filter or
* 3. will try to parse it as `layername.filterid` and us that one.
*
* Note: adding "#filter":"no-auto" will disable the filters added by tagRenderings
*
* group: filters
*/
filter?: (FilterConfigJson | string)[] | { sameAs: string }
/**
* Set this to disable the feature that tagRenderings can introduce filters
*/
"#filter"?: "no-auto"
/**
* This block defines under what circumstances the delete dialog is shown for objects of this layer.
* If set, a dialog is shown to the user to (soft) delete the point.
* The dialog is built to be user friendly and to prevent mistakes.
* If deletion is not possible, the dialog will hide itself and show the reason of non-deletability instead.
*
* To configure, the following values are possible:
*
* - false: never ever show the delete button
* - true: show the default delete button
* - undefined: use the mapcomplete default to show deletion or not. Currently, this is the same as 'false' but this will change in the future
* - or: a hash with options (see below)
*
* ### The delete dialog
*
*
*
* #### Hard deletion if enough experience
* A feature can only be deleted from OpenStreetMap by mapcomplete if:
* - It is a node
* - No ways or relations use the node
* - The logged-in user has enough experience OR the user is the only one to have edited the point previously
* - The logged-in user has no unread messages (or has a ton of experience)
* - The user did not select one of the 'non-delete-options' (see below)
*
* In all other cases, a 'soft deletion' is used.
*
* #### Soft deletion
*
* A 'soft deletion' is when the point isn't deleted fromOSM but retagged so that it'll won't how up in the mapcomplete theme anymore.
* This makes it look like it was deleted, without doing damage. A fixme will be added to the point.
*
* Note that a soft deletion is _only_ possible if these tags are provided by the theme creator, as they'll be different for every theme
*
* ##### No-delete options
*
* In some cases, the contributor might want to delete something for the wrong reason (e.g. someone who wants to have a path removed "because the path is on their private property").
* However, the path exists in reality and should thus be on OSM - otherwise the next contributor will pass by and notice "hey, there is a path missing here! Let me redraw it in OSM!)
*
* The correct approach is to retag the feature in such a way that it is semantically correct *and* that it doesn't show up on the theme anymore.
* A no-delete option is offered as 'reason to delete it', but secretly retags.
*
* group: editing
* types: Use an advanced delete configuration ; boolean
* iftrue: Allow deletion
* iffalse: Do not allow deletion
* ifunset: Do not allow deletion
*
**/
deletion?: DeleteConfigJson | boolean
/**
* Indicates if a point can be moved and why.
*
* A feature can be moved by MapComplete if:
*
* - It is a point
* - The point is _not_ part of a way or a a relation.
*
* types: use an advanced move configuration ; boolean
* group: editing
* question: Is deleting a point allowed?
* iftrue: Allow contributors to move a point (for accuracy or a relocation)
* iffalse: Don't allow contributors to move points
* ifunset: Don't allow contributors to move points (default)
*/
allowMove?: MoveConfigJson | boolean
/**
* If set, a 'split this way' button is shown on objects rendered as LineStrings, e.g. highways.
*
* If the way is part of a relation, MapComplete will attempt to update this relation as well
* question: Should the contributor be able to split ways using this layer?
* iftrue: enable the 'split-roads'-component
* iffalse: don't enable the split-roads component
* ifunset: don't enable the split-roads component
* group: editing
*/
allowSplit?: boolean
/**
* Either a list with [{"key": "unitname", "key2": {"quantity": "unitname", "denominations": ["denom", "denom"]}}]
*
* Use `"inverted": true` if the amount should be _divided_ by the denomination, e.g. for charge over time (`€5/day`)
*
* @see UnitConfigJson
*
* group: editing
*/
units?: (
| UnitConfigJson
| Record<
string,
| string
| {
quantity: string
denominations: string[]
canonical?: string
inverted?: boolean
}
>
)[]
/**
* If set, synchronizes whether this layer is enabled.
*
* group: advanced
* question: Should enabling/disabling the layer be saved (locally or in the cloud)?
* suggestions: return [{if: "value=no", then: "Don't save, always revert to the default"}, {if: "value=local", then: "Save selection in local storage"}, {if: "value=theme-only", then: "Save the state in the OSM-usersettings, but apply on this theme only (default)"}, {if: "value=global", then: "Save in OSM-usersettings and toggle on _all_ themes using this layer"}]
*/
syncSelection?: "no" | "local" | "theme-only" | "global"
/**
* Used for comments and/or to disable some checks
*
* no-question-hint-check: disables a check in MiscTagRenderingChecks which complains about 'div', 'span' or 'class=subtle'-HTML elements in the tagRendering
*
* group: hidden
*/
"#"?: string | "no-question-hint-check"
/**
* _Set automatically by MapComplete, please ignore_
*
* group: hidden
*/
fullNodeDatabase?: boolean
/**
* question: Should a theme using this layer leak some location info when making changes?
*
* When a changeset is made, a 'distance to object'-class is written to the changeset.
* For some particular themes and layers, this might leak too much information, and we want to obfuscate this
*
* ifunset: Write 'change_within_x_m' as usual and if GPS is enabled
* iftrue: Do not write 'change_within_x_m' and do not indicate that this was done by survey
*/
enableMorePrivacy?: boolean
/**
* question: When a feature is snapped to this name, how should this item be called?
*
* In the move wizard, the option `snap object onto {snapName}` is shown
*
* group: hidden
*/
snapName?: Translatable
}