Leaflet layers

From Maps for MediaWiki

Maps ships a set of built-in Leaflet base layers and overlays from the Leaflet-providers library. Any name below can be used as a value of the layers or overlaylayers parameters (see the Layers examples). To add your own, use the custom layers setting.

Base layers

These work without any configuration:

  • OpenStreetMap, OpenStreetMap.DE, OpenStreetMap.HOT
  • OpenTopoMap
  • Esri.WorldStreetMap, Esri.WorldTopoMap, Esri.WorldImagery, Esri.WorldTerrain, Esri.WorldShadedRelief, Esri.WorldPhysical, Esri.OceanBasemap, Esri.NatGeoWorldMap, Esri.WorldGrayCanvas
  • CartoDB.Positron, CartoDB.PositronNoLabels, CartoDB.PositronOnlyLabels, CartoDB.DarkMatter, CartoDB.DarkMatterNoLabels, CartoDB.DarkMatterOnlyLabels
  • BasemapAT.basemap, BasemapAT.grau, BasemapAT.overlay, BasemapAT.highdpi, BasemapAT.orthofoto (Austria)
  • NASAGIBS.ModisTerraTrueColorCR, NASAGIBS.ModisTerraBands367CR, NASAGIBS.ViirsEarthAtNight2012
  • FreeMapSK (Slovakia), MtbMap

Layers that need an API key

These load only once a key is supplied. Set the Thunderforest key in $egMapsLeafletLayersApiKeys:

  • Thunderforest.OpenCycleMap, Thunderforest.Transport, Thunderforest.TransportDark, Thunderforest.SpinalMap, Thunderforest.Landscape, Thunderforest.Outdoors, Thunderforest.Pioneer
  • NLS (historical maps; needs a MapTiler key)

Overlay layers

Use these with the overlaylayers parameter:

  • OpenSeaMap
  • NASAGIBS.ModisTerraLSTDay, NASAGIBS.ModisTerraSnowCover, NASAGIBS.ModisTerraAOD, NASAGIBS.ModisTerraChlorophyll
  • OpenWeatherMap.Clouds, OpenWeatherMap.Precipitation, OpenWeatherMap.Rain, OpenWeatherMap.Pressure, OpenWeatherMap.Wind, OpenWeatherMap.Temperature, OpenWeatherMap.Snow (with Classic and Contour variants) — need an OpenWeatherMap API key

Custom layers

Since Maps 13.1.0.

To add your own tile or WMS layers, define them with $egMapsLeafletLayerDefinitions in LocalSettings.php. The name of each definition becomes a valid value for the layers and overlaylayers parameters, in both #display_map maps and query result formats.

Each definition supports:

  • url (required): an XYZ tile template such as https://tiles.example.org/{z}/{x}/{y}.png, or the service endpoint for a WMS layer.
  • options (optional): an array passed directly to Leaflet. Common keys are attribution, minZoom, maxZoom, subdomains and bounds. For a WMS layer, put layers, format and transparent here.
  • wms (optional): set to true to load the layer through the WMS protocol.

Definitions without a non-empty url are ignored. A definition whose name matches a built-in layer, such as OpenStreetMap, overrides that built-in layer. Only the definitions a map actually uses are sent to the browser.

$egMapsLeafletLayerDefinitions = [
	'Historic 1904' => [
		'url' => 'https://tiles.example.org/historic1904/{z}/{x}/{y}.png',
		'options' => [
			'attribution' => 'Historic map tiles',
			'minZoom' => 1,
			'maxZoom' => 18,
			'subdomains' => 'abc',
			'bounds' => [ [ 49.5, 5.8 ], [ 53.6, 15.2 ] ],
		],
	],
	'Weather' => [
		'wms' => true,
		'url' => 'https://example.org/geoserver/wms',
		'options' => [
			'layers' => 'weather:precipitation',
			'format' => 'image/png',
			'transparent' => true,
			'attribution' => 'Weather service',
		],
	],
];

With those definitions in place, use the layers like any built-in one. "Historic 1904" becomes a base layer and "Weather" a toggleable overlay:

{{#display_map:Berlin |layers=Historic 1904 |zoom=12 }}

{{#display_map:Hamburg |overlaylayers=Weather |zoom=8 }}

Because attribution is rendered as HTML, only set it to content you trust.