Skip to content

Commit 3ec0f75

Browse files
committed
fix(ios): working marker image and other fixes
1 parent 7695e79 commit 3ec0f75

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

packages/ui-mapbox/platforms/ios/src/MapboxBridge.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public class MapboxBridge: NSObject {
202202
// Register this bridge for the created MapView
203203
MapboxBridge.registerBridge(self, for: mv)
204204

205-
addImage("default_pin", image: UIImage(named: "default_pin"))
205+
addImage("default_pin", UIImage(named: "default_pin"))
206206

207207
if let options = optionsOpt {
208208
if ((options["hideLogo"] as? Bool) == true) {
@@ -409,7 +409,7 @@ public class MapboxBridge: NSObject {
409409
return nil
410410
}
411411

412-
@objc public func addImage(_ imageId: String, image: UIImage?) {
412+
@objc public func addImage(_ imageId: String, _ image: UIImage?) {
413413
guard let mv = mapView else { return }
414414
if (image != nil) {
415415
imageRegistry[imageId] = image!
@@ -545,7 +545,7 @@ public class MapboxBridge: NSObject {
545545
annotation.allowOverlapWithPuck = true
546546
let image = an.image
547547
let imageHeight = image?.image.size.height ?? 0
548-
let offsetY = imageHeight - 12
548+
let offsetY = imageHeight/2 + 5
549549
// TODO: variableAnchors is broken for now if multiple
550550
annotation.variableAnchors = [ViewAnnotationAnchorConfig(anchor: .bottom, offsetY: offsetY)
551551
// , ViewAnnotationAnchorConfig(anchor: .bottomLeft, offsetY: offsetY), ViewAnnotationAnchorConfig(anchor: .bottomRight, offsetY: offsetY)
@@ -559,6 +559,7 @@ public class MapboxBridge: NSObject {
559559
@objc public func updateViewAnnotationForMarker(_ markerId: String, _ lat: Double, _ lng: Double) -> Bool {
560560
guard mapView != nil else { return false }
561561
guard let view = viewAnnotationByMarkerId[markerId] else { return false }
562+
view.view.setNeedsLayout()
562563
view.annotatedFeature = .geometry(Point(CLLocationCoordinate2D(latitude: lat, longitude: lng)))
563564
return true
564565
}

src/ui-mapbox/index.ios.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async function fetchImageIOS(imagePath: string): Promise<any> {
119119
if (!imagePath) return null;
120120
if (_markerIconDownloadCache[imagePath]) return _markerIconDownloadCache[imagePath];
121121
const img = await Http.getImage(imagePath);
122-
if (img && img.ios) {
122+
if (img?.ios) {
123123
_markerIconDownloadCache[imagePath] = img.ios;
124124
return img.ios;
125125
}
@@ -474,7 +474,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
474474
this.setMapboxViewInstance(nativeMap);
475475

476476
if (settings.showUserLocation) {
477-
this.showUserLocationMarker({});
477+
this.showUserLocationMarker({ cameraMode: 'NONE' });
478478
}
479479

480480
this.initEventHandlerShim(settings, this._mapboxViewInstance);
@@ -632,7 +632,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
632632
);
633633

634634
updated.forEach((m) => {
635-
if (m.icon && typeof m.icon === 'string' && (m as any).iconDownloaded) {
635+
if (typeof m?.icon === 'string' && (m as any).iconDownloaded) {
636636
try {
637637
b.addImage(m.icon, (m as any).iconDownloaded);
638638
delete (m as any).iconDownloaded;
@@ -669,8 +669,8 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
669669
_marker.lng = newSettings.lng;
670670
b.updateMarkerPosition(_marker.id + '', newSettings.lat, newSettings.lng);
671671
}
672-
673-
if (newSettings.selected) {
672+
if (newSettings.selected || this.isMarkerSelected(_marker)) {
673+
// this will also update callout position
674674
this.selectMarker(_marker);
675675
}
676676
}
@@ -688,8 +688,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
688688
});
689689
}
690690
selectedMarker: MapboxMarker;
691+
692+
isMarkerSelected(marker: MapboxMarker) {
693+
return this.selectedMarker === marker || this.selectedMarker?.id === marker.id;
694+
}
691695
async deselectMarker(marker: MapboxMarker) {
692-
if (this.selectedMarker === marker || this.selectedMarker?.id === marker.id) {
696+
if (this.isMarkerSelected(marker)) {
693697
this.hideCalloutForMarkerById(marker.id + '');
694698
this.selectedMarker = null;
695699
}
@@ -700,7 +704,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
700704
if (Trace.isEnabled()) {
701705
CLog(CLogTypes.info, 'selectMarker():', marker.id);
702706
}
703-
if (this.selectedMarker) {
707+
if (this.selectedMarker && !this.isMarkerSelected(marker)) {
704708
this.deselectMarker(this.selectedMarker);
705709
}
706710
await this.showCalloutForMarkerById(marker.id + '');
@@ -1371,8 +1375,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
13711375
if (Trace.isEnabled()) {
13721376
CLog(CLogTypes.info, 'createCalloutView1():', marker.id, marker.title, !!this._reusableCalloutView);
13731377
}
1374-
this._reusableCalloutView.removeEventListener('tap');
1375-
(this._reusableCalloutView.nativeViewProtected as UIView)?.removeFromSuperview();
13761378
return this._reusableCalloutView;
13771379
}
13781380

@@ -1384,10 +1386,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
13841386
if (Trace.isEnabled()) {
13851387
CLog(CLogTypes.info, 'showCalloutForMarkerById():', typeof markerId, markerId);
13861388
}
1389+
const callout = this.createCalloutView(m);
13871390
if (this.bridgeInstance.hasViewAnnotationForMarker(markerId)) {
1388-
return;
1391+
// let s Update
1392+
this.bridgeInstance.removeViewAnnotationForMarker(markerId);
1393+
// return;
13891394
}
1390-
const callout = this.createCalloutView(m);
13911395
callout.on('tap', () => {
13921396
try {
13931397
const res = m.onCalloutTap ? m.onCalloutTap(m) : undefined;
@@ -1396,6 +1400,8 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
13961400
console.error('callout tap handler error', e);
13971401
}
13981402
});
1403+
this._reusableCalloutView.removeEventListener('tap');
1404+
(this._reusableCalloutView.nativeViewProtected as UIView)?.removeFromSuperview();
13991405
try {
14001406
const nativeView = createUIViewAutoSizeUIViewAutoSize(callout);
14011407
if (Trace.isEnabled()) {
@@ -1778,12 +1784,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
17781784
onStart(nativeMap?: any): Promise<void> {
17791785
return Promise.resolve();
17801786
}
1781-
onResume(nativeMap?: any): Promise<void> {
1782-
return Promise.resolve();
1783-
}
1784-
onPause(nativeMap?: any): Promise<void> {
1785-
return Promise.resolve();
1786-
}
1787+
// onResume(nativeMap?: any): Promise<void> {
1788+
// return Promise.resolve();
1789+
// }
1790+
// onPause(nativeMap?: any): Promise<void> {
1791+
// return Promise.resolve();
1792+
// }
17871793
onStop(nativeMap?: any): Promise<void> {
17881794
return Promise.resolve();
17891795
}

src/ui-mapbox/typings/mapbox.bridge.ios.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare class MapboxBridge extends NSObject {
3232

3333
setStyle(styleURIOrURL: string, completion: (success: boolean, error?: any) => void): void;
3434

35-
addImage(imageId: string, image: any): void;
35+
addImage(imageId: string, image: UIImage): void;
3636
removeImage(imageId: string): void;
3737

3838
addMarkers(markers: string): void;

0 commit comments

Comments
 (0)