mapbox / mapbox/mapbox-maps-flutter

Detect whether a coordinate or zone intersects with water layer

Open
#1,111 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dart
Stars
380
Forks
204
PR merge metrics
No merged PRs in 30d

Description

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
}`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with _zoneContainsWater in the issue body and the shown queryRenderedFeatures, pixelForCoordinate, RenderedQueryGeometry.fromScreenBox, and RenderedQueryOptions calls. Verify how returned layers and features represent water and whether a bounding-box query matches coordinate or zone intersection semantics. Done means water zones return true and land-only zones return false, with query errors handled as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
api, mobile-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.