Leaflet
Basic Map
This example adds Maptoolkit raster tiles as a tile layer to a Leaflet map:
let map = L.map("map").setView([47.310897, 12.805988], 12);
L.tileLayer("https://rtc-cdn.maptoolkit.net/rtc/maptoolkit-maptoolkit.summer/{z}/{x}/{y}{ratio}.png?api_key=YOUR_API_KEY", {
ratio: L.Browser.retina ? "@2x" : "",
maxZoom: 18,
attribution:
"© <a href='https://www.maptoolkit.com' target='_blank'>Maptoolkit</a> \
© <a href='https://www.openstreetmap.org/copyright' target='_blank'>OSM</a>",
}).addTo(map);<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css" />
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
#map { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
let map = L.map("map").setView([47.310897, 12.805988], 12);
L.tileLayer("https://rtc-cdn.maptoolkit.net/rtc/maptoolkit-maptoolkit.summer/{z}/{x}/{y}{ratio}.png?api_key=YOUR_API_KEY", {
ratio: L.Browser.retina ? "@2x" : "",
maxZoom: 18,
attribution:
"© <a href='https://www.maptoolkit.com' target='_blank'>Maptoolkit</a> \
© <a href='https://www.openstreetmap.org/copyright' target='_blank'>OSM</a>",
}).addTo(map);
</script>
</body>
</html>Switching Styles
Each Standard Map Style is its own raster endpoint, so you can offer several
styles through a Leaflet layer control. Add one L.tileLayer per style and pass
them to L.control.layers as base layers:
const attribution =
"© <a href='https://www.maptoolkit.com' target='_blank'>Maptoolkit</a> \
© <a href='https://www.openstreetmap.org/copyright' target='_blank'>OSM</a>";
// Build a raster tile layer for one of the Standard Map Styles.
// `name` is the maptoolkit-maptoolkit.<variant> id.
function style(name) {
return L.tileLayer(
"https://rtc-cdn.maptoolkit.net/rtc/" + name + "/{z}/{x}/{y}{ratio}.png?api_key=YOUR_API_KEY",
{ ratio: L.Browser.retina ? "@2x" : "", maxZoom: 18, attribution: attribution }
);
}
const baseLayers = {
"Summer": style("maptoolkit-maptoolkit.summer"),
"Winter": style("maptoolkit-maptoolkit.winter"),
"Hiking": style("maptoolkit-maptoolkit.hiking"),
"Cycling": style("maptoolkit-maptoolkit.cycling"),
"Street": style("maptoolkit-maptoolkit.street"),
"Light": style("maptoolkit-maptoolkit.light"),
"Dark": style("maptoolkit-maptoolkit.dark"),
};
const map = L.map("map", {
center: [47.310897, 12.805988],
zoom: 12,
layers: [baseLayers["Summer"]],
});
L.control.layers(baseLayers, null, { collapsed: false }).addTo(map);<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css" />
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
#map { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
const attribution =
"© <a href='https://www.maptoolkit.com' target='_blank'>Maptoolkit</a> \
© <a href='https://www.openstreetmap.org/copyright' target='_blank'>OSM</a>";
// Build a raster tile layer for one of the Standard Map Styles.
// `name` is the maptoolkit-maptoolkit.<variant> id.
function style(name) {
return L.tileLayer(
"https://rtc-cdn.maptoolkit.net/rtc/" + name + "/{z}/{x}/{y}{ratio}.png?api_key=YOUR_API_KEY",
{ ratio: L.Browser.retina ? "@2x" : "", maxZoom: 18, attribution: attribution }
);
}
const baseLayers = {
"Summer": style("maptoolkit-maptoolkit.summer"),
"Winter": style("maptoolkit-maptoolkit.winter"),
"Hiking": style("maptoolkit-maptoolkit.hiking"),
"Cycling": style("maptoolkit-maptoolkit.cycling"),
"Street": style("maptoolkit-maptoolkit.street"),
"Light": style("maptoolkit-maptoolkit.light"),
"Dark": style("maptoolkit-maptoolkit.dark"),
};
const map = L.map("map", {
center: [47.310897, 12.805988],
zoom: 12,
layers: [baseLayers["Summer"]],
});
L.control.layers(baseLayers, null, { collapsed: false }).addTo(map);
</script>
</body>
</html>