diff --git a/packages/ui-mapbox/platforms/ios/src/MapboxBridge.swift b/packages/ui-mapbox/platforms/ios/src/MapboxBridge.swift index 12f8892..9b32183 100644 --- a/packages/ui-mapbox/platforms/ios/src/MapboxBridge.swift +++ b/packages/ui-mapbox/platforms/ios/src/MapboxBridge.swift @@ -95,6 +95,11 @@ public class MapboxBridge: NSObject { public func postEvent(_ event: String) { NotificationCenter.default.post(name: Notification.Name(event), object: self.mapView) } + + public static let MARKER_LAYER_ID = "mapbox-ios-markers" + public static let POLYLINE_LAYER_ID = "mapbox-ios-polylines" + public static let POLYGON_LAYER_ID = "mapbox-ios-polygons" + public static let POLYGON_OUTLINE_LAYER_ID = "mapbox-ios-polygon-outlines" // Notification constants public static let MapLoadedNotification = "MapboxBridgeMapLoaded" @@ -168,6 +173,16 @@ public class MapboxBridge: NSObject { return MapboxBridge.bridgeTable.object(forKey: mapView) as? MapboxBridge } + private func ensurePointAnnotationManager(for mapView: MapView) -> PointAnnotationManager { + if let manager = pointAnnotationManager { + return manager + } + + let manager = mapView.annotations.makePointAnnotationManager(id: MapboxBridge.MARKER_LAYER_ID) + pointAnnotationManager = manager + return manager + } + @objc public func getMapView() -> MapView? { return mapView } @@ -203,6 +218,7 @@ public class MapboxBridge: NSObject { // Register this bridge for the created MapView MapboxBridge.registerBridge(self, for: mv) + _ = ensurePointAnnotationManager(for: mv) let defaultPinImage = UIImage(named: "default_pin") if (defaultPinImage != nil) { self.defaultPinImageHeight = defaultPinImage!.size.height @@ -444,10 +460,7 @@ public class MapboxBridge: NSObject { guard let data = markersJSON.data(using: .utf8) else { return } guard let markers = try? JSONSerialization.jsonObject(with: data, options: []) as! [NSDictionary] else { return } - if pointAnnotationManager == nil { - pointAnnotationManager = mv.annotations.makePointAnnotationManager() - } - guard let manager = pointAnnotationManager else { return } + let manager = ensurePointAnnotationManager(for: mv) var current = manager.annotations var additions: [PointAnnotation] = [] @@ -934,8 +947,12 @@ public class MapboxBridge: NSObject { } + _ = ensurePointAnnotationManager(for: mv) if polylineAnnotationManager == nil { - polylineAnnotationManager = mv.annotations.makePolylineAnnotationManager() + polylineAnnotationManager = mv.annotations.makePolylineAnnotationManager( + id: MapboxBridge.POLYLINE_LAYER_ID, + layerPosition: .below(MapboxBridge.MARKER_LAYER_ID) + ) } guard let manager = polylineAnnotationManager else { return false } var annotation = PolylineAnnotation(id: id, lineCoordinates: ccoords) @@ -1138,8 +1155,12 @@ public class MapboxBridge: NSObject { } + _ = ensurePointAnnotationManager(for: mv) if polygonAnnotationManager == nil { - polygonAnnotationManager = mv.annotations.makePolygonAnnotationManager() + polygonAnnotationManager = mv.annotations.makePolygonAnnotationManager( + id: MapboxBridge.POLYGON_LAYER_ID, + layerPosition: .below(MapboxBridge.MARKER_LAYER_ID) + ) } guard let manager = polygonAnnotationManager else { return false } let polygon = Polygon(outerRing: .init(coordinates: ccoords)) @@ -1162,7 +1183,10 @@ public class MapboxBridge: NSObject { if (strokeOpacity != nil || strokeWidth != nil){ if polygonOutlineAnnotationManager == nil { - polygonOutlineAnnotationManager = mv.annotations.makePolylineAnnotationManager() + polygonOutlineAnnotationManager = mv.annotations.makePolylineAnnotationManager( + id: MapboxBridge.POLYGON_OUTLINE_LAYER_ID, + layerPosition: .below(MapboxBridge.MARKER_LAYER_ID) + ) } var outline = PolylineAnnotation(id: id, lineCoordinates: ccoords) if (strokeColor != nil) { diff --git a/src/ui-mapbox/index.android.ts b/src/ui-mapbox/index.android.ts index ea8a278..86f55fb 100755 --- a/src/ui-mapbox/index.android.ts +++ b/src/ui-mapbox/index.android.ts @@ -669,7 +669,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi { const annotationPlugin = this._getPlugin('MAPBOX_ANNOTATION_PLUGIN_ID'); this.lineManager = annotationPlugin.createAnnotationManager( com.mapbox.maps.plugin.annotation.AnnotationType.PolylineAnnotation, - new com.mapbox.maps.plugin.annotation.AnnotationConfig() + new com.mapbox.maps.plugin.annotation.AnnotationConfig(MarkerManager.LAYER_ID) ) as com.mapbox.maps.plugin.annotation.generated.PolylineAnnotationManager; this.onAnnotationClickListener = new com.mapbox.maps.plugin.annotation.generated.OnPolylineAnnotationClickListener({ @@ -1754,7 +1754,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi { const annotationPlugin = this._getPlugin('MAPBOX_ANNOTATION_PLUGIN_ID'); this.polygonManager = annotationPlugin.createAnnotationManager( com.mapbox.maps.plugin.annotation.AnnotationType.PolygonAnnotation, - new com.mapbox.maps.plugin.annotation.AnnotationConfig() + new com.mapbox.maps.plugin.annotation.AnnotationConfig(MarkerManager.LAYER_ID) ) as com.mapbox.maps.plugin.annotation.generated.PolygonAnnotationManager; } const polygonOptions = new com.mapbox.maps.plugin.annotation.generated.PolygonAnnotationOptions(); @@ -1796,7 +1796,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi { const annotationPlugin = this._getPlugin('MAPBOX_ANNOTATION_PLUGIN_ID'); this.lineManager = annotationPlugin.createAnnotationManager( com.mapbox.maps.plugin.annotation.AnnotationType.PolylineAnnotation, - new com.mapbox.maps.plugin.annotation.AnnotationConfig() + new com.mapbox.maps.plugin.annotation.AnnotationConfig(MarkerManager.LAYER_ID) ) as com.mapbox.maps.plugin.annotation.generated.PolylineAnnotationManager; } const polylineOptions = new com.mapbox.maps.plugin.annotation.generated.PolylineAnnotationOptions(); diff --git a/src/ui-mapbox/markers/MarkerManager.android.ts b/src/ui-mapbox/markers/MarkerManager.android.ts index b2cbd73..8e554f8 100644 --- a/src/ui-mapbox/markers/MarkerManager.android.ts +++ b/src/ui-mapbox/markers/MarkerManager.android.ts @@ -29,7 +29,7 @@ export class MarkerManager { this.mapView = mapView; this.onInfoWindowTapped = onInfoWindowClick; const AnnotationConfig = com.mapbox.maps.plugin.annotation.AnnotationConfig; - const layerConfig = new AnnotationConfig(MarkerManager.LAYER_ID); + const layerConfig = new AnnotationConfig(null, MarkerManager.LAYER_ID); const annotationPlugin = mapView.getPlugin('MAPBOX_ANNOTATION_PLUGIN_ID') as com.mapbox.maps.plugin.annotation.AnnotationPlugin; this.pointAnnotationManager = annotationPlugin.createAnnotationManager( com.mapbox.maps.plugin.annotation.AnnotationType.PointAnnotation,