mapbox / mapbox/mapbox-maps-ios
Disappearing LineStrings
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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