Quick start
The example below, running in the Mappia calculator - click it to run it live. Full-size picture
- Run it
Click the picture: the map opens right here and runs the example. Nothing is saved, and nothing to install.
- Try it
- Click the Topographic thumbnail at the top right: the basemap under the States layer changes.
- Click OpenStreetMap to switch back: only one basemap is visible at a time.
- Move
visibility: truefrom OpenStreetMap to Topographic and run it again: the map starts topographic.
- Make it yours
Copy the query, change it - the key parameters are below - and run it again in the playground, or paste it into the Mappia editor to save it as your map.
Key parameters
| Parameter | Example | What it does |
|---|---|---|
group | background | Makes the layer a basemap: it sits under every other layer, leaves the layer list and joins the picker. |
setOptions | ExtjsUtils.CONFIGURATION.setOptions({ backgroundSelector: true }) | Shows the floating picker, one thumbnail per basemap, when the query loads. |
source | osm | Where the basemap comes from: osm for OpenStreetMap, arcgisrest for ArcGIS basemaps. |
name | mapnik | Which map of that source: mapnik for OpenStreetMap; Topographic in the ArcGIS example. |
title | Topographic | The label under the basemap’s thumbnail. |
visibility | true | The basemap the map starts with. Set it on one basemap only. |
Every parameter, with its type and default, is in the reference at the end of this page.
Complete example
The query 7 lines · runs as is
// Background map picker: layers with group "background" are basemaps; backgroundSelector
// shows them as thumbnails the user switches between. One basemap is visible at a time.
ExtjsUtils.CONFIGURATION.setOptions({ backgroundSelector: true }) && [
{ name: "CSR:estados", title: "States", visibility: true, opacity: 0.4 },
{ name: "mapnik", source: "osm", title: "OpenStreetMap", group: "background", visibility: true },
{ name: "Topographic", source: "arcgisrest", title: "Topographic", group: "background", visibility: false },
];Customize it
How a basemap behaves
A layer with group: "background" is drawn under everything else and is not listed in the layer panel. Only one basemap is visible at a time: choosing a thumbnail hides the others. Your data layers stay on top and keep their own visibility.
The default basemap
When no layer of the query declares group: "background", the platform adds OpenStreetMap by itself. As soon as you declare a basemap of your own, that default is left out - so list OpenStreetMap among yours if you still want it, as the example does.
Turning the picker on
setOptions goes before the layer list, joined with &&, because a query is a single expression (how a query is evaluated). The setting belongs to the query: it is cleared when another query loads.
To show the picker only when there really is a choice, pass an object instead of true:
ExtjsUtils.CONFIGURATION.setOptions({ backgroundSelector: { minCount: 2 } }) && [
{ name: "CSR:estados", title: "States", visibility: true },
{ name: "mapnik", source: "osm", title: "OpenStreetMap", group: "background", visibility: true },
{ name: "Topographic", source: "arcgisrest", title: "Topographic", group: "background" },
];
Labels
Each thumbnail is labelled with the layer’s title, or its name when there is no title. Keep titles short: long ones are cut off under the thumbnail.
Related
For tiles from any z/x/y tile service, see the XYZ layer. OpenStreetMap tiles can also be saved for use without a connection - see offline areas.