@@ -389,6 +389,8 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
389
389
private onCameraIdleListener ;
390
390
private onLocationClickListener ;
391
391
392
+ private iconFactory ;
393
+
392
394
private _markers = [ ] ;
393
395
private _polylines = [ ] ;
394
396
private _polygons = [ ] ;
@@ -688,7 +690,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
688
690
destroy ( nativeMap ?: any ) : Promise < void > {
689
691
return new Promise ( async ( resolve , reject ) => {
690
692
this . clearEventListeners ( ) ;
691
-
693
+ this . iconFactory = null ;
692
694
if ( Trace . isEnabled ( ) ) {
693
695
CLog ( CLogTypes . info , 'destroy(): destroying mapbox view.' ) ;
694
696
}
@@ -1267,13 +1269,19 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
1267
1269
if ( marker . icon ) {
1268
1270
// for markers from url see UrlMarker in https://github.com/mapbox/mapbox-gl-native/issues/5370
1269
1271
if ( marker . icon . startsWith ( 'res://' ) ) {
1270
- const resourcename = marker . icon . substring ( 6 ) ;
1271
- const res = Utils . ad . getApplicationContext ( ) . getResources ( ) ;
1272
- const identifier = res . getIdentifier ( resourcename , 'drawable' , Utils . ad . getApplication ( ) . getPackageName ( ) ) ;
1273
- if ( identifier === 0 ) {
1274
- console . log ( `No icon found for this device density for icon ' ${ marker . icon } '. Falling back to the default icon.` ) ;
1272
+ let cached = this . iconCache [ marker . iconPath ] ;
1273
+ if ( ! cached ) {
1274
+ const resourcename = marker . icon . substring ( 6 ) ;
1275
+ const res = Utils . ad . getApplicationContext ( ) . getResources ( ) ;
1276
+ const identifier = res . getIdentifier ( resourcename , 'drawable' , Utils . ad . getApplication ( ) . getPackageName ( ) ) ;
1277
+ if ( identifier !== 0 ) {
1278
+ cached = this . iconCache [ marker . iconPath ] = iconFactory . fromResource ( identifier ) ;
1279
+ }
1280
+ }
1281
+ if ( cached ) {
1282
+ markerOptions . setIcon ( cached ) ;
1275
1283
} else {
1276
- markerOptions . setIcon ( iconFactory . fromResource ( identifier ) ) ;
1284
+ console . log ( `No icon found for this device density for icon ' ${ marker . icon } '. Falling back to the default icon.` ) ;
1277
1285
}
1278
1286
} else if ( marker . icon . startsWith ( 'http' ) ) {
1279
1287
if ( marker . iconDownloaded !== null ) {
@@ -1285,13 +1293,19 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
1285
1293
}
1286
1294
}
1287
1295
} else if ( marker . iconPath ) {
1288
- const iconFullPath = path . join ( knownFolders . currentApp ( ) . path , marker . iconPath . replace ( '~/' , '' ) ) ;
1289
- // if the file doesn't exist the app will crash, so checking it
1290
- if ( File . exists ( iconFullPath ) ) {
1291
- // could set width, height, retina, see https://github.com/Telerik-Verified-Plugins/Mapbox/pull/42/files?diff=unified&short_path=1c65267, but that's what the marker.icon param is for..
1292
- markerOptions . setIcon ( iconFactory . fromPath ( iconFullPath ) ) ;
1296
+ let cached = this . iconCache [ marker . iconPath ] ;
1297
+ if ( ! cached ) {
1298
+ const iconFullPath = path . join ( knownFolders . currentApp ( ) . path , marker . iconPath . replace ( '~/' , '' ) ) ;
1299
+ // if the file doesn't exist the app will crash, so checking it
1300
+ if ( File . exists ( iconFullPath ) ) {
1301
+ // could set width, height, retina, see https://github.com/Telerik-Verified-Plugins/Mapbox/pull/42/files?diff=unified&short_path=1c65267, but that's what the marker.icon param is for..
1302
+ cached = this . iconCache [ marker . iconPath ] = iconFactory . fromPath ( iconFullPath ) ;
1303
+ }
1304
+ }
1305
+ if ( cached ) {
1306
+ markerOptions . setIcon ( cached ) ;
1293
1307
} else {
1294
- console . log ( `Marker icon not found, using the default instead. Requested full path: '" + ${ iconFullPath } '.` ) ;
1308
+ console . log ( `Marker icon not found, using the default instead. Requested path: '" + ${ marker . iconPath } '.` ) ;
1295
1309
}
1296
1310
}
1297
1311
marker . android = this . _mapboxMapInstance . addMarker ( markerOptions ) ;
0 commit comments