mapbox / mapbox/mapbox-maps-flutter

Start and End Point Icons Overlapped by Trace Path in Mapbox

Open
#309 0 comments 2 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

I'm encountering an issue in my Mapbox implementation where the icons representing the start and end points of a movement trace are being overlapped by the trace path line. I'm looking for a way to ensure that these point icons are rendered above the trace line. Below is the relevant code snippet from my application:

/// Displays the start icon of the movement trace
void showStartLocation() async {
  final tracePositions = this.tracePositions;
  final ByteData bytes = await rootBundle.load('assets/images/icon_marker_start.png');
  final Uint8List imageData = bytes.buffer.asUint8List();
  Point start = Point(coordinates: tracePositions.first);
  final annotation = await pointAnnotationManager.addAnnotation(imageData, start);
}

/// Displays the end icon of the movement trace
void showEndLocation() async {
  final tracePositions = this.tracePositions;
  final ByteData bytes = await rootBundle.load('assets/images/icon_marker_end.png');
  final Uint8List imageData = bytes.buffer.asUint8List();
  Point end = Point(coordinates: tracePositions.last);
  final annotation = await pointAnnotationManager.addAnnotation(imageData, end);
}

/// Draws the movement trace path
void drawTraceLocationPath(List<Position> polyline) async {
  final mapboxMap = this.mapboxMap;
  final line = LineString(coordinates: polyline);

  mapboxMap.style.styleSourceExists("source").then((exists) async {
    if (exists) {
      // If source exists - just update it
      final source = await mapboxMap.style.getSource("source");
      (source as GeoJsonSource).updateGeoJSON(json.encode(line));
    } else {
      await mapboxMap.style.addSource(GeoJsonSource(id: "source", data: json.encode(line), lineMetrics: true));
      await mapboxMap.style.addLayer(LineLayer(
        id: 'layer',
        sourceId: 'source',
        lineCap: LineCap.ROUND,
        lineJoin: LineJoin.ROUND,
        lineBlur: 1.0,
        lineTrimOffset: [0.0, 0.0],
        lineWidth: 10,
      ));
    }

    final lineGradient = jsonEncode([
      'interpolate',
      ['linear'],
      ['line-progress'],
      ...MapUtils.getMapboxLineGradient(widget.tracePoints!)
    ]);

    // Draw layer with gradient
    mapboxMap.style.setStyleLayerProperty('layer', 'line-gradient', lineGradient);
  });
}

issue-img

The issue is that the line representing the movement trace is rendering on top of the start and end point icons, making them less visible or entirely obscured. I need the start and end icons to always appear on top of the trace line for better visibility. Is there a specific setting or method in Mapbox that allows for controlling the z-index or layer order of these elements?

Any guidance or suggestions would be greatly appreciated. Thank you!

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 the shown showStartLocation, showEndLocation, and drawTraceLocationPath methods, then read the Mapbox Maps Flutter documentation for annotation and style-layer ordering. Reproduce the line and point annotations from the snippet; done means the start and end icons remain visibly above the trace line.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.