|
1 | | -import { Color, ContentView, ImageSource, Property, Trace, booleanConverter } from '@nativescript/core'; |
| 1 | +import { Color, ContentView, ImageSource, Property, Trace, Utils, booleanConverter } from '@nativescript/core'; |
2 | 2 |
|
3 | 3 | export * from './geo.utils'; |
4 | 4 | export * from './expression/expression-parser'; |
@@ -712,7 +712,7 @@ export interface MapboxApi { |
712 | 712 |
|
713 | 713 | getImage(imageId: string, nativeMap?: any): Promise<ImageSource>; |
714 | 714 |
|
715 | | - addImage(imageId: string, image: string, nativeMap?: any): Promise<void>; |
| 715 | + addImage(imageId: string, imagePath: string, nativeMap?: any): Promise<void>; |
716 | 716 |
|
717 | 717 | removeImage(imageId: string, nativeMap?: any): Promise<void>; |
718 | 718 | project(data: LatLng): { x: number; y: number }; |
@@ -773,6 +773,17 @@ export abstract class MapboxCommon implements MapboxCommonApi { |
773 | 773 | async hasFineLocationPermission() { |
774 | 774 | return true; |
775 | 775 | } |
| 776 | + |
| 777 | + protected async fetchImageSource(imagePath: string): Promise<ImageSource> { |
| 778 | + if (Utils.isDataURI(imagePath)) { |
| 779 | + const [, base64] = imagePath.split(';base64,'); |
| 780 | + return ImageSource.fromBase64Sync(base64); |
| 781 | + } |
| 782 | + if (Utils.isFileOrResourcePath(imagePath)) { |
| 783 | + return ImageSource.fromFileOrResourceSync(imagePath); |
| 784 | + } |
| 785 | + return ImageSource.fromUrl(imagePath); |
| 786 | + } |
776 | 787 | } |
777 | 788 |
|
778 | 789 | // ------------------------------------------------------------ |
@@ -872,7 +883,7 @@ export interface MapboxViewApi { |
872 | 883 |
|
873 | 884 | getImage(imageId: string, nativeMap?: any): Promise<ImageSource>; |
874 | 885 |
|
875 | | - addImage(imageId: string, image: string, nativeMap?: any): Promise<void>; |
| 886 | + addImage(imageId: string, imagePath: string, nativeMap?: any): Promise<void>; |
876 | 887 |
|
877 | 888 | removeImage(imageId: string, nativeMap?: any): Promise<void>; |
878 | 889 |
|
@@ -1060,8 +1071,8 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox |
1060 | 1071 | getImage(imageId: string): Promise<ImageSource> { |
1061 | 1072 | return this.mapbox.getImage(imageId, this.getNativeMapView()); |
1062 | 1073 | } |
1063 | | - addImage(imageId: string, image: string): Promise<void> { |
1064 | | - return this.mapbox.addImage(imageId, image, this.getNativeMapView()); |
| 1074 | + addImage(imageId: string, imagePath: string): Promise<void> { |
| 1075 | + return this.mapbox.addImage(imageId, imagePath, this.getNativeMapView()); |
1065 | 1076 | } |
1066 | 1077 | removeImage(imageId: string): Promise<void> { |
1067 | 1078 | return this.mapbox.removeImage(imageId, this.getNativeMapView()); |
|
0 commit comments