@nativescript-community/ui-mapbox 7.0.3 → 7.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [7.0.4](https://github.com/nativescript-community/ui-mapbox/compare/v7.0.3...v7.0.4) (2025-10-30)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **ios:** working marker image and other fixes ([3ec0f75](https://github.com/nativescript-community/ui-mapbox/commit/3ec0f75f72708a03cafb2a0a1cd847cea8e74206))
11
+
6
12
  ## [7.0.3](https://github.com/nativescript-community/ui-mapbox/compare/v7.0.2...v7.0.3) (2025-10-29)
7
13
 
8
14
  **Note:** Version bump only for package @nativescript-community/ui-mapbox
package/common.js CHANGED
@@ -269,18 +269,9 @@ export class MapboxViewCommonBase extends ContentView {
269
269
  onStart() {
270
270
  return this.mapbox?.onStart(this.getNativeMapView());
271
271
  }
272
- // onResume(nativeMap?: any): Promise<any> {
273
- // return this.mapbox && this.mapbox.onResume(this.getNativeMapView());
274
- // }
275
- // onPause(nativeMap?: any): Promise<any> {
276
- // return this.mapbox && this.mapbox.onPause(this.getNativeMapView());
277
- // }
278
272
  onStop(nativeMap) {
279
273
  return this.mapbox?.onStop(this.getNativeMapView());
280
274
  }
281
- // onLowMemory(nativeMap?: any): Promise<any> {
282
- // return this.mapbox.onLowMemory(this.getNativeMapView());
283
- // }
284
275
  onDestroy(nativeMap) {
285
276
  return this.mapbox?.onDestroy(this.getNativeMapView());
286
277
  }
@@ -65,6 +65,7 @@ export declare class MapboxView extends MapboxViewBase {
65
65
  */
66
66
  createNativeView(): object;
67
67
  onLoaded(): void;
68
+ onUnloaded(): void;
68
69
  initNativeView(): void;
69
70
  /**
70
71
  * when the view is destroyed.
@@ -160,12 +161,6 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
160
161
  */
161
162
  hide(): Promise<void>;
162
163
  unhide(): Promise<void>;
163
- /**
164
- * destroy the map programmatically
165
- *
166
- * Destroy the map instance.
167
- */
168
- clear(nativeMap?: any): void;
169
164
  destroy(nativeMap?: any): Promise<void>;
170
165
  /**
171
166
  * Clear Event Listeners
package/index.android.js CHANGED
@@ -174,16 +174,22 @@ export class MapboxView extends MapboxViewBase {
174
174
  onLoaded() {
175
175
  super.onLoaded();
176
176
  if (Trace.isEnabled()) {
177
- CLog(CLogTypes.info, 'onLoaded()');
177
+ CLog(CLogTypes.info, 'onLoaded()', this);
178
178
  }
179
179
  if (!this.initialized) {
180
180
  this.initMap();
181
181
  this.initialized = true;
182
182
  }
183
183
  }
184
+ onUnloaded() {
185
+ super.onUnloaded();
186
+ if (Trace.isEnabled()) {
187
+ CLog(CLogTypes.info, 'onUnloaded()', this);
188
+ }
189
+ }
184
190
  initNativeView() {
185
191
  if (Trace.isEnabled()) {
186
- CLog(CLogTypes.info, 'initNativeView(): top');
192
+ CLog(CLogTypes.info, 'initNativeView(): top', this);
187
193
  }
188
194
  this.nativeView.owner = this;
189
195
  // Application.android.on(AndroidApplication.activityStartedEvent, this.onStart, this);
@@ -202,13 +208,13 @@ export class MapboxView extends MapboxViewBase {
202
208
  * @link https://docs.nativescript.org/plugins/ui-plugin-custom
203
209
  */
204
210
  disposeNativeView() {
211
+ super.disposeNativeView();
205
212
  if (Trace.isEnabled()) {
206
- CLog(CLogTypes.info, 'disposeNativeView(): top');
213
+ CLog(CLogTypes.info, 'disposeNativeView(): top', this);
207
214
  }
208
215
  this.nativeView.owner = null;
209
216
  this.mapbox?.destroy();
210
217
  this.mapbox = null;
211
- super.disposeNativeView();
212
218
  }
213
219
  /**
214
220
  * initialize the map
@@ -455,7 +461,7 @@ export class Mapbox extends MapboxCommon {
455
461
  logoPlugin.setEnabled(!settings.hideLogo);
456
462
  logoPlugin.setPosition(Mapbox.mapPositionToGravity(settings.logoPosition));
457
463
  if (Trace.isEnabled()) {
458
- CLog(CLogTypes.info, 'show(): onMapReady() with instance:', this._mapboxMapInstance);
464
+ CLog(CLogTypes.info, 'show(): onMapReady() with instance:', this._mapboxMapInstance, this._mapboxViewInstance);
459
465
  }
460
466
  // Android SDK 7.0.0 and on requires that the style be set separately after the map
461
467
  // is initialized. We do not consider the map ready until the style has successfully
@@ -614,16 +620,11 @@ export class Mapbox extends MapboxCommon {
614
620
  throw ex;
615
621
  }
616
622
  }
617
- /**
618
- * destroy the map programmatically
619
- *
620
- * Destroy the map instance.
621
- */
622
- clear(nativeMap) {
623
+ async destroy(nativeMap) {
623
624
  this.clearEventListeners();
624
625
  this._markerIconDownloadCache = {};
625
626
  if (Trace.isEnabled()) {
626
- CLog(CLogTypes.info, 'destroy(): destroying mapbox view.');
627
+ CLog(CLogTypes.info, 'destroy(): destroying mapbox view.', this.view, this._mapboxViewInstance);
627
628
  }
628
629
  if (this.lineManager) {
629
630
  this.lineManager.onDestroy();
@@ -660,7 +661,7 @@ export class Mapbox extends MapboxCommon {
660
661
  const viewGroup = this._mapboxViewInstance.getParent();
661
662
  if (viewGroup !== null) {
662
663
  if (Trace.isEnabled()) {
663
- CLog(CLogTypes.info, 'destroy(): removing _mapboxViewInstance view.');
664
+ CLog(CLogTypes.info, 'destroy(): removing _mapboxViewInstance view.', this._mapboxViewInstance);
664
665
  }
665
666
  viewGroup.removeView(this._mapboxViewInstance);
666
667
  }
@@ -673,9 +674,6 @@ export class Mapbox extends MapboxCommon {
673
674
  this._mapboxMapInstance = null;
674
675
  }
675
676
  }
676
- async destroy(nativeMap) {
677
- this.clear();
678
- }
679
677
  // private enableUserLocationPlugin() {
680
678
  // if (!this.map) {
681
679
  // return;
@@ -794,30 +792,12 @@ export class Mapbox extends MapboxCommon {
794
792
  }
795
793
  this._mapboxViewInstance.onStart();
796
794
  }
797
- // async onResume(nativeMapViewInstance?: any) {
798
- // if (Trace.isEnabled()) {
799
- // CLog(CLogTypes.info, 'onResume()');
800
- // }
801
- // this._mapboxViewInstance.onResume();
802
- // }
803
- // async onPause(nativeMapViewInstance?: any) {
804
- // if (Trace.isEnabled()) {
805
- // CLog(CLogTypes.info, 'onPause()');
806
- // }
807
- // this._mapboxViewInstance.onPause();
808
- // }
809
795
  async onStop(nativeMap) {
810
796
  if (Trace.isEnabled()) {
811
797
  CLog(CLogTypes.info, 'onStop()');
812
798
  }
813
799
  this._mapboxViewInstance.onStop();
814
800
  }
815
- // async onLowMemory(nativeMap?: any) {
816
- // if (Trace.isEnabled()) {
817
- // CLog(CLogTypes.info, 'onLowMemory()');
818
- // }
819
- // this._mapboxViewInstance.onLowMemory();
820
- // }
821
801
  async onDestroy(nativeMap) {
822
802
  if (Trace.isEnabled()) {
823
803
  CLog(CLogTypes.info, 'onDestroy()');
@@ -2621,7 +2601,11 @@ export class Mapbox extends MapboxCommon {
2621
2601
  return 'file://' + path.join(knownFolders.currentApp().path, input.replace('~/', ''));
2622
2602
  }
2623
2603
  else {
2624
- const key = Object.keys(MapStyle)[Object.values(MapStyle).indexOf(input)];
2604
+ let key = Object.keys(MapStyle)[Object.values(MapStyle).indexOf(input)];
2605
+ // on android STREETS is defined as MAPBOX_STREETS field
2606
+ if (key === 'STREETS') {
2607
+ key = 'MAPBOX_STREETS';
2608
+ }
2625
2609
  // fix because MAPBOX_STREETS and others are not exposed by the
2626
2610
  const field = Style.class.getDeclaredField(key) || Style.class.getDeclaredField('MAPBOX_STREETS');
2627
2611
  field.setAccessible(true);
package/index.d.ts CHANGED
@@ -67,10 +67,7 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
67
67
  unhide(): Promise<void>;
68
68
  destroy(nativeMap?: any): Promise<void>;
69
69
  onStart(nativeMap?: any): Promise<void>;
70
- onResume(nativeMap?: any): Promise<void>;
71
- onPause(nativeMap?: any): Promise<void>;
72
70
  onStop(nativeMap?: any): Promise<void>;
73
- onLowMemory(nativeMap?: any): Promise<void>;
74
71
  onDestroy(nativeMap?: any): Promise<void>;
75
72
  setMapStyle(style: string | MapStyle, nativeMap?: any): Promise<void>;
76
73
  getImage(imageId: string, nativeMap?: any): Promise<ImageSource>;
package/index.ios.d.ts CHANGED
@@ -39,6 +39,7 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
39
39
  removeImage(imageId: string, nativeMap?: any): Promise<void>;
40
40
  addMarkers(markers: MapboxMarker[], nativeMap?: any): Promise<void>;
41
41
  selectedMarker: MapboxMarker;
42
+ isMarkerSelected(marker: MapboxMarker): boolean;
42
43
  deselectMarker(marker: MapboxMarker): Promise<void>;
43
44
  selectMarker(marker: MapboxMarker): Promise<void>;
44
45
  removeMarkers(ids?: any, nativeMap?: any): Promise<void>;
@@ -104,8 +105,6 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
104
105
  y: number;
105
106
  }, nativeMap?: any): LatLng;
106
107
  onStart(nativeMap?: any): Promise<void>;
107
- onResume(nativeMap?: any): Promise<void>;
108
- onPause(nativeMap?: any): Promise<void>;
109
108
  onStop(nativeMap?: any): Promise<void>;
110
109
  onLowMemory(nativeMap?: any): Promise<void>;
111
110
  onDestroy(nativeMap?: any): Promise<void>;
package/index.ios.js CHANGED
@@ -87,7 +87,7 @@ async function fetchImageIOS(imagePath) {
87
87
  if (_markerIconDownloadCache[imagePath])
88
88
  return _markerIconDownloadCache[imagePath];
89
89
  const img = await Http.getImage(imagePath);
90
- if (img && img.ios) {
90
+ if (img?.ios) {
91
91
  _markerIconDownloadCache[imagePath] = img.ios;
92
92
  return img.ios;
93
93
  }
@@ -403,7 +403,7 @@ export class Mapbox extends MapboxCommon {
403
403
  view.addSubview(nativeMap);
404
404
  this.setMapboxViewInstance(nativeMap);
405
405
  if (settings.showUserLocation) {
406
- this.showUserLocationMarker({});
406
+ this.showUserLocationMarker({ cameraMode: 'NONE' });
407
407
  }
408
408
  this.initEventHandlerShim(settings, this._mapboxViewInstance);
409
409
  if (settings.onMapReady) {
@@ -559,7 +559,7 @@ export class Mapbox extends MapboxCommon {
559
559
  return m;
560
560
  }));
561
561
  updated.forEach((m) => {
562
- if (m.icon && typeof m.icon === 'string' && m.iconDownloaded) {
562
+ if (typeof m?.icon === 'string' && m.iconDownloaded) {
563
563
  try {
564
564
  b.addImage(m.icon, m.iconDownloaded);
565
565
  delete m.iconDownloaded;
@@ -598,7 +598,8 @@ export class Mapbox extends MapboxCommon {
598
598
  _marker.lng = newSettings.lng;
599
599
  b.updateMarkerPosition(_marker.id + '', newSettings.lat, newSettings.lng);
600
600
  }
601
- if (newSettings.selected) {
601
+ if (newSettings.selected || this.isMarkerSelected(_marker)) {
602
+ // this will also update callout position
602
603
  this.selectMarker(_marker);
603
604
  }
604
605
  }
@@ -615,8 +616,11 @@ export class Mapbox extends MapboxCommon {
615
616
  }
616
617
  });
617
618
  }
619
+ isMarkerSelected(marker) {
620
+ return this.selectedMarker === marker || this.selectedMarker?.id === marker.id;
621
+ }
618
622
  async deselectMarker(marker) {
619
- if (this.selectedMarker === marker || this.selectedMarker?.id === marker.id) {
623
+ if (this.isMarkerSelected(marker)) {
620
624
  this.hideCalloutForMarkerById(marker.id + '');
621
625
  this.selectedMarker = null;
622
626
  }
@@ -627,7 +631,7 @@ export class Mapbox extends MapboxCommon {
627
631
  if (Trace.isEnabled()) {
628
632
  CLog(CLogTypes.info, 'selectMarker():', marker.id);
629
633
  }
630
- if (this.selectedMarker) {
634
+ if (this.selectedMarker && !this.isMarkerSelected(marker)) {
631
635
  this.deselectMarker(this.selectedMarker);
632
636
  }
633
637
  await this.showCalloutForMarkerById(marker.id + '');
@@ -1313,8 +1317,6 @@ export class Mapbox extends MapboxCommon {
1313
1317
  if (Trace.isEnabled()) {
1314
1318
  CLog(CLogTypes.info, 'createCalloutView1():', marker.id, marker.title, !!this._reusableCalloutView);
1315
1319
  }
1316
- this._reusableCalloutView.removeEventListener('tap');
1317
- this._reusableCalloutView.nativeViewProtected?.removeFromSuperview();
1318
1320
  return this._reusableCalloutView;
1319
1321
  }
1320
1322
  async showCalloutForMarkerById(markerId) {
@@ -1325,10 +1327,12 @@ export class Mapbox extends MapboxCommon {
1325
1327
  if (Trace.isEnabled()) {
1326
1328
  CLog(CLogTypes.info, 'showCalloutForMarkerById():', typeof markerId, markerId);
1327
1329
  }
1330
+ const callout = this.createCalloutView(m);
1328
1331
  if (this.bridgeInstance.hasViewAnnotationForMarker(markerId)) {
1329
- return;
1332
+ // let s Update
1333
+ this.bridgeInstance.removeViewAnnotationForMarker(markerId);
1334
+ // return;
1330
1335
  }
1331
- const callout = this.createCalloutView(m);
1332
1336
  callout.on('tap', () => {
1333
1337
  try {
1334
1338
  const res = m.onCalloutTap ? m.onCalloutTap(m) : undefined;
@@ -1339,6 +1343,8 @@ export class Mapbox extends MapboxCommon {
1339
1343
  console.error('callout tap handler error', e);
1340
1344
  }
1341
1345
  });
1346
+ this._reusableCalloutView.removeEventListener('tap');
1347
+ this._reusableCalloutView.nativeViewProtected?.removeFromSuperview();
1342
1348
  try {
1343
1349
  const nativeView = createUIViewAutoSizeUIViewAutoSize(callout);
1344
1350
  if (Trace.isEnabled()) {
@@ -1708,12 +1714,12 @@ export class Mapbox extends MapboxCommon {
1708
1714
  onStart(nativeMap) {
1709
1715
  return Promise.resolve();
1710
1716
  }
1711
- onResume(nativeMap) {
1712
- return Promise.resolve();
1713
- }
1714
- onPause(nativeMap) {
1715
- return Promise.resolve();
1716
- }
1717
+ // onResume(nativeMap?: any): Promise<void> {
1718
+ // return Promise.resolve();
1719
+ // }
1720
+ // onPause(nativeMap?: any): Promise<void> {
1721
+ // return Promise.resolve();
1722
+ // }
1717
1723
  onStop(nativeMap) {
1718
1724
  return Promise.resolve();
1719
1725
  }
@@ -217,8 +217,10 @@ export class MarkerManager {
217
217
  const gesturePlugin = this.mapView.getPlugin('MAPBOX_GESTURES_PLUGIN_ID');
218
218
  com.mapbox.maps.plugin.gestures.GesturesUtils.removeOnMapClickListener(this.map, this.onMapClickListener);
219
219
  this.onMapClickListener = null;
220
- com.nativescript.mapbox.ViewAnnotationManager.removeOnViewAnnotationUpdatedListener(this.mapView, this.onViewAnnotationUpdatedListener);
221
- this.onViewAnnotationUpdatedListener = null;
220
+ if (this.onViewAnnotationUpdatedListener) {
221
+ com.nativescript.mapbox.ViewAnnotationManager.removeOnViewAnnotationUpdatedListener(this.mapView, this.onViewAnnotationUpdatedListener);
222
+ this.onViewAnnotationUpdatedListener = null;
223
+ }
222
224
  if (this._reusableCalloutView) {
223
225
  this._reusableCalloutView._tearDownUI();
224
226
  this._reusableCalloutView = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript-community/ui-mapbox",
3
- "version": "7.0.3",
3
+ "version": "7.0.4",
4
4
  "description": "Interactive, thoroughly customizable maps powered by vector tiles and OpenGL.",
5
5
  "main": "index",
6
6
  "typings": "index.d.ts",
@@ -55,5 +55,5 @@
55
55
  "dependencies": {
56
56
  "@nativescript-community/perms": "^3.0.4"
57
57
  },
58
- "gitHead": "8dcec4f0ac14748e1dba5701bdc53e89bd45c135"
58
+ "gitHead": "76d122e7d75fa5889e1dcf1ff52638ad1ec67ebf"
59
59
  }
@@ -202,7 +202,7 @@ public class MapboxBridge: NSObject {
202
202
  // Register this bridge for the created MapView
203
203
  MapboxBridge.registerBridge(self, for: mv)
204
204
 
205
- addImage("default_pin", image: UIImage(named: "default_pin"))
205
+ addImage("default_pin", UIImage(named: "default_pin"))
206
206
 
207
207
  if let options = optionsOpt {
208
208
  if ((options["hideLogo"] as? Bool) == true) {
@@ -409,7 +409,7 @@ public class MapboxBridge: NSObject {
409
409
  return nil
410
410
  }
411
411
 
412
- @objc public func addImage(_ imageId: String, image: UIImage?) {
412
+ @objc public func addImage(_ imageId: String, _ image: UIImage?) {
413
413
  guard let mv = mapView else { return }
414
414
  if (image != nil) {
415
415
  imageRegistry[imageId] = image!
@@ -545,7 +545,7 @@ public class MapboxBridge: NSObject {
545
545
  annotation.allowOverlapWithPuck = true
546
546
  let image = an.image
547
547
  let imageHeight = image?.image.size.height ?? 0
548
- let offsetY = imageHeight - 12
548
+ let offsetY = imageHeight/2 + 5
549
549
  // TODO: variableAnchors is broken for now if multiple
550
550
  annotation.variableAnchors = [ViewAnnotationAnchorConfig(anchor: .bottom, offsetY: offsetY)
551
551
  // , ViewAnnotationAnchorConfig(anchor: .bottomLeft, offsetY: offsetY), ViewAnnotationAnchorConfig(anchor: .bottomRight, offsetY: offsetY)
@@ -559,6 +559,7 @@ public class MapboxBridge: NSObject {
559
559
  @objc public func updateViewAnnotationForMarker(_ markerId: String, _ lat: Double, _ lng: Double) -> Bool {
560
560
  guard mapView != nil else { return false }
561
561
  guard let view = viewAnnotationByMarkerId[markerId] else { return false }
562
+ view.view.setNeedsLayout()
562
563
  view.annotatedFeature = .geometry(Point(CLLocationCoordinate2D(latitude: lat, longitude: lng)))
563
564
  return true
564
565
  }
@@ -32,7 +32,7 @@ declare class MapboxBridge extends NSObject {
32
32
 
33
33
  setStyle(styleURIOrURL: string, completion: (success: boolean, error?: any) => void): void;
34
34
 
35
- addImage(imageId: string, image: any): void;
35
+ addImage(imageId: string, image: UIImage): void;
36
36
  removeImage(imageId: string): void;
37
37
 
38
38
  addMarkers(markers: string): void;