Skip to content
Open
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
21 changes: 17 additions & 4 deletions packages/ui-mapbox/platforms/ios/src/MapboxBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ 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"

// Notification constants
public static let MapLoadedNotification = "MapboxBridgeMapLoaded"
Expand Down Expand Up @@ -203,6 +205,8 @@ public class MapboxBridge: NSObject {

// Register this bridge for the created MapView
MapboxBridge.registerBridge(self, for: mv)

pointAnnotationManager = mv.annotations.makePointAnnotationManager(id: MapboxBridge.MARKER_LAYER_ID)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you instantiate here when you are already doing it later when accessed?

let defaultPinImage = UIImage(named: "default_pin")
if (defaultPinImage != nil) {
self.defaultPinImageHeight = defaultPinImage!.size.height
Expand Down Expand Up @@ -445,7 +449,7 @@ public class MapboxBridge: NSObject {
guard let markers = try? JSONSerialization.jsonObject(with: data, options: []) as! [NSDictionary] else { return }

if pointAnnotationManager == nil {
pointAnnotationManager = mv.annotations.makePointAnnotationManager()
pointAnnotationManager = mv.annotations.makePointAnnotationManager(id: MapboxBridge.MARKER_LAYER_ID)
}
guard let manager = pointAnnotationManager else { return }

Expand Down Expand Up @@ -935,7 +939,10 @@ public class MapboxBridge: NSObject {


if polylineAnnotationManager == nil {
polylineAnnotationManager = mv.annotations.makePolylineAnnotationManager()
polylineAnnotationManager = mv.annotations.makePolylineAnnotationManager(
id: "mapbox-ios-polylines",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a static property for the name here too, as you use it in multiple places ?

layerPosition: .below(MapboxBridge.MARKER_LAYER_ID)
)
}
guard let manager = polylineAnnotationManager else { return false }
var annotation = PolylineAnnotation(id: id, lineCoordinates: ccoords)
Expand Down Expand Up @@ -1139,7 +1146,10 @@ public class MapboxBridge: NSObject {


if polygonAnnotationManager == nil {
polygonAnnotationManager = mv.annotations.makePolygonAnnotationManager()
polygonAnnotationManager = mv.annotations.makePolygonAnnotationManager(
id: "mapbox-ios-polygons",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a static property for the name here too, as you use it in multiple places ?

layerPosition: .below(MapboxBridge.MARKER_LAYER_ID)
)
}
guard let manager = polygonAnnotationManager else { return false }
let polygon = Polygon(outerRing: .init(coordinates: ccoords))
Expand All @@ -1162,7 +1172,10 @@ public class MapboxBridge: NSObject {

if (strokeOpacity != nil || strokeWidth != nil){
if polygonOutlineAnnotationManager == nil {
polygonOutlineAnnotationManager = mv.annotations.makePolylineAnnotationManager()
polygonOutlineAnnotationManager = mv.annotations.makePolylineAnnotationManager(
id: "mapbox-ios-polygon-outlines",
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