mapbox-maps-ios
mapbox-maps-ios copied to clipboard
Disappearing LineStrings
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
@pjleonard37 @persidskiy @aleksproger @OdNairy @evil159 @maios
Any thoughts on this issue?
@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