Jump to content

Maps in Mediawiki: Difference between revisions

From Squirrel's Lair
Ttenbergen (talk | contribs)
Ttenbergen (talk | contribs)
m Ttenbergen moved page Maps to Maps in Mediawiki without leaving a redirect
(No difference)

Revision as of 21:31, 2022 November 11

Mediawiki can be used with the Mediawiki Extension Maps to display maps with markers based on coordinates. These coordinates can be provided explicitly or through data, such as through Mediawiki Extension Cargo.

Maps via Cargo Displayformat

Cargo can format its query results in some unexpected ways, and one of them is as a map. If the data is already in Cargo then this method draws a map with just one line of code, e.g.

{{#cargo_query: table=Place | fields = Name, Description, Coordinates | format = leaflet| width = 400| height = 200}}

A disadvantage is that it won't display in preview mode, only once you save, which can slow troubleshooting. This method is also limited in how much it can annotate the maps.

Maps via the Maps extension

Mediawiki Extension Maps is a more flexible way to display maps. It allows adding shapes like lines, rectangles and circles and can use different layers such as satellite photography and openstreetmaps. It can still be used with Cargo data by writing an inline Cargo query to provide coordinates for targets or shapes. It can also take names of locations and addresses as input instead of coordinates, which makes it more flexible in what data can drive it. For example, the following code will list all locations in table place and then draw a line between two of them; the layers button in the top right corner will switch between map view and satellite image view.

{{#display_map:
 {{#cargo_query: table=Place |fields   = CONCAT(Coordinates__full, '~', Name ) |format=list |delimiter=; |no html }} 
 |lines= {{#cargo_query: table=Place |fields   = Coordinates__full |where=Name="North Forge" |format=list |delimiter=; |no html
}}:{{#cargo_query: table=Place |fields   = Coordinates__full |where=Name="WRC" |format=list |delimiter=; |no html  }}
 |copycoords=yes
 |resizable=on
 |layers=OpenStreetMap,Esri.WorldImagery 
 |height=200
}}
Loading map...

Encoding locations in a cargo table to use them in queries

Storing locations in a Cargo table allows data driven maps. This wiki contains Template:Place which defines Cargo Table Place. This table has a field "Coordinates" in a data type meant for map coordinates. Coordinates for locations can be obtained from Google Maps by right-clicking on an area and then clicking on the coordinates.

Here are some template calls to store test data used above:

{{Place| Name=North Forge | Description=A makerspace | Coordinates = 49.89959808249238, -97.14224677575343 }} 
  • Cargo


{{Place| Name=WRC | Description=A rowing club | Coordinates = 49.88086121609553, -97.13063599481808 }} 
  • Cargo