Maps in Mediawiki: Difference between revisions

From Squirrel's Lair
mNo edit summary
mNo edit summary
Line 2: Line 2:


== Maps via Cargo Displayformat ==
== Maps via Cargo Displayformat ==
Cargo can format its query results in some unexpected ways, and one of them is [https://www.mediawiki.org/wiki/Extension:Cargo/Display_formats#Maps as a map].  
Cargo can format its query results in some unexpected ways, and one of them is [https://www.mediawiki.org/wiki/Extension:Cargo/Display_formats#Maps as a map]. If the data is already in Cargo then this method draws a map with just one line of code, e.g.
<nowiki>{</nowiki>{#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.


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


== Maps extension ==
== Maps via the Maps extension ==
[https://maps.extension.wiki Maps extension] with an inline Cargo query to set targets and a line
[[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:
 
<nowiki>{</nowiki>{#display_map:
  <nowiki>{</nowiki>{#cargo_query: table=Place |fields  = CONCAT(Coordinates__full, '~', Name ) |format=list |delimiter=; |no html }}
  |lines= <nowiki>{</nowiki>{#cargo_query: table=Place |fields  = Coordinates__full |where=Name="North Forge" |format=list |delimiter=; |no html
}}:<nowiki>{</nowiki>{#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
}}


{{#display_map:
{{#display_map:
  {{#cargo_query: table=Place
  {{#cargo_query: table=Place |fields  = CONCAT(Coordinates__full, '~', Name ) |format=list |delimiter=; |no html }}
|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
  |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  }}
  }}:{{#cargo_query: table=Place |fields  = Coordinates__full |where=Name="WRC" |format=list |delimiter=; |no html  }}

Revision as of 22:20, 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:

{{#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
}}

{{#display_map:

49.88086121609553, -97.13063599481808~WRC; 49.89959808249238, -97.14224677575343~North Forge
|lines= 49.89959808249238, -97.14224677575343:49.88086121609553, -97.13063599481808
 |copycoords=yes
 |resizable=on
 |layers=OpenStreetMap,Esri.WorldImagery 
 |height=200

}}


Encode locations in a cargo table to use them in queries

Template:Place defines Cargo Table Place.

Locations can be grabbed from Google Maps by right-clicking on an area and then clicking on the coordinates. They can be pasted into the Coordinates template paramater.

Here are the template calls (see edit view).


  • Cargo



  • Cargo