Zum Inhalt springen
Astrid

Maplibre GL - Maßstab

Kennt man sich in einer Gegend nicht aus, ist ein Maßstab hilfreich.

Full Screen Map with Scale Control Gatsby Mapbox GL Starter

<!-- https://raw.githubusercontent.com/astridx/maplibreexamples/main/examples/scale_control.html -->

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Scale Control Maplibre GL Beispiel</title>
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <script src="../.env"></script>
    <script src="https://unpkg.com/maplibre-gl@1.14.0-rc.1/dist/maplibre-gl.js"></script>
    <link
      href="https://unpkg.com/maplibre-gl@1.14.0-rc.1/dist/maplibre-gl.css"
      rel="stylesheet"
    />
  </head>

  <body>
    <div id="map" style="width: 100vw; height: 100vh"></div>
    <script>
      var map = new maplibregl.Map({
        container: 'map',
        style:
          'https://api.maptiler.com/maps/streets/style.json?key=' +
          config.MAPTILER_TOKEN,
        center: [7.2, 50.3],
        zoom: 12,
      })
      var scale = new maplibregl.ScaleControl({
        maxWidth: 80,
        unit: 'metric',
      })
      map.addControl(scale)
    </script>
  </body>
</html>

Alle Optionen sind in der MapBox GL Dokumentation beschrieben.

Demo
Quellcode
Gatsby Starter mit dieser Funktion - Gatsby Starter Demo