Hızlı başlangıç: maplibre_gl (Flutter, vektör)
maplibre_gl Android ve iOS'ta MapLibre Native'i, web'de MapLibre GL JS'i kullanır. Vektör stil raster karodan keskindir, döndürmede etiketler düz kalır, karo yükü azdır ve termik, skyway, kalkış ve iniş katmanları stilin içinde gelir.
1. Bağımlılık
flutter pub add updraft_maps maplibre_gl:0.28.0
updraft_maps Updraft'ın istemci paketidir: stil adresi (updraftStyleString), anahtar başlığı (applyUpdraftKey), termik süzgeci (setUpdraftThermalFilter) ve atıf satırı (UpdraftAttribution).
Platform kurulumu (Android minSdk, iOS sürümü ve konum izinleri) paketin kendi belgesindedir; web için ek ayar gerekmez.
2. Harita
// Updraft quick start 3: maplibre_gl (MapLibre Native on Android/iOS, MapLibre GL JS on web)
// with the Updraft "pilot eye" vector style and the thermal grid, through the updraft_maps package.
import 'package:flutter/material.dart';
import 'package:maplibre_gl/maplibre_gl.dart';
import 'package:updraft_maps/maplibre_gl.dart';
import 'raster_map.dart'
show openAttributionRules, updraftTiles, updraftTilesKey;
class VectorMapScreen extends StatefulWidget {
const VectorMapScreen({super.key, this.dark = false});
/// `pilot-dark` instead of `pilot-light`.
final bool dark;
@override
State<VectorMapScreen> createState() => _VectorMapScreenState();
}
class _VectorMapScreenState extends State<VectorMapScreen> {
MapLibreMapController? _controller;
UpdraftTheme get _theme =>
widget.dark ? UpdraftTheme.dark : UpdraftTheme.light;
Future<void> _onMapCreated(MapLibreMapController controller) async {
_controller = controller;
// The key goes only to the Updraft tile server, as a header (Android and iOS; on web the
// public tile path is used, a browser key would be visible to everyone).
await applyUpdraftKey(
controller,
apiKey: updraftTilesKey,
tilesUrl: updraftTiles,
);
}
// Thermal grid for July, 12:00–14:00 local time, wind from the west (all values: ThermalFilter()).
Future<void> _onStyleLoaded() => setUpdraftThermalFilter(
_controller!,
ThermalFilter(month: 7, hourBucket: 6, windSector: 6),
theme: _theme,
tilesUrl: updraftTiles,
);
@override
Widget build(BuildContext context) => Stack(
children: [
MapLibreMap(
styleString: updraftStyleString(theme: _theme, tilesUrl: updraftTiles),
initialCameraPosition: const CameraPosition(
target: LatLng(36.56, 29.17),
zoom: 11.5,
),
onMapCreated: _onMapCreated,
onStyleLoadedCallback: _onStyleLoaded,
minMaxZoomPreference: const MinMaxZoomPreference(4, 17),
compassEnabled: true,
// MapLibre's own attribution button folds the text into a menu: show the line instead.
attributionButtonPosition: AttributionButtonPosition.topRight,
),
const UpdraftAttribution(thermals: true, onTap: openAttributionRules),
],
);
}
updraftTiles, updraftTilesKey ve openAttributionRules flutter_map örneğindeki dosyadan gelir.
3. Anahtar
- Android ve iOS'ta
applyUpdraftKeyanahtarısetCustomHeadersile yalnız Updraft karo sunucusuna giden isteklere ekler (süzgeç bir düzenli ifadedir,updraftHeaderFilter).setHttpHeadersbütün isteklere ekler; başka sunuculara anahtar göndermemek için süzgeçli olanı kullanın. - Web'de başlık ayarlanamaz; tarayıcı anahtarsız, herkese açık karo yolunu kullanır (istemci adresi başına sınırlı). Web için MapLibre GL JS'i doğrudan kullanmak isterseniz: MapLibre hızlı başlangıcı.
- Uygulamaya giren anahtar yalnız
tileskapsamlı olmalıdır.
4. Termik ızgarası
Stil termik ızgarasını "bütün aylar, bütün gün, bütün rüzgâr yönleri" kırılımıyla çizer (thermals kaynağı, katmanlar thermals-fill ve thermals-line). Başka bir kırılım için kaynağın TileJSON adresi süzgeçle değişir, ör. https://maps.updraftmaps.com/thermals?month=7&hour_bucket=6. maplibre_gl kaynak adresini değiştiremez; setUpdraftThermalFilter kaynağı bu adresle yeniden ekler ve iki katmanı stildeki özelliklerle, skyway katmanlarının altına yeniden kurar (stil yüklendikten sonra çağırın, örnekte onStyleLoadedCallback). Parametreler: Karolar ve stiller.
5. Atıf
MapLibre'nin kendi atıf düğmesi metni bir menüye katlar; kurallara göre satır görünür olmalıdır. Örnek, düğmeyi köşeye alır ve satırı UpdraftAttribution(thermals: true) ile haritanın altına yazar (termik ızgarası gösterildiği için DWD rüzgâr verisi atfıyla) (Atıf).