LayersControl is a control inspired by maplibre-gl-opacity. It integrates support for legends and several improvements in layer and transparency management.
- Layer Visibility: Easily show or hide individual layers.
- Transparency Management: Control the opacity of each layer to create custom visualizations.
- Legend Support: Integrates legends directly into the control for better context.
- Enhanced Management: Offers an improved user experience for managing map layers compared to the original plugin.
<!doctype html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LayersControl Example</title>
<link href="https://unpkg.com/maplibre-gl@latest/dist/maplibre-gl.css" rel="stylesheet"/>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/maplibre-gl@latest/dist/maplibre-gl.js"></script>
<script src="../dist/maplibre-gl-layers-control.min.js"></script>
<link href="style.css" rel="stylesheet"/>
<script>
const map = new maplibregl.Map({
container: "map",
style: "https://demotiles.maplibre.org/style.json",
center: [0, 0],
zoom: 1,
});
let layersControl = new LayersControl({
title: 'Layers',
});
map.addControl(layersControl, "bottom-left");
</script>
</body>
</html>
let layersControl = new LayersControl({
title: 'Layers',
opacityControl: true,
});
map.addControl(layersControl, "bottom-left");
const labels = {
"countries-fill": "Countries",
}
let layersControl = new LayersControl({
title: 'Layers',
customLabels: labels,
});
map.addControl(layersControl, "bottom-left");
Using a legends service such as the one provided by MVT Server.
let layersControl = new LayersControl({
title: 'Layers',
style: "https://example.com/services/legends/public:latam"
opacityControl: true,
});
map.addControl(layersControl, "bottom-left");
LayersControl is part of the mvt-proj ecosystem, along with MVT Server and MapLibre Legend.