Leaflet desaturation example
by Mapycz
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Simple map in OpenLayers</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-sA+zWATbFveLLNqWO2gtiw3HL/lh1giY/Inf1BJ0z14=" crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-o9N1jGDZrf5tS+Ft4gbIK7mYMipq9lqpVJ91xHSyKhg=" crossorigin=""></script>
</head>
<body>
<div id="map"></div>
</body>
</html>
CSS
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
JavaScript
// replace with your own API key
const API_KEY = 'eyJpIjoyNTcsImMiOjE2Njc0ODU2MjN9.c_UlvdpHGTI_Jb-TNMYlDYuIkCLJaUpi911RdlwPsAY';
/*
We create the map and set its initial coordinates and zoom.
See https://leafletjs.com/reference.html#map
*/
const map = L.map('map').setView([49.8729, 14.8981], 16);
/*
Then we add a raster tile layer with Mapy NG tiles
See https://leafletjs.com/reference.html#tilelayer
*/
layer=L.tileLayer(`https://api.mapy.cz/v1/maptiles/basic/256/{z}/{x}/{y}?apikey=${API_KEY}`, {
minZoom: 0,
maxZoom: 19,
attribution: '<a href="https://api.mapy.cz/copyright" target="_blank">© Seznam.cz a.s. a další</a>',
});
layer.addTo(map);
//Apply a color filter to map layer
layer.getContainer().style.filter = 'grayscale(90%) opacity(60%)';
//Adding a marker - color filters are not applied to it
var shopIcon = L.icon({
iconUrl: 'https://developer.mapy.cz/wp-content/uploads/2023/08/shop-red.png',
iconSize: [55, 61], // size of the icon
iconAnchor: [20, 60], // point of the icon which will correspond to marker's location
popupAnchor: [-0, -50] // point from which the popup should open relative to the iconAnchor
});
var marker = L.marker([49.8729, 14.8981], { icon: shopIcon }).addTo(map);
marker.bindPopup("Click");
//We will add a logo - it must be in original colors
const LogoControl = L.Control.extend({
options: {
position: 'bottomleft',
},
onAdd: function (map) {
const container = L.DomUtil.create('div');
const link = L.DomUtil.create('a', '', container);
link.setAttribute('href', 'http://mapy.cz/');
link.setAttribute('target', '_blank');
link.innerHTML = '<img src="https://api.mapy.cz/img/api/logo.svg" />';
L.DomEvent.disableClickPropagation(link);
return container;
},
});
// finally we add our LogoControl to the map
new LogoControl().addTo(map);