mapbox / mapbox-maps-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and Metal
https://www.mapbox.com/mapbox-mobile-sdk
Other
485 stars 157 forks source link

Disappearing LineStrings #2104

Open ristiisa opened 10 months ago

ristiisa commented 10 months ago

Environment

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

ristiisa commented 10 months ago

@pjleonard37 @persidskiy @aleksproger @OdNairy @evil159 @maios

Any thoughts on this issue?

persidskiy commented 10 months ago

@ristiisa Thank you for filing this issue, we will look into it. If you need a priority support, please contact our support team https://www.mapbox.com/support