mapbox / mapbox/mapbox-maps-flutter

Detect whether a coordinate or zone intersects with water layer

Aperta
#1,111 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Dart
Stelle
380
Fork
204
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Currently, I am trying to determine whether a coordinate lies on water by querying the rendered features of the water layer using queryRenderedFeatures.
` Future _zoneContainsWater(
double centerLat,
double centerLon,
double radiusNM,
) async {
if (mapboxMap == null) return false;

try {
  // Calculate Bounding Box coordinates for the zone (NW and SE corners)
  final dLat = radiusNM / 60.0;
  final latCos = cos(centerLat * pi / 180.0);
  final dLon = latCos.abs() < 0.0001 ? dLat : dLat / latCos;

  final nLat = centerLat + dLat;
  final sLat = centerLat - dLat;
  final wLon = centerLon - dLon;
  final eLon = centerLon + dLon;

  // Convert those geographic corners to screen pixels
  final nw = await mapboxMap!.pixelForCoordinate(mapBox.Point(coordinates: mapBox.Position(wLon, nLat)));
  final se = await mapboxMap!.pixelForCoordinate(mapBox.Point(coordinates: mapBox.Position(eLon, sLat)));

  // Perform a query across the entire zone's bounding box
  final result = await mapboxMap!.queryRenderedFeatures(
    mapBox.RenderedQueryGeometry.fromScreenBox(mapBox.ScreenBox(
      min: mapBox.ScreenCoordinate(x: min(nw.x, se.x), y: min(nw.y, se.y)),
      max: mapBox.ScreenCoordinate(x: max(nw.x, se.x), y: max(nw.y, se.y)),
    )),
    mapBox.RenderedQueryOptions(
      // Ensure we target our manually added 'water' layer + any style-detected ones
      layerIds: ["water", ..._waterLayerIds],
    ),
  );

  developer.log("Zone query found ${result.length} features in targeted water layers");

  for (var queried in result) {
    if (queried != null) {
      final layers = queried.layers;
      final featureMap = queried.queriedFeature.feature;
      final properties = featureMap["properties"] as Map?;

      print("Water Feature Match: $layers, properties: $properties");

      bool layerMatch = layers.any((layer) =>
          layer != null &&
          (layer.toLowerCase().contains("water") || layer.toLowerCase().contains("ocean") || layer.toLowerCase().contains("lake") || layer.toLowerCase().contains("sea")));

      bool propertyMatch = properties != null && (properties["class"] == "water" || properties["type"] == "water" || properties["water"] == "true");

      if (layerMatch || propertyMatch) {
        developer.log("WATER CONFIRMED inside Zone Box!");
        return true;
      }
    }
  }
} catch (e) {
  developer.log("Error querying zone box for water: $e");
}

return false; // No water features found within the 2*Radius area

}`

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia da _zoneContainsWater nel corpo della issue e dalle chiamate mostrate a queryRenderedFeatures, pixelForCoordinate, RenderedQueryGeometry.fromScreenBox e RenderedQueryOptions. Verifica come i layer e le feature restituiti rappresentano l’acqua e se una query con bounding box corrisponde alla semantica di intersezione delle coordinate o delle zone. Il lavoro è completato quando le zone d’acqua restituiscono true e le zone composte esclusivamente da terra restituiscono false, con gli errori di query gestiti come mostrato.

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

Valutazione

Stack tecnologico
dart, flutter
Ambito
api, mobile-dev
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
40/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.