Skip to content

mvt-proj/maplibre-gl-layers-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LayersControl

LayersControl is a control inspired by maplibre-gl-opacity. It integrates support for legends and several improvements in layer and transparency management.

Features

  • 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.

Examples:

Simple

<!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>
imagen

With Opacity Control

      let layersControl = new LayersControl({
        title: 'Layers',
        opacityControl: true,
      });
      map.addControl(layersControl, "bottom-left");
imagen

With Custom Labels

      const labels = {
        "countries-fill": "Countries",
      }

      let layersControl = new LayersControl({
        title: 'Layers',
        customLabels: labels,
      });
      map.addControl(layersControl, "bottom-left");
imagen

With Legends Information

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");
imagen

Ecosystem

LayersControl is part of the mvt-proj ecosystem, along with MVT Server and MapLibre Legend.

About

Control to show or hide layers and handle transparencies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors