55 */
66
77import { request } from '@nativescript-community/perms' ;
8- import { AndroidApplication , Application , Color , File , Trace , Utils , knownFolders , path , ImageSource , Image } from '@nativescript/core' ;
8+ import { AndroidApplication , Application , Color , File , Image , ImageSource , Trace , Utils , knownFolders , path } from '@nativescript/core' ;
99import { getImage } from '@nativescript/core/http' ;
1010import { FilterParser } from './filter/filter-parser.android' ;
1111import { GeoUtils } from './geo.utils' ;
@@ -100,7 +100,6 @@ export class MapboxView extends MapboxViewBase {
100100 }
101101 }
102102
103-
104103 /**
105104 * programmatically include settings
106105 */
@@ -347,7 +346,6 @@ export class MapboxView extends MapboxViewBase {
347346 }
348347}
349348
350-
351349/**
352350 * A NativeScript shim for the Mapbox API.
353351 *
@@ -1118,7 +1116,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
11181116
11191117 const builder = new com . mapbox . mapboxsdk . maps . Style . Builder ( ) ;
11201118 this . _mapboxMapInstance . setStyle ( builder . fromUri ( mapStyle ) ) ;
1121-
11221119 } catch ( ex ) {
11231120 if ( Trace . isEnabled ( ) ) {
11241121 CLog ( CLogTypes . error , 'Error in mapbox.setMapStyle' , style , ex ) ;
@@ -1131,7 +1128,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
11311128 async getImage ( imageId : string , nativeMap ?: any ) : Promise < ImageSource > {
11321129 return new Promise ( ( resolve , reject ) => {
11331130 const theMap = nativeMap || this . _mapboxMapInstance ;
1134-
1131+
11351132 if ( ! theMap ) {
11361133 reject ( 'No map has been loaded' ) ;
11371134 return ;
@@ -1141,51 +1138,51 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
11411138 const nativeImage = theMap . getStyle ( ) . getImage ( imageId ) ;
11421139 const img = new ImageSource ( nativeImage ) ;
11431140
1144- resolve ( img ) ;
1141+ resolve ( img ) ;
11451142 } catch ( ex ) {
1146- reject ( " Error during getImage: " + ex ) ;
1143+ reject ( ' Error during getImage: ' + ex ) ;
11471144
11481145 if ( Trace . isEnabled ( ) ) {
11491146 CLog ( CLogTypes . info , 'Error in mapbox.getImage: ' + ex ) ;
11501147 }
11511148 throw ex ;
1152- }
1149+ }
11531150 } ) ;
11541151 }
11551152
11561153 async addImage ( imageId : string , image : string , nativeMap ?: any ) : Promise < void > {
11571154 return new Promise ( ( resolve , reject ) => {
11581155 const theMap = nativeMap || this . _mapboxMapInstance ;
1159-
1156+
11601157 if ( ! theMap ) {
11611158 reject ( 'No map has been loaded' ) ;
11621159 return ;
11631160 }
11641161
1165- if ( ! image . startsWith ( " res://" ) ) {
1162+ if ( ! image . startsWith ( ' res://' ) ) {
11661163 image = path . join ( knownFolders . currentApp ( ) . path , image . replace ( '~/' , '' ) ) ;
11671164 }
1168-
1165+
11691166 const img = ImageSource . fromFileOrResourceSync ( image ) ;
11701167
11711168 try {
11721169 theMap . getStyle ( ) . addImage ( imageId , img . android ) ;
11731170 resolve ( ) ;
11741171 } catch ( ex ) {
1175- reject ( " Error during addImage: " + ex ) ;
1172+ reject ( ' Error during addImage: ' + ex ) ;
11761173
11771174 if ( Trace . isEnabled ( ) ) {
11781175 CLog ( CLogTypes . info , 'Error in mapbox.addImage: ' + ex ) ;
11791176 }
11801177 throw ex ;
1181- }
1178+ }
11821179 } ) ;
11831180 }
11841181
11851182 async removeImage ( imageId : string , nativeMap ?: any ) : Promise < void > {
11861183 return new Promise ( ( resolve , reject ) => {
11871184 const theMap = nativeMap || this . _mapboxMapInstance ;
1188-
1185+
11891186 if ( ! theMap ) {
11901187 reject ( 'No map has been loaded' ) ;
11911188 return ;
@@ -1195,13 +1192,13 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
11951192 theMap . getStyle ( ) . removeImage ( imageId ) ;
11961193 resolve ( ) ;
11971194 } catch ( ex ) {
1198- reject ( " Error during removeImage: " + ex ) ;
1195+ reject ( ' Error during removeImage: ' + ex ) ;
11991196
12001197 if ( Trace . isEnabled ( ) ) {
12011198 CLog ( CLogTypes . info , 'Error in mapbox.removeImage: ' + ex ) ;
12021199 }
12031200 throw ex ;
1204- }
1201+ }
12051202 } ) ;
12061203 }
12071204
@@ -1233,7 +1230,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
12331230 * @deprecated
12341231 * @link https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation
12351232 */
1236-
12371233 _addMarkers ( markers : MapboxMarker [ ] , nativeMap ?) {
12381234 if ( ! markers ) {
12391235 if ( Trace . isEnabled ( ) ) {
@@ -1399,7 +1395,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
13991395 }
14001396 }
14011397
1402-
14031398 setCenter ( options : SetCenterOptions , nativeMap ?) : Promise < void > {
14041399 return new Promise ( ( resolve , reject ) => {
14051400 try {
@@ -2407,8 +2402,11 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
24072402 }
24082403
24092404 const geoJsonSource = new com . mapbox . mapboxsdk . style . sources . GeoJsonSource ( id , geojsonOptions ) ;
2410- const geoJsonString = JSON . stringify ( options . data ) ;
2411- geoJsonSource . setGeoJson ( geoJsonString ) ;
2405+ if ( options . data ) {
2406+ const geoJsonString = JSON . stringify ( options . data ) ;
2407+ geoJsonSource . setGeoJson ( geoJsonString ) ;
2408+ }
2409+
24122410 source = geoJsonSource ;
24132411
24142412 break ;
@@ -2436,7 +2434,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
24362434 tileSet . setBounds ( options . bounds . map ( ( val ) => new java . lang . Float ( val ) ) ) ;
24372435 }
24382436
2439- source = new com . mapbox . mapboxsdk . style . sources . RasterSource ( id , tileSet , options . tileSize ) ;
2437+ source = new com . mapbox . mapboxsdk . style . sources . RasterSource ( id , tileSet , options . tileSize || 256 ) ;
24402438 break ;
24412439 default :
24422440 reject ( 'Invalid source type: ' + options [ 'type' ] ) ;
@@ -2478,7 +2476,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
24782476
24792477 const isRemoved = theMap . getStyle ( ) . removeSource ( id ) ;
24802478 if ( ! isRemoved ) {
2481- reject ( `Could not remove source with id: ${ id } ` )
2479+ reject ( `Could not remove source with id: ${ id } ` ) ;
24822480 }
24832481
24842482 resolve ( ) ;
@@ -2565,17 +2563,17 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
25652563 try {
25662564 const sId = ! ! sourceId ? sourceId : id + '_source' ;
25672565 const lineSource = this . _mapboxMapInstance . getStyle ( ) . getSource ( sId ) as com . mapbox . mapboxsdk . style . sources . GeoJsonSource ;
2568-
2566+
25692567 if ( ! lineSource ) {
25702568 throw new Error ( `no source found with id: ${ sId } ` ) ;
25712569 }
25722570
25732571 const lineFeatures = lineSource . querySourceFeatures ( FilterParser . parseJson ( [ '==' , '$type' , 'LineString' ] ) ) ;
2574-
2572+
25752573 if ( lineFeatures . size ( ) === 0 ) {
2576- throw new Error ( " no line string feature found" ) ;
2574+ throw new Error ( ' no line string feature found' ) ;
25772575 }
2578-
2576+
25792577 const feature = lineFeatures . get ( 0 ) ;
25802578
25812579 const newPoints = new java . util . ArrayList < com . mapbox . geojson . Point > ( feature . geometry ( ) . coordinates ( ) ) ;
@@ -2788,7 +2786,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
27882786 }
27892787
27902788 return mapboxMapOptions ;
2791- }
2789+ }
27922790
27932791 /**
27942792 * convert string to camera mode constant.
@@ -3006,7 +3004,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
30063004 reject ( ex ) ;
30073005 }
30083006 } ) ;
3009- }
3007+ }
30103008
30113009 /**
30123010 * hide (destroy) the user location marker
@@ -3089,7 +3087,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
30893087 } ) ;
30903088 }
30913089
3092-
30933090 /**
30943091 * force updating of user location
30953092 *
0 commit comments