Single-file no-build-step example

Aperta Adatta ai principianti
#589 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
65/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript
Ambito
documentation

Direzione di ricerca

Inizia con l’esempio HTML fornito e ispeziona la struttura esistente degli esempi o della documentazione del repository per trovare la posizione appropriata. Aggiungi un esempio eseguibile per browser in un singolo file, usando gli import delle dipendenze mostrati nell’issue, senza un passaggio di build, e verifica che carichi la mappa e la scena raster come descritto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

See https://github.com/microsoft/PlanetaryComputerDataCatalog/pull/530/changes#diff-75f8c328e1b62b6317e072b79dea671d5638af89f2c75bbe1b7f29491bf559f7

<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <title>Planetary Computer · deck.gl-raster (no build)</title>
  <link href="https://esm.sh/[email protected]/dist/maplibre-gl.css" rel="stylesheet" />
  <style>
    html, body { margin: 0; height: 100%; font-family: system-ui, sans-serif; }
    #map { position: absolute; inset: 0; }
    #panel {
      position: absolute; top: 16px; left: 16px; z-index: 2; width: 240px;
      background: #ffffff; border-radius: 10px; padding: 16px 18px;
      box-shadow: 0 2px 14px #0003; font-size: 13px; color: #1a1a1a;
    }
    #panel h1 { font-size: 15px; margin: 0 0 6px; }
    #panel .muted { color: #666; line-height: 1.4; }
    #panel label { display: block; margin-top: 14px; font-weight: 600; }
    #panel input[type=range] { width: 100%; }
    #scene { font-family: ui-monospace, monospace; font-size: 11px; word-break: break-all; }
  </style>

  <!-- No build step: an import map resolves every dependency from a CDN.
       All @deck.gl/* and @luma.gl/core MUST share one version (mismatched
       patch versions throw "deck.gl - multiple versions detected"). The
       deck.gl-geotiff entry marks deck/luma/geotiff as `external` so they
       resolve to the singletons above instead of being bundled again. -->
  <script type="importmap">
  {
    "imports": {
      "maplibre-gl": "https://esm.sh/[email protected]",
      "@deck.gl/core": "https://esm.sh/@deck.gl/[email protected]",
      "@deck.gl/layers": "https://esm.sh/@deck.gl/[email protected]",
      "@deck.gl/geo-layers": "https://esm.sh/@deck.gl/[email protected]",
      "@deck.gl/mesh-layers": "https://esm.sh/@deck.gl/[email protected]",
      "@deck.gl/mapbox": "https://esm.sh/@deck.gl/[email protected][email protected]/core,maplibre-gl",
      "@luma.gl/core": "https://esm.sh/@luma.gl/[email protected]",
      "@developmentseed/geotiff": "https://esm.sh/@developmentseed/[email protected]",
      "@developmentseed/deck.gl-geotiff": "https://esm.sh/@developmentseed/[email protected][email protected]/core,@deck.gl/layers,@deck.gl/geo-layers,@deck.gl/mesh-layers,@luma.gl/core,@developmentseed/geotiff"
    }
  }
  </script>
</head>
<body>
  <div id="map"></div>
  <div id="panel">
    <h1>NAIP over Portland</h1>
    <div class="muted">A Cloud Optimized GeoTIFF, decoded and reprojected in your browser with <b>deck.gl-raster</b>. No tile server.</div>
    <label>Imagery opacity</label>
    <input id="opacity" type="range" min="0" max="100" value="100" />
    <label>Scene</label>
    <div id="scene" class="muted">searching…</div>
  </div>

  <script type="module">
    import maplibregl from "maplibre-gl";
    import { MapboxOverlay } from "@deck.gl/mapbox";
    import { COGLayer } from "@developmentseed/deck.gl-geotiff";
    import { DecoderPool } from "@developmentseed/geotiff";

    const STAC = "https://planetarycomputer.microsoft.com/api/stac/v1";
    const SIGN = "https://planetarycomputer.microsoft.com/api/sas/v1/sign?href=";

    const map = new maplibregl.Map({
      container: "map",
      style: "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",
      center: [-122.62, 45.52],
      zoom: 11,
    });

    // size: 0 keeps decoding on the main thread. The default pool spawns a
    // Web Worker from the package URL, which browsers block when that URL is
    // cross-origin (a CDN). Main-thread decoding sidesteps that for a
    // single-file app; add a same-origin worker if you need the throughput.
    const pool = new DecoderPool({ size: 0 });
    const overlay = new MapboxOverlay({ interleaved: true, layers: [] });
    map.addControl(overlay);

    let opacity = 1;
    let geotiff = null;
    let beforeId = null; // draw imagery beneath the basemap's labels
    let styleReady = false;
    let fitted = false;

    function render() {
      if (!geotiff || !styleReady) return;
      overlay.setProps({
        layers: [
          new COGLayer({
            id: "naip",
            geotiff,
            pool,
            opacity,
            beforeId,
            // Frame the map to the COG's own bounds once it has loaded.
            onGeoTIFFLoad: (tiff, { geographicBounds }) => {
              if (fitted) return;
              fitted = true;
              const { west, south, east, north } = geographicBounds;
              map.fitBounds([[west, south], [east, north]], { padding: 40, duration: 0 });
            },
          }),
        ],
      });
    }

    document.getElementById("opacity").addEventListener("input", (e) => {
      opacity = e.target.value / 100;
      render();
    });

    map.on("load", () => {
      // Insert deck layers before the first label layer so basemap text
      // (place names, roads) stays legible on top of the imagery.
      beforeId = map.getStyle().layers.find((l) => l.type === "symbol")?.id;
      styleReady = true;
      render();
    });

    // Find a NAIP scene over Portland, then sign its asset href. The Planetary
    // Computer signing endpoint is public. No key, no backend.
    const search = await fetch(`${STAC}/search`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        collections: ["naip"],
        bbox: [-122.70, 45.50, -122.55, 45.57],
        datetime: "2022-01-01/2023-01-01",
        limit: 1,
      }),
    }).then((r) => r.json());

    const item = search.features[0];
    const signed = await fetch(SIGN + encodeURIComponent(item.assets.image.href)).then((r) => r.json());
    geotiff = signed.href;
    document.getElementById("scene").textContent = item.id;
    render();
  </script>
</body>
</html>
Lingua principale
TypeScript
Stelle
240
Fork
34
Merge medio
17h 24m
PR unite (30g)
62

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di developmentseed/deck.gl-raster

Tutte le issue di developmentseed/deck.gl-raster

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.