MapComplete/Docs/SpecialRenderings.md

61 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

  1. Special tag renderings
  2. Using expanded syntax
  3. Overview of all special components

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

UI

braced

Show a literal text within braces

name default description
text undefined The value to show

Defined in /src/UI/SpecialVisualisations/UISpecialVisualisations.ts#L332

Example usage of braced

{braced()}

create_copy

Allow to create a copy of the current element

Defined in /src/UI/SpecialVisualisations/UISpecialVisualisations.ts#L356

Example usage of create_copy

{create_copy()}

title

Shows the title of the popup. Useful for some cases, e.g. 'What is phone number of {title()}?'

Defined in /src/UI/SpecialVisualisations/UISpecialVisualisations.ts#L311

Example usage of title

What is the phone number of {title()}, which might automatically become What is the phone number of XYZ.

translated

If the given key can be interpreted as a JSON, only show the key containing the current language (or 'en'). This specialRendering is meant to be used by MapComplete studio and is not useful in map themes

name default description
key value The attribute to interpret as json

Defined in /src/UI/SpecialVisualisations/UISpecialVisualisations.ts#L277

Example usage of translated

{translated(value)}

data

Visualises data of a POI, sometimes with data updating capabilities

all_tags

Prints all key-value pairs of the object - used for debugging

Defined in /src/UI/Popup/DataVisualisations.ts#L283

Example usage of all_tags

{all_tags()}

canonical

Converts a short, canonical value into the long, translated text including the unit. This only works if a unit is defined for the corresponding value. The unit specification will be included in the text.

name default description
key undefined The key of the tag to give the canonical text for

Defined in /src/UI/Popup/DataVisualisations.ts#L169

Example usage of canonical

If the object has length=42, then {canonical(length)} will be shown as 42 meter (in english), 42 metre (in french), ...

direction_absolute

Converts compass degrees (with 0° being north, 90° being east, ...) into a human readable, translated direction such as 'north', 'northeast'

name default description
key _direction:centerpoint The attribute containing the degrees
offset 0 Offset value that is added to the actual value, e.g. 180 to indicate the opposite (backward) direction

Defined in /src/UI/Popup/DataVisualisations.ts#L45

Example usage of direction_absolute

{direction_absolute(_direction:centerpoint,0)}

direction_indicator

Gives a distance indicator and a compass pointing towards the location from your GPS-location. If clicked, centers the map on the object

Defined in /src/UI/Popup/DataVisualisations.ts#L27

Example usage of direction_indicator

{direction_indicator()}

opening_hours_state

A small element, showing if the POI is currently open and when the next change is

name default description
key opening_hours The tagkey from which the opening hours are read.
prefix empty string Remove this string from the start of the value before parsing. Note: use &LPARENs to indicate ( if needed
postfix empty string Remove this string from the end of the value before parsing. Note: use &RPARENs to indicate ) if needed

Defined in /src/UI/Popup/DataVisualisations.ts#L128

Example usage of opening_hours_state

{opening_hours_state(opening_hours,,)}

opening_hours_table

Creates an opening-hours table. Usage: {opening_hours_table(opening_hours)} to create a table of the tag 'opening_hours'.

name default description
key opening_hours The tagkey from which the table is constructed.
prefix empty string Remove this string from the start of the value before parsing. Note: use &LPARENs to indicate ( if needed
postfix empty string Remove this string from the end of the value before parsing. Note: use &RPARENs to indicate ) if needed

Defined in /src/UI/Popup/DataVisualisations.ts#L89

Example usage of opening_hours_table

A normal opening hours table can be invoked with {opening_hours_table()}. A table for e.g. conditional access with opening hours can be {opening_hours_table(access:conditional, no @ &LPARENS, &RPARENS)}

points_in_time

Creates a visualisation for 'points in time', e.g. collection times of a postbox

name default description
key undefined The key out of which the points_in_time will be parsed

Defined in /src/UI/Popup/DataVisualisations.ts#L294

Example usage of points_in_time

{points_in_time()}

statistics

Show general statistics about all the elements currently in view. Intended to use on the current_view-layer. They will be split per layer

Defined in /src/UI/Popup/DataVisualisations.ts#L209

Example usage of statistics

{statistics()}

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

auto_apply

    A button to run many actions for many features at once.
    To effectively use this button, you'll need some ingredients:

    1. A target layer with features for which an action is defined in a tag rendering. The following special visualisations support an autoAction: tag_apply, import_way_button, conflate_button
    2. A host feature to place the auto-action on. This can be a big outline (such as a city). Another good option for this is the layer [current_view](./BuiltinLayers.md#current_view)
    3. Then, use a calculated tag on the host feature to determine the overlapping object ids
    4. At last, add this component
name default description
target_layer undefined The layer that the target features will reside in
target_feature_ids undefined The key, of which the value contains a list of ids
tag_rendering_id undefined The ID of the tagRendering containing the autoAction. This tagrendering will be calculated. The embedded actions will be executed
text undefined The text to show on the button
icon ./assets/svg/robot.svg The icon to show on the button

Defined in /src/UI/Popup/AutoApplyButtonVis.ts#L68

Example usage of auto_apply

{auto_apply(,,,,./assets/svg/robot.svg)}

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

Defined in /src/UI/SpecialVisualisations/DataImportSpecialVisualisations.ts#L237

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:

  1. The dataset to import has a suitable license
  2. The community has been informed of the import
  3. All other requirements of the import guidelines have been followed

There are also some technicalities in your theme to keep in mind:

  1. 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.
  2. 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)
  3. 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
  4. 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

Defined in /src/UI/Popup/ImportButtons/ConflateImportButtonViz.ts#L25

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:

  1. The dataset to import has a suitable license
  2. The community has been informed of the import
  3. All other requirements of the import guidelines have been followed

There are also some technicalities in your theme to keep in mind:

  1. 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.
  2. 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)
  3. 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
  4. 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

Defined in /src/UI/Popup/ImportButtons/PointImportButtonViz.ts#L17

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:

  1. The dataset to import has a suitable license
  2. The community has been informed of the import
  3. All other requirements of the import guidelines have been followed

There are also some technicalities in your theme to keep in mind:

  1. 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.
  2. 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)
  3. 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
  4. 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

Defined in /src/UI/Popup/ImportButtons/WayImportButtonViz.ts#L21

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; but is disabled if the theme has the 'more privacy' flag set

name default description
key website Attempt to load ld+json from the specified URL. This can be in an embedded