Salta el contingut

2.10 Afegir control

Exemple

.addControl(control,position)

See the Pen Exemple AddMarker by unitatgeostart (@unitatgeostart) on CodePen.

CodePen

Codi

<html>
  <head>
    <meta charset="utf-8" />
    <title>Exemple mapicgc-gl-js: Afegir control</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"
    />

    <link
      rel="stylesheet"
      href="https://unpkg.com/maplibre-gl@4.0.0/dist/maplibre-gl.css"
    />
    <script src="https://unpkg.com/maplibre-gl@4.0.0/dist/maplibre-gl.js"></script>

    <style>
      body {
        margin: 0;
        padding: 0;
      }
      #map {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
      }
    </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,
          center: [2.1464, 41.306],
          zoom: 7.4,
          maxZoom: 19,
          hash: true,
          pitch: 0,
        });
        map.on("load", () => {

          map.addFullscreenControl({}, "top-right");
          map.addGeolocateControl(
            {
              positionOptions: {
                enableHighAccuracy: true,
              },
              trackUserLocation: true,
            },
            "bottom-right"
          );

          //control export amb opcions
          // map.addExportControl(
          //   {
          //     PageSize: Size.A4,
          //     PageOrientation: PageOrientation.Landscape,
          //     Format: Format.PNG,
          //     DPI: DPI[300],
          //     Crosshair: true,
          //     PrintableArea: true,
          //   },
          //   "bottom-right"
          // );
          //control export per defecte
          map.addExportControl();

          // control d'una biblioteca externa
          map.addControl(new maplibregl.NavigationControl(), "bottom-right");
        });
      }
      initMap();
    </script>
  </body>
</html>

addGeolocateControl(options, position)

map.addGeolocateControl(); ; //default version 
map.addGeolocateControl({
positionOptions: { enableHighAccuracy: true }, trackUserLocation: true
},"bottom-right")

addExportControl(options, position)

map.addExportControl() ; //default version 
map.addExportControl({ PageSize:
Size.A4, PageOrientation:PageOrientation.Landscape, Format: Format.PNG, DPI:
DPI[300], Crosshair: true, PrintableArea: true, }, "bottom-right")

addMouseCoordControl(options, position)

map.addMouseCoordControl(); //default version
map.addMouseCoordControl({width:'225px',utm:true,lonlat:true},"bottom-left");

addFullscreenControl(options, position)

map.addFullscreenControl(); //default version
map.addFullscreenControl({container: HTMLElement}, 'top-right');

addScaleControl(options, position)

map.addScaleControl(); //default version 
map.addScaleControl({maxWidth: 100,
unit: 'metric' ('imperial', 'metric' or 'nautical')}, "top-right");

addNavigationControl(options, position)

map.addNavigationControl(); //default version
map.addMouseCoordControl({showCompass: true, showZoom: true, visualizePitch:
true}, "top-right");

addAttributionControl(options, position)

map.addAttributionControl(); //default version
map.addAttributionControl({compact: true, customAttribution: "your custom
attribution" }, "bottom-right");