Leaflet SMW queries

From Maps for MediaWiki
Revision as of 01:40, 3 November 2020 by Jeroen De Dauw (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Maps adds a Leaflet result format as part of its integration with Semantic MediaWiki. This result format can be used to visualize queried data onto maps.

Syntax[edit | edit source]

Maps shown with the Leaflet result format can be customized using various parameters. Example demonstrating usage of the Leaflet-only geojson parameter:

{{#ask: [[Coordinates::+]]
 | format=leaflet
 | geojson=Berlin
 | zoom=9
 | center=Berlin
 | ?Coordinates
}}
Result
Loading map...

Parameters[edit | edit source]

Parameter Aliases Type Default Description
width - number and dimensional unit auto Allows setting the width of the map. By default pixels will be assumed as unit, but you can explicitly specify one of these units: px, ex, em, %.
height - number and dimensional unit 350 Allows setting the height of the map. By default pixels will be assumed as unit, but you can explicitly specify one of these units: px, ex, em.
centre center text no The location on which the map should be centered
title - text empty Allows setting text that will be displayed in the pop-ups of all markers that do not have a specific title.

When used together with label, the title will be bold and underlined.

label text text empty Allows setting text that will be displayed in the pop-ups of all markers that do not have a specific label.
icon - text empty Allows setting the icon used for all markers.
lines - List of lines empty Lines to display
polygons - List of geographical polygons empty Polygons to display
circles - List of circles empty Circles to display
rectangles - List of rectangles empty Rectangles to display
maxzoom - whole number no The maximum zoom level
minzoom - whole number no The minimum zoom level
copycoords - yes/no no Show a dialog when clicking on a location from which its coordinates may be copied
static - yes/no no Make the map static
zoom - whole number no The zoom level for the map. For maps with markers this will default to the most zoomed in level that still shows all markers.
defzoom - whole number 14 Allows setting the default zoom level of the map.
layers layer list of texts OpenStreetMap The layers that will be available in the layer selector. The first layer will be shown when the map loads.
image layers image layer, imagelayers, imagelayer list of texts empty Image base layers. The first layer will be shown by default. If any images are specified, they will be used instead of the regular map layers.
overlays overlaylayers list of texts empty The overlay layers that will be shown when the map loads.
resizable - yes/no no Makes the map resizable by dragging at its lower right corner.
fullscreen enablefullscreen yes/no no Enable fullscreen button
scrollwheelzoom scrollzoom yes/no yes Indicates if mouse scrolling should be enabled or not.
cluster markercluster yes/no no Allows merging of multiple nearby markers into one marker
clustermaxzoom - whole number 20 The maximum zoom level where clusters may exist.
clusterzoomonclick - yes/no yes Whether the default behaviour of clicking on a cluster is to zoom into it.
clustermaxradius - whole number 80 The maximum radius that a cluster will cover.
clusterspiderfy - yes/no yes When you click a cluster at the bottom zoom level we spiderfy it so you can see all of its markers.
geojson - text empty URL of a file or name of the page containing GeoJSON data
clicktarget - text empty When clicking on the map you will be send to this URL. %lat% is replaced by the latitude and %long% by the longitude
staticlocations locations, points List of locations empty A list of locations to add to the map together with the queried data. Like with display_points, you can add a title, description and icon per location using the tilde "~" as separator.
showtitle show title yes/no yes Show a title in the marker info window or not. Disabling this is often useful when using a template to format the info window content.
hidenamespace hide namespace yes/no no Show the namespace title in the marker info window
template - text no A template to use to format the info window contents.
userparam - text empty A value passed into each template call, if a template is used
activeicon - text empty Icon to be displayed instead of default marker, when active page is equal to query result
pagelabel - yes/no no When set to "yes", all markers will have an "inlineLabel" with a link to the page containing the coordinates for the marker
ajaxcoordproperty - text empty Name of the coordinate property which is used to build the ajax query.
ajaxquery - text empty A second query that is sent via ajax to fetch additional coordinates.

Parameter examples[edit | edit source]

Dynamic coordinate fetching (ajaxquery)[edit | edit source]

Initially only includes Berlin onto the map. When moving the map around or changing zoom, the map looks for extra pages with the Has Coordinates property within the visible area. This is great for large data sets where loading all data on the map at once is not feasible.

{{#ask: [[Example data:Berlin]]
 | format=leaflet
 | ?Coordinates
 | ajaxquery = [[Category:Cities]]
 | ajaxcoordproperty = Coordinates
 | zoom=8
 | minzoom=5
 | maxzoom=8
 | center=Berlin
}}
Loading map...

Marker clustering[edit | edit source]

{{#ask: [[Category:Cities]]
 | format=leaflet
 | ?Coordinates
 | cluster=on
 | zoom=4
}}
Loading map...

Template (simple)[edit | edit source]

Adding a link to maps.google.com by using a template. See template "Google Maps Link".

{{#ask: [[Category:Cities]]
 | format=leaflet
 | ?Coordinates
 | template=Google Maps Link
}}
Loading map...

Template (advanced)[edit | edit source]

This example shows usage of multiple queried values via the "City Popup" template.

{{#ask:[[Category:Cities]]
 | format=leaflet
 | ?Coordinates
 | ?Located in
 | ?Population
 | ?Surface area
 | template=City Popup
 | showtitle=off
}}
Loading map...