Hızlı başlangıç: MapLibre GL JS
Bu örnek Updraft "pilot gözü" vektör stilini açar ve termik ızgarasını ay, saat dilimi ve rüzgâr yönüne göre süzer. Aynı kod bu sitede çalışıyor: canlı örnek.
1. Kurulum
npm install @updraft/maps [email protected]
Harita için sayfada bir kap:
<div id="map" style="height: 70vh"></div>
<script type="module" src="./main.js"></script>
2. Harita ve termik süzgeci
Aşağıdaki dosyayı projenize kopyalayın (updraft-map.js). İşin çoğunu Updraft istemci paketi @updraft/maps yapar: updraftMapOptions stili açar, anahtar varsa X-Api-Key başlığını yalnız Updraft karo sunucusuna giden isteklere ekler ve atıf kutusunu açık tutar; setThermalFilter termik kaynağının adresini süzgece göre değiştirir. Paket maplibre-gl'i kendisi içe aktarmaz, sizin kopyanızla çalışır. Paketin API istemcisi ve tipleri: Kimlik.
// Updraft quick start 1: MapLibre GL JS + the Updraft "pilot eye" vector style + the thermal grid.
// npm install @updraft/maps [email protected]
import { Map as MapLibreMap, NavigationControl, ScaleControl } from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
import { updraftMapOptions } from '@updraft/maps/maplibre';
// setThermalFilter(map, { month, hourBucket, windSector }) points the style's `thermals` source at
// a breakdown; thermalsUrl(filter) gives its TileJSON address.
export { setThermalFilter } from '@updraft/maps/maplibre';
export { thermalsUrl } from '@updraft/maps';
/**
* Creates the map. `apiKey` is optional: with a key (scope `tiles`) every request to the Updraft
* tile server, and only to it, carries the `X-Api-Key` header and counts towards your key's usage;
* without one the public tile path is used, which is limited per client address.
* `updraftMapOptions` also keeps the attribution box open ("© Updraft · © OpenStreetMap
* contributors · © OpenMapTiles · Copernicus DEM" must stay visible).
* @param {object} options
* @param {HTMLElement | string} options.container
* @param {string} [options.apiKey] key with the `tiles` scope (header, never in the URL)
* @param {'light' | 'dark'} [options.theme] published style; default light
* @param {string} [options.style] your own style URL instead
* @param {string} [options.tilesUrl] Updraft tile server root; default https://maps.updraftmaps.com
* @param {[number, number]} [options.center] [longitude, latitude]
* @param {number} [options.zoom]
* @returns {MapLibreMap}
*/
export function createUpdraftMap(options) {
const map = new MapLibreMap(updraftMapOptions(options));
map.addControl(new NavigationControl(), 'top-right');
map.addControl(new ScaleControl({ unit: 'metric' }), 'bottom-left');
return map;
}
// Usage:
// const map = createUpdraftMap({ container: 'map', apiKey: 'upd_…' });
// map.on('load', () => setThermalFilter(map, { month: 7, hourBucket: 6, windSector: 6 }));
Kullanım (main.js):
import { setWorkerUrl } from 'maplibre-gl';
import workerUrl from 'maplibre-gl/dist/maplibre-gl-worker.mjs?url';
import { createUpdraftMap, setThermalFilter } from './updraft-map.js';
// MapLibre 6 çizim işçisini ayrı dosyadan yükler; paketleyicide adresini verin (Vite):
setWorkerUrl(workerUrl);
const map = createUpdraftMap({ container: 'map', apiKey: 'upd_…' }); // anahtar isteğe bağlı
map.on('load', () => {
// Temmuz, 12:00–14:00 (yerel), batıdan esen rüzgâr
setThermalFilter(map, { month: 7, hourBucket: 6, windSector: 6 });
});
3. Termik parametreleri
Termik ızgarası Martin'in thermals fonksiyon kaynağıdır; süzgeç TileJSON adresinin sorgu dizisindedir (https://maps.updraftmaps.com/thermals?month=7&hour_bucket=6).
| Parametre | Değerler | "Hepsi" | Anlamı |
|---|---|---|---|
month |
1–12 | 0 (varsayılan) | Yerel ay |
hour_bucket |
0–11 | 12 (varsayılan) | Yerel iki saatlik dilim: 0 = 00–02, 6 = 12–14 |
wind_sector |
0–7 | 8 (varsayılan) | 850 hPa rüzgârının geldiği 45° dilim: 0 kuzey, 2 doğu, 4 güney, 6 batı |
Geçersiz değer boş karo döndürür. Izgara z8–14'te çizilir (z8–10 ~5 km², z11–14 ~0,1 km² altıgenler); her hücrede avg_climb_ms (ortalama tırmanış, 0,1 m/s), confidence_tier (low, medium, high) ve min_pilots (en az N pilot) vardır. Yeterli sayıda farklı pilotun uçmadığı hücre hiç gelmez (Gizlilik). Ayrıntı: Karolar ve stiller.
4. Anahtar ve köken
- Anahtar
transformRequestile yalnız Updraft karo sunucusuna giden isteklere eklenir; adrese (?key=) yazılmaz, sunucu ve CDN günlüklerine düşmez. - Tarayıcıya giden anahtar herkes tarafından görülebilir: yalnız
tileskapsamlı bir anahtar kullanın. Sızarsa yalnız karo okunur ve anahtar iptal edilir (Kimlik). - Karo sunucusu tarayıcı isteklerini yalnız kayıtlı kökenlerden kabul eder (CORS). Anahtarı alırken sitenizin kökenini (
https://ornek.com) bildirin; yerel deneme içinhttp://localhost:5173gibi adresi de ekletin. - Anahtarsız istek de çalışır, ama istemci adresi başına sınırlıdır ve kullanımınız sayılmaz.
5. Atıf
Stil, atıf satırını kendi taşır: "© Updraft · © OpenStreetMap contributors · © OpenMapTiles · Copernicus DEM". Örnek MapLibre'nin atıf kutusunu açık (katlanmamış) tutar; satırı gizlemeyin ya da yalnız bir menüye koymayın. Termik katmanını kullanıyorsanız lisanslar sayfanıza DWD rüzgâr verisi atfını da koyun (Atıf kuralları).