mapbox / mapbox/mapbox-maps-ios

Disappearing LineStrings

Open
#2,104 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Swift
Stars
601
Forks
196
PR merge metrics
No merged PRs in 30d

Description

Environment

  • Xcode version: 15.1
  • iOS version: 17
  • Devices affected: all
  • Maps SDK Version: 11.1

Observed behavior and steps to reproduce

https://github.com/mapbox/mapbox-maps-ios/assets/514571/f77d61ec-655c-4e86-abdf-ae9cf4b3e588

When I import a large GeoJson to show on the map, I noticed that the lines would disappear depending on zoom level. After some investigation it seems that MapBox does not like when there are lot of Feature's with LineStrings inside. Here is the minimal code sample to produce the issue.

import UIKit
import MapboxMaps

final class MultipleGeometriesExample: UIViewController, ExampleProtocol {
    private var mapView: MapView!
    private var cancelables = Set<AnyCancelable>()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Set the center coordinate and zoom level.
        let centerCoordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0)
        let options = MapInitOptions(cameraOptions: CameraOptions(center: centerCoordinate, zoom: 11))

        mapView = MapView(frame: view.bounds, mapInitOptions: options)
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        view.addSubview(mapView)
        
        var lines:[LineString] = []
        for i in 0...1000 {
            lines.append(LineString([
                CLLocationCoordinate2DMake(59 + Double(i)*(1 / 1000), 25 + Double(i)*(1 / 1000)),
                CLLocationCoordinate2DMake(59 + Double(i + 1)*(1 / 1000), 25 + Double(i + 1)*(1 / 1000))
            ]))
        }
        
        // Allow the view controller to receive information about map events.
        mapView.mapboxMap.onMapLoaded.observeNext { [weak self] _ in
            guard let self = self else { return }

            let referenceCamera = CameraOptions()

            let camera = (try? mapView.mapboxMap.camera(
                for: [lines.first!.coordinates[0], lines.last!.coordinates[1]],
                camera: CameraOptions(),
                coordinatesPadding: .init(allEdges: 0),
                maxZoom: nil,
                offset: nil))!
            
            mapView.camera.fly(to: camera, duration: 0.5)

            var line = GeoJSONSource(id: "line")
            line.data = .featureCollection(FeatureCollection(features: lines.compactMap({ Feature(geometry: $0) })))
            
            var lineLayer = LineLayer(id: "line-layer", source: line.id)
            lineLayer.lineColor = .constant(StyleColor(.red))
            lineLayer.lineWidth = .constant(4)
            lineLayer.lineCap = .constant(.round)
            lineLayer.lineJoin = .constant(.round)
            
            try! mapView.mapboxMap.addSource(line)
            try! mapView.mapboxMap.addLayer(lineLayer)
            
            self.finish()
        }.store(in: &cancelables)
    }
}

Expected behavior

The lines painted would not disappear.

Notes / preliminary analysis

It seems that if the LineStrings from all the Features are merged then into one LineString then the lines do not dissapear. It is not a feasible workaround for all cases as the continuous route is usually one feature anyway.

Additional links and references

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 MultipleGeometriesExample entry point and its mapboxMap.onMapLoaded setup, using the supplied 1,000-LineString reproduction. Trace how the GeoJSONSource and LineLayer handle separate LineString features across zoom levels. Done means the lines remain visible at the affected zoom levels without requiring that features be merged.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.