User:Dan Shick (WMDE)/Drafts/Help:Extension:Kartographer

The Kartographer eextension powers custom interactive and static maps on Wikimedia wiki pages. This page is an exhaustive reference to the many options available when using the Kartographer tags, which embeds maps directly in wiki pages, and  , which creates links to full-page interactive maps.



The tag embeds a map in a wiki page. The tag must be either empty or contain valid GeoJSON with styling, as produced by a GeoJSON editor. See below for a list of GeoJSON resources.

Changing to  creates a link to a full screen map. Link text can be set with the attribute (example:   and   === Here's a list of parameters for both   and.

GeoJSON
The and  tags can either be empty or contain valid GeoJSON.

You will find a helpful introduction to GeoJSON [ =https://www.developer.here.com/blog/an-introduction-to-geojson here] and the full specification [ https://datatracker.ietf.org/doc/html/rfc7946 here].

Markers
Maps that use GeoJSON may contain one or more markers to point out special locations. These markers are set using marker-specific keywords under the "properties" level in GeoJSON.

Kartographer supports the [ https://github.com/mapbox/simplestyle-spec/tree/master/1.1.0 simplestyle] specification with Maki icons, which are available under the CC0 license .  See [[Help:Extension:Kartographer/Icons for the full list of supported icons.

Result:

Auto-counters
 { "type": "FeatureCollection", "features": [ {     "type": "Feature", "properties": { "marker-symbol": "-number", "marker-color": "302060" },     "geometry": { "type": "Point", "coordinates": [ -122.41816520690917,         37.79097260220947        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-number", "marker-color": "302060" },     "geometry": { "type": "Point", "coordinates": [ -122.40786552429199,         37.799654055191525        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-number", "marker-color": "302060" },     "geometry": { "type": "Point", "coordinates": [ -122.40185737609865,         37.796262984039544        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-number", "marker-color": "302060" },     "geometry": { "type": "Point", "coordinates": [ -122.38743782043457,         37.80535070427755        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-number", "marker-color": "302060" },     "geometry": { "type": "Point", "coordinates": [ -122.38005638122557,         37.795449103799726        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-letter", "marker-color": "208020" },     "geometry": { "type": "Point", "coordinates": [ -122.40941047668457,         37.81850557172186        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-letter", "marker-color": "208020" },     "geometry": { "type": "Point", "coordinates": [ -122.40357398986815,         37.81280993744834        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-letter", "marker-color": "208020" },     "geometry": { "type": "Point", "coordinates": [ -122.39842414855956,         37.8071138637568        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-number-bar", "marker-color": "f01080" },     "geometry": { "type": "Point", "coordinates": [ -122.41181373596191,         37.78595317184089        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-number-bar", "marker-color": "f01080" },     "geometry": { "type": "Point", "coordinates": [ -122.39542007446289,         37.787674400057654        ]      }    },    {      "type": "Feature", "properties": { "marker-symbol": "-number-bar", "marker-color": "f01080" },     "geometry": { "type": "Point", "coordinates": [ -122.38649368286131,         37.78401144262929        ]      }    }  ] }


 * : determines whether the incremental marker labels proceed by (1, 2, 3...) or  (A, B, C...).
 * You can add a suffix to the value of to create multiple counters on the map.  For example, using both  and  would create separate counters for your lists of museums and of libraries.
 * If more than one counter is specified, the link text will be set to the first counter's value.
 * : sets the hexadecimal color value for each marker.
 * : Markers can be "small", "medium" or "large".
 * : When a marker is clicked, it will display wikitext specified in the "title" value.
 * : When a marker is clicked, it will display an image (specified in wikitext) in the "description" value.

For a rich variety of examples, see the Examples section.

Languages and fallbacks
By default, Kartographer tries to display map labels in the language of the wiki in which the embedded map is displayed. If that language is not available, then the map will use the given wiki's configured fallback language, then any transliterated value available, and finally the local language in the map region specified in the Kartographer map. If none of these are available, Kartographer will display no label.

You can specify the language to use for labels with the  parameter and by setting its value to the desired language code Example:   will display labels in Japanese, if available.

To use the language local to the map area, specify. For more information about using the local language in your labels, and about OpenStreetMap multilingual data in general, read this post. Kartographer maps get their data, including map label data in all available languages, from the open-source mapping project OpenStreetMap. If the map you want to display doesn't offer labels in the desired language, you can always add labels in that language by adding them yourself to OpenStreetMap. To get started, see the OpenStreetMap Beginners’ Guide and these best practices in naming conventions.

External data
 { "type": "ExternalData", "service": "geoshape", "ids": "Q797" }

GeoJSON allows you to obtain outlines of well-known geographical objects from external sources using the "type" parameter with the value "ExternalData".

Maps can draw from well-known geographical objects in the OpenStreetMap database by using their Wikidata ID as well as objects stored in Wikimedia Commons.

GeoShapes via Wikidata Query
To place a geoshape from Wikidata onto your map, use the following GeoJSON parameters and values:


 * "type": "ExternalData"
 * "service": "geoshape"

To that you need to add either the "ids" parameter with a value containing the QID of your desired Wikidata Item, or the "query" parameter with a value containing a valid SPARQL query against Wikidata.


 * "ids": "Q42"
 * "query": valid SPARQL query against Wikidata

For detailed instructions, see.

 { "type": "ExternalData", "service": "geoshape", "query": "SELECT ?id ?head (SAMPLE(?img) as ?img_) (min(?partyId) as ?party) (if(?party = '0', '#800000', if(?party = '1', '#000080', '#008000')) as ?fill) (concat(, ?headLabel, ) as ?title) (concat(?stateLabel, '\\n', '') as ?description) WHERE { ?id wdt:P31 wd:Q35657 . ?id wdt:P6 ?head . ?head wdt:P102 ?party . BIND(if(?party = wd:Q29468, '0', if(?party = wd:Q29552, '1', '2')) as ?partyId) SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . ?head rdfs:label ?headLabel . ?id rdfs:label ?stateLabel . } OPTIONAL { ?head wdt:P18 ?img . } ?link schema:about ?head . ?link schema:isPartOf  .} GROUP BY ?id ?head ?headLabel ?link ?stateLabel" }

Map data from Commons

 *  Further information: 

Map data stored on Commons can be drawn on the map. For example, c:Data:Neighbourhoods/New York City.map:

 { "type": "ExternalData", "service": "page", "title": "Neighbourhoods/New York City.map" }

Combining multiple data types
 [ {    "type": "ExternalData", "service": "geoshape", "ids": "Q13518258", "properties": { "stroke": "#ffb100", "stroke-width": 6, } },  {    "type": "Feature", "geometry": { "type": "Point", "coordinates": [4.75566, 44.104498] }, "properties": { "title": "Porte de Castellan" } },  {    "type": "Feature", "geometry": { "type": "Point", "coordinates": [4.75829, 44.10258] }, "properties": { "title": "Porte Léon Roche" } } ]

You can combine ExternalData, Feature, and FeatureCollection together in the same &lt;mapframe> or &lt;maplink> element:

 [ {    "type": "ExternalData", "service": "page", "title": "Neighbourhoods/New York City.map" }, {    "type": "ExternalData", "service": "geoshape", "ids": "Q160409", "properties": { "fill": "#07c63e", "title": "Central Park" } },  {    "type": "Feature", "properties": {"title": "Roosevelt Island", "marker-color": "f01080"}, "geometry": { "type": "Point", "coordinates": [ -73.94511222839355,       40.76734665426719      ]    }  } ]

Map data from Commons can be combined with other types of data:

Styling Wikidata ID elements
 { "type": "ExternalData", "service": "geoline", "ids": "Q2108", "properties": { "title": "Highway I-696", "description": "", "stroke": "#ffb100", "stroke-width": 8 } }

For external data, you can also add styles and titles, using the properties keyword:

The main style keys are: "stroke" (color), "stroke-width", "stroke-opacity", "fill" (color), "fill-opacity".

Overlapping elements
Map elements that overlap are drawn in the order in which they are written in the code. For instance, if a map includes two lines that overlap, the line that is defined first will appear beneath the line that is defined second. The following examples show how this can affect the appearance of the map:

 { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {"fill": "#ff0000","fill-opacity": 0.7,"stroke-width": 0}, "geometry": { "type": "Polygon", "coordinates": [ [ [ 77.926025390625, -25.150257104114733 ], [ 80.14251708984374, -25.150257104114733 ], [ 80.14251708984374, -24.43714786161562 ], [ 77.926025390625, -24.43714786161562 ], [ 77.926025390625, -25.150257104114733 ] ] ] } }, { "type": "Feature", "properties": {"stroke": "#fffa00","stroke-width": 5}, "geometry": { "type": "LineString", "coordinates": [ [ 77.926025390625, -25.150257104114733 ], [ 80.14251708984374, -24.43714786161562 ] ] } }, { "type": "Feature", "properties": {"stroke": "#000000","stroke-width": 5}, "geometry": { "type": "LineString", "coordinates": [ [ 77.926025390625, -24.43714786161562 ], [ 80.14251708984374, -25.150257104114733 ] ] } } ] }

The code for the map above includes three elements, all of which use GeoJSON's "feature" functionality. The first feature is a "Polygon" - the red rectangle. This is followed by two "LineString" features. The yellow line is defined first, so it appears beneath the black line. Note that the hierarchy used to draw elements applies regardless of whether the data is raw GeoJSON or comes from a Wikidata ID or Commons data page.

The map below changes the order from that of the first example: the black line is defined first and is thus moved to the bottom of the stack:

 { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {"stroke": "#000000","stroke-width": 5}, "geometry": { "type": "LineString", "coordinates": [ [ 77.926025390625, -24.43714786161562 ], [ 80.14251708984374, -25.150257104114733 ] ] } }, { "type": "Feature", "properties": {"fill": "#ff0000","fill-opacity": 0.7,"stroke-width": 0}, "geometry": { "type": "Polygon", "coordinates": [ [ [  77.926025390625,  -25.150257104114733  ],  [  80.14251708984374,  -25.150257104114733  ],  [  80.14251708984374,  -24.43714786161562  ],  [  77.926025390625,  -24.43714786161562  ],  [  77.926025390625,  -25.150257104114733  ]  ]  ]  } }, { "type": "Feature", "properties": {"stroke": "#fffa00","stroke-width": 5}, "geometry": { "type": "LineString", "coordinates": [ [ 77.926025390625, -25.150257104114733 ], [ 80.14251708984374, -24.43714786161562 ] ] } } ] }

Groups
For use on the Wikivoyage project, there is a need to show a map whose data is defined somewhere else on the page. For example, there may be multiple points of interest (POI) defined with tags, and one common map on the side of the page that shows them all.

The grouping concept allows editors to share data between multiple and  tags.

By default, the data inside the or  tag is shown only for that one tag, and will not be shown anywhere else.

If or  specify the  attribute, the data inside those tags will be placed into a named group, together with all the other data by the same group name. As a result, any tags with the same group name will show the same map data, and each tag may incrementally add data to the group.

A tag may also show other groups, regardless if it belongs to a group or not, by specifying the attribute. Comma-separated multiple group names may be specified. The group name may only contain lower case English letters. This matrix shows what data will be shown for each tag.

Rendering options
The following table shows how a map can be formatted for display on a wiki page. The table contains two columns: the first shows an interactive map via the tag, and the second showing the rendering of an example image with the same options.

Use the width value  in order to make the map take up the full width of the page.  