Salta el contingut

2.4 Afegir control d'estil

Exemple

.addBasemapsICGC(baseLayers)

See the Pen addBasemapsICGC by unitatgeostart (@unitatgeostart) on CodePen.

CodePen

Codi

<html>
  <head>
    <meta charset="utf-8" />
    <title>Exemple mapicgc-gl-js: Afegir mapa base ICGC</title>
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <script src="https://eines.icgc.cat/recursos/mapicgc-gl-js/mapicgc-gl.js"></script>
    <link
      href="https://eines.icgc.cat/recursos/mapicgc-gl-js/mapicgc-gl.css"
      rel="stylesheet"
    />

    <style>
      body {
        margin: 0;
        padding: 0;
      }
      #map {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
      }

      #basemap-group {
        position: absolute;
        bottom: 40px;
        right: 10px;
        color: #000000;
        display: flex;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>

    <script>
      async function initMap() {
        const data = await mapicgcgl.Config.getConfigICGC();
        const map = new mapicgcgl.Map({
          container: "map",
          style: data.Styles.TOPO, // <-- add style basemap here
          center: [2.1464, 41.306],
          zoom: 7.4,
          maxZoom: 14,
          hash: true,
          pitch: 0,
        });
        map.on("load", () => {
          //add multiple ICGC basemaps and get a style menu component
          map.addFullscreenControl();
          let basemapsicgc = [data.Styles.ORTO, data.Styles.TOPO];
          map.addBasemapsICGC(basemapsicgc);
        });
      }
      initMap();
    </script>
  </body>
</html>