Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions packages/ui-mapbox/platforms/ios/src/MapboxBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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] = []
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/ui-mapbox/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
const annotationPlugin = this._getPlugin<com.mapbox.maps.plugin.annotation.AnnotationPlugin>('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({
Expand Down Expand Up @@ -1754,7 +1754,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
const annotationPlugin = this._getPlugin<com.mapbox.maps.plugin.annotation.AnnotationPlugin>('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();
Expand Down Expand Up @@ -1796,7 +1796,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
const annotationPlugin = this._getPlugin<com.mapbox.maps.plugin.annotation.AnnotationPlugin>('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();
Expand Down
2 changes: 1 addition & 1 deletion src/ui-mapbox/markers/MarkerManager.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down