Maps in Mediawiki: Difference between revisions

From Squirrel's Lair
mNo edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
This page is a test ground and demo for using maps in mediawiki.
{{TidBit
|shortDescription=Displaying Maps in Mediawiki
|skillSet=Mediawiki
|featured=Yes
}}


== Maps extension ==
[[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]].
[https://maps.extension.wiki Maps extension] - installed 2022-11 to test this.


{{#cargo_query: table=Place
== Maps via Cargo Displayformat ==
|fields  = CONCAT(Coordinates__full, '~', Name , '~',Description )
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.
|format=list
<nowiki>{</nowiki>{#cargo_query: table=Place | fields = Name, Description, Coordinates | format = leaflet| width = 400| height = 200}}
|delimiter=;
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 | fields = Name, Description, Coordinates | format = leaflet| width = 400| height = 200}}
 
== 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.
 
<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 , '~',Description )
|lines= {{#cargo_query: table=Place |fields  = Coordinates__full |where=Name="North Forge" |format=list |delimiter=; |no html
|format=list
}}:{{#cargo_query: table=Place |fields  = Coordinates__full |where=Name="WRC" |format=list |delimiter=; |no html  }}
|delimiter=;
}}
   |copycoords=yes
   |copycoords=yes
   |resizable=on
   |resizable=on
   |layers=OpenStreetMap,Esri.WorldImagery  
   |layers=OpenStreetMap,Esri.WorldImagery  
  |height=200
}}
}}


== Cargo Displayformat Maps ==
== Encoding locations in a cargo table to use them in queries==
[https://www.mediawiki.org/wiki/Extension:Cargo/Display_formats#Maps Cargo Displayformat Maps]
Storing locations in a Cargo table allows data driven maps. This wiki contains [[Template:Place]] which defines [https://wiki.squirrelslair.ca/index.php?title=Special:CargoTables/Place Cargo Table Place]. This table has a field "Coordinates" in a [https://www.mediawiki.org/wiki/Extension:Cargo/Storing_data#Storing_data_in_a_table data type meant for map coordinates]. Coordinates for locations can be obtained from [https://www.google.com/maps Google Maps] by right-clicking on an area and then clicking on the coordinates.
* [https://openlayers.org/ Openlayers]
{{#cargo_query: table=Place
|format  = openlayers
|fields  = Name, Description, Coordinates
|width    = 400
|height  = 300
}}
 
* [https://leafletjs.com/ Leaflet]
{{#cargo_query: table=Place
|format  = leaflet
|fields  = Name, Description, Coordinates
|width    = 400
|height  = 300
}}
 
=== Notes ===
* parameters:
** |icon = Squirrelslair 200.png - works, but poor visibility
 
* googlemaps would require billing <!--
{{#cargo_query: table=Place
|format  = googlemaps
|fields  = Name, Description, Coordinates
|width    = 400
|height  = 300
}} -->
 
== Encode locations ==
[[Template:Place]] defines [https://wiki.squirrelslair.ca/index.php?title=Special:CargoTables/Place Cargo Table Place].  


Locations can be grabbed from [https://www.google.com/maps 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 some template calls to store test data used above:
<nowiki>{</nowiki>{Place| Name=North Forge | Description=[https://northforge.ca/ A makerspace] | Coordinates = 49.89959808249238, -97.14224677575343 }} {{Place| Name=North Forge | Description=[https://northforge.ca/ A makerspace] | Coordinates = 49.89959808249238, -97.14224677575343 }}
<nowiki>{</nowiki>{Place| Name=WRC | Description=[https://winnipegrowingclub.ca/ A rowing club] | Coordinates = 49.88086121609553, -97.13063599481808 }} {{Place| Name=WRC | Description=[https://winnipegrowingclub.ca/ A rowing club] | Coordinates = 49.88086121609553, -97.13063599481808 }}


Here are the template calls (see edit view).
{{WhatLinksHere|}}
{{Place|
| Name=North Forge
| Description=A place entry for testing
| Coordinates = 49.89959808249238, -97.14224677575343
}}
{{Place|
| Name=WRC
| Description=A place entry for testing
| Coordinates = 49.88086121609553, -97.13063599481808
}}

Latest revision as of 22:32, 2022 November 11


  • Cargo:


  • Categories:
  • Default form


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

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

}}

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


Related articles

Related articles: