48 KiB
Special tag renderings
In a tagrendering, some special values are substituted by an advanced UI-element. This allows advanced features and visualizations to be reused by custom themes or even to query third-party API's.
General usage is {func_name()}
, {func_name(arg, someotherarg)}
or {func_name(args):cssClasses}
. Note that you do not need to use quotes around your arguments, the comma is enough to separate them. This also implies you cannot use a comma in your args
Table of contents
Using expanded syntax
Instead of using {"render": {"en": "{some_special_visualisation(some_arg, some other really long message, more args)} , "nl": "{some_special_visualisation(some_arg, een boodschap in een andere taal, more args)}}
, one can also write
{
"render": {
"special": {
"type": "some_special_visualisation",
"argname": "some_arg",
"message": {
"en": "some other really long message",
"nl": "een boodschap in een andere taal"
},
"other_arg_name": "more args"
},
"before": {
"en": "Some text to prefix before the special element (e.g. a title)",
"nl": "Een tekst om voor het element te zetten (bv. een titel)"
},
"after": {
"en": "Some text to put after the element, e.g. a footer"
}
}
}
In other words: use { "before": ..., "after": ..., "special": {"type": ..., "argname": ...argvalue...}
. The args are in the special
block; an argvalue can be a string, a translation or another value. (Refer to class RewriteSpecial
in case of problems)
Overview of all special components
data_import
Elements to help with importing data to OSM. For example: buttons to import a feature, apply tags on an element, apply multiple tags on an element or to work with maproulette
compare_data
Gives an interactive element which shows a tag comparison between the OSM-object and the upstream object. This allows to copy some or all tags into OSM
name | default | description |
---|---|---|
url | undefined | The attribute containing the url where to fetch more data |
host | undefined | The domain name(s) where data might be fetched from - this is needed to set the CSP. A domain must include 'https', e.g. 'https://example.com'. For multiple domains, separate them with ';'. If you don't know the possible domains, use '*'. |
readonly | undefined | If 'yes', will not show 'apply'-buttons |
Example usage of compare_data
{compare_data(,,)}
conflate_button
This button will modify the geometry of an existing OSM way to match the specified geometry. This can conflate OSM-ways with LineStrings and Polygons (only simple polygons with one single ring). An attempt is made to move points with special values to a decent new location (e.g. entrances)
Note that the contributor must zoom to at least zoomlevel 18 to be able to use this functionality. It is only functional in official themes, but can be tested in unoffical themes.
Specifying which tags to copy or add
The argument `tags` of the import button takes a `;`-seperated list of tags to add (or the name of a property which contains a JSON-list of properties).
These can either be a tag to add, such as amenity=fast_food
or can use a substitution, e.g. addr:housenumber=$number
.
This new point will then have the tags amenity=fast_food
and addr:housenumber
with the value that was saved in number
in the original feature.
If a value to substitute is undefined, empty string will be used instead.
This supports multiple values, e.g. ref=$source:geometry:type/$source:geometry:ref
Remark that the syntax is slightly different then expected; it uses '$' to note a value to copy, followed by a name (matched with [a-zA-Z0-9_:]*
). Sadly, delimiting with {}
as these already mark the boundaries of the special rendering...
Note that these values can be prepare with javascript in the theme by using a calculatedTag
Importing a dataset into OpenStreetMap: requirements
If you want to import a dataset, make sure that:
- The dataset to import has a suitable license
- The community has been informed of the import
- All other requirements of the import guidelines have been followed
There are also some technicalities in your theme to keep in mind:
- The new feature will be added and will flow through the program as any other new point as if it came from OSM. This means that there should be a layer which will match the new tags and which will display it.
- The original feature from your geojson layer will gain the tag '_imported=yes'. This should be used to change the appearance or even to hide it (eg by changing the icon size to zero)
- There should be a way for the theme to detect previously imported points, even after reloading. A reference number to the original dataset is an excellent way to do this
- When importing ways, the theme creator is also responsible of avoiding overlapping ways.
Disabled in unofficial themes
The import button can be tested in an unofficial theme by adding test=true
or backend=osm-test
as URL-paramter.
The import button will show up then. If in testmode, you can read the changeset-XML directly in the web console.
In the case that MapComplete is pointed to the testing grounds, the edit will be made on https://master.apis.dev.openstreetmap.org
name | default | description |
---|---|---|
targetLayer | undefined | The id of the layer where this point should end up. This is not very strict, it will simply result in checking that this layer is shown preventing possible duplicate elements |
tags | undefined | The tags to add onto the new object - see specification above. If this is a key (a single word occuring in the properties of the object), the corresponding value is taken and expanded instead |
text | Import this data into OpenStreetMap | The text to show on the button |
icon | ./assets/svg/addSmall.svg | A nice icon to show in the button |
way_to_conflate | undefined | The key, of which the corresponding value is the id of the OSM-way that must be conflated; typically a calculatedTag |
Example usage of conflate_button
{conflate_button(,,Import this data into OpenStreetMap,./assets/svg/addSmall.svg,)}
import_button
This button will copy the point from an external dataset into OpenStreetMap
Note that the contributor must zoom to at least zoomlevel 18 to be able to use this functionality. It is only functional in official themes, but can be tested in unoffical themes.
Specifying which tags to copy or add
The argument `tags` of the import button takes a `;`-seperated list of tags to add (or the name of a property which contains a JSON-list of properties).
These can either be a tag to add, such as amenity=fast_food
or can use a substitution, e.g. addr:housenumber=$number
.
This new point will then have the tags amenity=fast_food
and addr:housenumber
with the value that was saved in number
in the original feature.
If a value to substitute is undefined, empty string will be used instead.
This supports multiple values, e.g. ref=$source:geometry:type/$source:geometry:ref
Remark that the syntax is slightly different then expected; it uses '$' to note a value to copy, followed by a name (matched with [a-zA-Z0-9_:]*
). Sadly, delimiting with {}
as these already mark the boundaries of the special rendering...
Note that these values can be prepare with javascript in the theme by using a calculatedTag
Importing a dataset into OpenStreetMap: requirements
If you want to import a dataset, make sure that:
- The dataset to import has a suitable license
- The community has been informed of the import
- All other requirements of the import guidelines have been followed
There are also some technicalities in your theme to keep in mind:
- The new feature will be added and will flow through the program as any other new point as if it came from OSM. This means that there should be a layer which will match the new tags and which will display it.
- The original feature from your geojson layer will gain the tag '_imported=yes'. This should be used to change the appearance or even to hide it (eg by changing the icon size to zero)
- There should be a way for the theme to detect previously imported points, even after reloading. A reference number to the original dataset is an excellent way to do this
- When importing ways, the theme creator is also responsible of avoiding overlapping ways.
Disabled in unofficial themes
The import button can be tested in an unofficial theme by adding test=true
or backend=osm-test
as URL-paramter.
The import button will show up then. If in testmode, you can read the changeset-XML directly in the web console.
In the case that MapComplete is pointed to the testing grounds, the edit will be made on https://master.apis.dev.openstreetmap.org
name | default | description |
---|---|---|
targetLayer | undefined | The id of the layer where this point should end up. This is not very strict, it will simply result in checking that this layer is shown preventing possible duplicate elements |
tags | undefined | The tags to add onto the new object - see specification above. If this is a key (a single word occuring in the properties of the object), the corresponding value is taken and expanded instead |
text | Import this data into OpenStreetMap | The text to show on the button |
icon | ./assets/svg/addSmall.svg | A nice icon to show in the button |
snap_onto_layers | undefined | If a way of the given layer(s) is closeby, will snap the new point onto this way (similar as preset might snap). To show multiple layers to snap onto, use a ; -seperated list |
max_snap_distance | 5 | The maximum distance that the imported point will be moved to snap onto a way in an already existing layer (in meters). This is previewed to the contributor, similar to the 'add new point'-action of MapComplete |
note_id | undefined | If given, this key will be read. The corresponding note on OSM will be closed, stating 'imported' |
maproulette_id | undefined | The property name of the maproulette_id - this is probably mr_taskId . If given, the maproulette challenge will be marked as fixed. Only use this if part of a maproulette-layer. |
to_point | undefined | If set, a feature will be converted to a centerpoint |
Example usage of import_button
{import_button(,,Import this data into OpenStreetMap,./assets/svg/addSmall.svg,,5,,,)}
import_way_button
This button will copy the data from an external dataset into OpenStreetMap, copying the geometry and adding it as a 'line'
Note that the contributor must zoom to at least zoomlevel 18 to be able to use this functionality. It is only functional in official themes, but can be tested in unoffical themes.
Specifying which tags to copy or add
The argument `tags` of the import button takes a `;`-seperated list of tags to add (or the name of a property which contains a JSON-list of properties).
These can either be a tag to add, such as amenity=fast_food
or can use a substitution, e.g. addr:housenumber=$number
.
This new point will then have the tags amenity=fast_food
and addr:housenumber
with the value that was saved in number
in the original feature.
If a value to substitute is undefined, empty string will be used instead.
This supports multiple values, e.g. ref=$source:geometry:type/$source:geometry:ref
Remark that the syntax is slightly different then expected; it uses '$' to note a value to copy, followed by a name (matched with [a-zA-Z0-9_:]*
). Sadly, delimiting with {}
as these already mark the boundaries of the special rendering...
Note that these values can be prepare with javascript in the theme by using a calculatedTag
Importing a dataset into OpenStreetMap: requirements
If you want to import a dataset, make sure that:
- The dataset to import has a suitable license
- The community has been informed of the import
- All other requirements of the import guidelines have been followed
There are also some technicalities in your theme to keep in mind:
- The new feature will be added and will flow through the program as any other new point as if it came from OSM. This means that there should be a layer which will match the new tags and which will display it.
- The original feature from your geojson layer will gain the tag '_imported=yes'. This should be used to change the appearance or even to hide it (eg by changing the icon size to zero)
- There should be a way for the theme to detect previously imported points, even after reloading. A reference number to the original dataset is an excellent way to do this
- When importing ways, the theme creator is also responsible of avoiding overlapping ways.
Disabled in unofficial themes
The import button can be tested in an unofficial theme by adding test=true
or backend=osm-test
as URL-paramter.
The import button will show up then. If in testmode, you can read the changeset-XML directly in the web console.
In the case that MapComplete is pointed to the testing grounds, the edit will be made on https://master.apis.dev.openstreetmap.org
name | default | description |
---|---|---|
targetLayer | undefined | The id of the layer where this point should end up. This is not very strict, it will simply result in checking that this layer is shown preventing possible duplicate elements |
tags | undefined | The tags to add onto the new object - see specification above. If this is a key (a single word occuring in the properties of the object), the corresponding value is taken and expanded instead |
text | Import this data into OpenStreetMap | The text to show on the button |
icon | ./assets/svg/addSmall.svg | A nice icon to show in the button |
snap_to_point_if | undefined | Points with the given tags will be snapped to or moved |
max_snap_distance | 0.05 | If the imported object is a LineString or (Multi)Polygon, already existing OSM-points will be reused to construct the geometry of the newly imported way |
move_osm_point_if | undefined | Moves the OSM-point to the newly imported point if these conditions are met |
max_move_distance | 0.05 | If an OSM-point is moved, the maximum amount of meters it is moved. Capped on 20m |
snap_onto_layers | undefined | If no existing nearby point exists, but a line of a specified layer is closeby, snap to this layer instead |
snap_to_layer_max_distance | 0.1 | Distance to distort the geometry to snap to this layer |
Example usage of import_way_button
{import_way_button(,,Import this data into OpenStreetMap,./assets/svg/addSmall.svg,,0.05,,0.05,,0.1)}
linked_data_from_website
Attempts to load (via a proxy) the specified website and parsed ld+json from there. Suitable data will be offered to import into OSM. Note: this element is added by default
name | default | description |
---|---|---|
key | website | Attempt to load ld+json from the specified URL. This can be in an embedded |