5
5
*/
6
6
7
7
import { request } from '@nativescript-community/perms' ;
8
- import { AndroidApplication , Application , Color , File , Trace , Utils , knownFolders , path , ImageSource } from '@nativescript/core' ;
8
+ import { AndroidApplication , Application , Color , File , Trace , Utils , knownFolders , path , ImageSource , Image } from '@nativescript/core' ;
9
9
import { getImage } from '@nativescript/core/http' ;
10
10
import { FilterParser } from './filter/filter-parser.android' ;
11
11
import { GeoUtils } from './geo.utils' ;
@@ -1100,6 +1100,31 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
1100
1100
} ) ;
1101
1101
}
1102
1102
1103
+ async getImage ( imageId : string , nativeMap ?: any ) : Promise < ImageSource > {
1104
+ return new Promise ( ( resolve , reject ) => {
1105
+ const theMap = nativeMap || this . _mapboxMapInstance ;
1106
+
1107
+ if ( ! theMap ) {
1108
+ reject ( 'No map has been loaded' ) ;
1109
+ return ;
1110
+ }
1111
+
1112
+ try {
1113
+ const nativeImage = theMap . getStyle ( ) . getImage ( imageId ) ;
1114
+ const img = new ImageSource ( nativeImage ) ;
1115
+
1116
+ resolve ( img ) ;
1117
+ } catch ( ex ) {
1118
+ reject ( "Error during getImage: " + ex ) ;
1119
+
1120
+ if ( Trace . isEnabled ( ) ) {
1121
+ CLog ( CLogTypes . info , 'Error in mapbox.getImage: ' + ex ) ;
1122
+ }
1123
+ throw ex ;
1124
+ }
1125
+ } ) ;
1126
+ }
1127
+
1103
1128
async addImage ( imageId : string , image : string , nativeMap ?: any ) : Promise < void > {
1104
1129
return new Promise ( ( resolve , reject ) => {
1105
1130
const theMap = nativeMap || this . _mapboxMapInstance ;
@@ -1125,8 +1150,30 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
1125
1150
CLog ( CLogTypes . info , 'Error in mapbox.addImage: ' + ex ) ;
1126
1151
}
1127
1152
throw ex ;
1128
- }
1153
+ }
1154
+ } ) ;
1155
+ }
1156
+
1157
+ async removeImage ( imageId : string , nativeMap ?: any ) : Promise < void > {
1158
+ return new Promise ( ( resolve , reject ) => {
1159
+ const theMap = nativeMap || this . _mapboxMapInstance ;
1129
1160
1161
+ if ( ! theMap ) {
1162
+ reject ( 'No map has been loaded' ) ;
1163
+ return ;
1164
+ }
1165
+
1166
+ try {
1167
+ theMap . getStyle ( ) . removeImage ( imageId ) ;
1168
+ resolve ( ) ;
1169
+ } catch ( ex ) {
1170
+ reject ( "Error during removeImage: " + ex ) ;
1171
+
1172
+ if ( Trace . isEnabled ( ) ) {
1173
+ CLog ( CLogTypes . info , 'Error in mapbox.removeImage: ' + ex ) ;
1174
+ }
1175
+ throw ex ;
1176
+ }
1130
1177
} ) ;
1131
1178
}
1132
1179
0 commit comments