5
5
*/
6
6
7
7
import { request } from '@nativescript-community/perms' ;
8
- import { AndroidApplication , Application , Color , File , Trace , Utils , knownFolders } from '@nativescript/core' ;
8
+ import { AndroidApplication , Application , Color , File , Trace , Utils , knownFolders , path } from '@nativescript/core' ;
9
9
import { AndroidActivityBundleEventData , AndroidActivityEventData } from '@nativescript/core/application/application-interfaces' ;
10
10
import { getImage } from '@nativescript/core/http' ;
11
11
import { GeoUtils } from './geo.utils' ;
@@ -796,15 +796,15 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
796
796
797
797
const showIt = ( ) => {
798
798
if ( Trace . isEnabled ( ) ) {
799
- CLog ( CLogTypes . info , 'show(): showit() top ' ) ;
799
+ CLog ( CLogTypes . info , 'show()' ) ;
800
800
}
801
801
802
802
// if no accessToken was set the app may crash.
803
803
//
804
804
// FIXME: Even if using a local server add some string.
805
805
806
806
if ( settings . accessToken === undefined ) {
807
- reject ( "Please set the 'accessToken' parameter" ) ;
807
+ reject ( 'mapbox_accesstoken_missing' ) ;
808
808
return ;
809
809
}
810
810
@@ -833,10 +833,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
833
833
context = settings . context ;
834
834
}
835
835
836
- if ( Trace . isEnabled ( ) ) {
837
- CLog ( CLogTypes . info , 'show(): before getInstance()' ) ;
838
- }
839
-
840
836
// Per the Mapbox Android Native samples:
841
837
//
842
838
// "Mapbox access token is configured here. This needs to be called either in your application
@@ -859,34 +855,24 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
859
855
// define some listeners to inform in case the map does not
860
856
// load.
861
857
862
- this . onDidFailLoadingMapListener = new com . mapbox . mapboxsdk . maps . MapView . OnDidFailLoadingMapListener ( {
863
- onDidFailLoadingMap : ( error ) => {
864
- console . error ( 'Mapbox::show(): failed to load map:' , error ) ;
865
- } ,
866
- } ) ;
867
-
868
858
if ( Trace . isEnabled ( ) ) {
869
- CLog ( CLogTypes . info , 'show(): about on add onDidFailLoadingMapListener:' , this . onDidFailLoadingMapListener ) ;
859
+ this . onDidFailLoadingMapListener = new com . mapbox . mapboxsdk . maps . MapView . OnDidFailLoadingMapListener ( {
860
+ onDidFailLoadingMap : ( error ) => CLog ( CLogTypes . error , 'Mapbox::show(): failed to load map:' , error ) ,
861
+ } ) ;
862
+ this . _mapboxViewInstance . addOnDidFailLoadingMapListener ( this . onDidFailLoadingMapListener ) ;
870
863
}
871
864
872
- this . _mapboxViewInstance . addOnDidFailLoadingMapListener ( this . onDidFailLoadingMapListener ) ;
873
-
874
865
// this.gcFix('com.mapbox.mapboxsdk.maps.MapView.OnDidFailLoadingMapListener', this.onDidFailLoadingMapListener);
875
866
876
867
if ( Trace . isEnabled ( ) ) {
877
868
this . onDidFinishLoadingMapListener = new com . mapbox . mapboxsdk . maps . MapView . OnDidFinishLoadingMapListener ( {
878
869
onDidFinishLoadingMap : ( ) => CLog ( CLogTypes . info , 'show(): finished loading map' ) ,
879
870
} ) ;
871
+ this . _mapboxViewInstance . addOnDidFinishLoadingMapListener ( this . onDidFinishLoadingMapListener ) ;
880
872
}
881
873
882
- this . _mapboxViewInstance . addOnDidFinishLoadingMapListener ( this . onDidFinishLoadingMapListener ) ;
883
-
884
874
// this.gcFix('com.mapbox.mapboxsdk.maps.MapView.OnDidFinishLoadingMapListener', this.onDidFinishLoadingMapListener);
885
875
886
- if ( Trace . isEnabled ( ) ) {
887
- CLog ( CLogTypes . info , 'show(): after adding fail listener()' ) ;
888
- }
889
-
890
876
this . onMapReadyCallback = new com . mapbox . mapboxsdk . maps . OnMapReadyCallback ( {
891
877
onMapReady : ( mbMap ) => {
892
878
this . _mapboxMapInstance = mbMap ;
@@ -899,10 +885,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
899
885
// is initialized. We do not consider the map ready until the style has successfully
900
886
// loaded.
901
887
902
- if ( Trace . isEnabled ( ) ) {
903
- CLog ( CLogTypes . info , "Mapbox::show(): attempting to set style '" + settings . style ) ;
904
- }
905
-
906
888
this . setMapStyle ( settings . style ) . then ( ( style ) => {
907
889
if ( Trace . isEnabled ( ) ) {
908
890
CLog ( CLogTypes . info , 'show(): style loaded.' ) ;
@@ -1709,7 +1691,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
1709
1691
}
1710
1692
1711
1693
// callback for when the style is successfully loaded.
1712
-
1713
1694
this . onDidFinishLoadingStyleListener = new com . mapbox . mapboxsdk . maps . MapView . OnDidFinishLoadingStyleListener ( {
1714
1695
onDidFinishLoadingStyle : ( ) => {
1715
1696
if ( Trace . isEnabled ( ) ) {
@@ -1743,7 +1724,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
1743
1724
// this.gcFix('com.mapbox.mapboxsdk.plugins.annotation.OnAnnotationClickListener', this.onAnnotationClickListener);
1744
1725
1745
1726
resolve ( ) ;
1746
- } ,
1727
+ }
1747
1728
} ) ;
1748
1729
1749
1730
this . _mapboxViewInstance . addOnDidFinishLoadingStyleListener ( this . onDidFinishLoadingStyleListener ) ;
@@ -1755,30 +1736,26 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
1755
1736
this . onDidFailLoadingMapListener = new com . mapbox . mapboxsdk . maps . MapView . OnDidFailLoadingMapListener ( {
1756
1737
onDidFailLoadingMap : ( error ) => {
1757
1738
if ( Trace . isEnabled ( ) ) {
1758
- CLog ( CLogTypes . info , 'Mapbox:setMapStyle(): style failed' ) ;
1739
+ CLog ( CLogTypes . error , 'Mapbox:setMapStyle(): style failed' , mapStyle , error ) ;
1759
1740
}
1760
1741
reject ( error ) ;
1761
1742
} ,
1762
1743
} ) ;
1763
1744
1764
- if ( Trace . isEnabled ( ) ) {
1765
- CLog ( CLogTypes . info , 'setMapStyle(): before onDidFailLoadingMapListener' ) ;
1766
- }
1767
-
1768
1745
this . _mapboxViewInstance . addOnDidFailLoadingMapListener ( this . onDidFailLoadingMapListener ) ;
1769
1746
1770
1747
// this.gcFix('com.mapbox.mapboxsdk.maps.MapView.OnDidFailLoadingMapListener', this.onDidFailLoadingMapListener);
1771
1748
1772
1749
const builder = new com . mapbox . mapboxsdk . maps . Style . Builder ( ) ;
1773
1750
1774
- this . _mapboxMapInstance . setStyle ( builder . fromUrl ( mapStyle ) ) ;
1751
+ this . _mapboxMapInstance . setStyle ( builder . fromUri ( mapStyle ) ) ;
1775
1752
1776
1753
// FIXME: probably not necessary.
1777
1754
1778
1755
// this.gcFix('com.mapbox.mapboxsdk.maps.Style.Builder', builder);
1779
1756
} catch ( ex ) {
1780
1757
if ( Trace . isEnabled ( ) ) {
1781
- CLog ( CLogTypes . info , 'Error in mapbox.setMapStyle: ' + ex ) ;
1758
+ CLog ( CLogTypes . error , 'Error in mapbox.setMapStyle' , style , ex ) ;
1782
1759
}
1783
1760
reject ( ex ) ;
1784
1761
}
@@ -1787,34 +1764,28 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
1787
1764
1788
1765
// ------------------------------------------------------------------------------
1789
1766
1790
- addMarkers ( markers : MapboxMarker [ ] , nativeMap ?: any ) : Promise < void > {
1791
- return new Promise ( ( resolve , reject ) => {
1792
- try {
1793
- this . _addMarkers ( markers , this . _mapboxViewInstance ) ;
1794
- resolve ( ) ;
1795
- } catch ( ex ) {
1796
- if ( Trace . isEnabled ( ) ) {
1797
- CLog ( CLogTypes . info , 'Error in mapbox.addMarkers: ' + ex ) ;
1798
- }
1799
- reject ( ex ) ;
1767
+ async addMarkers ( markers : MapboxMarker [ ] , nativeMap ?: any ) {
1768
+ try {
1769
+ this . _addMarkers ( markers , this . _mapboxViewInstance ) ;
1770
+ } catch ( ex ) {
1771
+ if ( Trace . isEnabled ( ) ) {
1772
+ CLog ( CLogTypes . info , 'Error in mapbox.addMarkers: ' + ex ) ;
1800
1773
}
1801
- } ) ;
1774
+ throw ( ex ) ;
1775
+ }
1802
1776
}
1803
1777
1804
1778
// ----------------------------------------------------------------------------------
1805
1779
1806
- removeMarkers ( ids ?: any , nativeMap ?: any ) : Promise < void > {
1807
- return new Promise ( ( resolve , reject ) => {
1808
- try {
1809
- this . _removeMarkers ( ids , this . _mapboxViewInstance ) ;
1810
- resolve ( ) ;
1811
- } catch ( ex ) {
1812
- if ( Trace . isEnabled ( ) ) {
1813
- CLog ( CLogTypes . info , 'Error in mapbox.removeMarkers: ' + ex ) ;
1814
- }
1815
- reject ( ex ) ;
1780
+ async removeMarkers ( ids ?: any , nativeMap ?: any ) {
1781
+ try {
1782
+ this . _removeMarkers ( ids , this . _mapboxViewInstance ) ;
1783
+ } catch ( ex ) {
1784
+ if ( Trace . isEnabled ( ) ) {
1785
+ CLog ( CLogTypes . info , 'Error in mapbox.removeMarkers: ' + ex ) ;
1816
1786
}
1817
- } ) ;
1787
+ throw ( ex ) ;
1788
+ }
1818
1789
}
1819
1790
1820
1791
// --------------------------------------------------------------------------------------------
@@ -3858,31 +3829,25 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
3858
3829
3859
3830
const Style = com . mapbox . mapboxsdk . maps . Style ;
3860
3831
3861
- if ( Trace . isEnabled ( ) ) {
3862
- CLog ( CLogTypes . info , '_getMapStyle(): Style object is:' , Style ) ;
3863
- }
3864
-
3865
3832
// allow for a style URL to be passed
3866
3833
3867
- if ( / ^ m a p b o x : \/ \/ s t y l e s / . test ( input ) || / ^ h t t p : \/ \/ / . test ( input ) || / ^ h t t p s : \/ \/ / . test ( input ) ) {
3868
- return input ;
3869
- } else if ( / ^ ~ \/ / . test ( input ) ) {
3870
- const assetsPath = 'asset://app/' ;
3871
- input = input . replace ( / ^ ~ \/ / , assetsPath ) ;
3834
+ if ( input . startsWith ( 'mapbox://styles' ) || input . startsWith ( 'http://' ) || input . startsWith ( 'https://' ) ) {
3872
3835
return input ;
3873
- } else if ( input === MapStyle . LIGHT || input === MapStyle . LIGHT . toString ( ) ) {
3836
+ } else if ( input . startsWith ( '~/' ) ) {
3837
+ return 'file://' + path . join ( knownFolders . currentApp ( ) . path , input . replace ( '~/' , '' ) ) ;
3838
+ } else if ( input === MapStyle . LIGHT ) {
3874
3839
return Style . LIGHT ;
3875
- } else if ( input === MapStyle . DARK || input === MapStyle . DARK . toString ( ) ) {
3840
+ } else if ( input === MapStyle . DARK ) {
3876
3841
return Style . DARK ;
3877
- } else if ( input === MapStyle . OUTDOORS || input === MapStyle . OUTDOORS . toString ( ) ) {
3842
+ } else if ( input === MapStyle . OUTDOORS ) {
3878
3843
return Style . OUTDOORS ;
3879
- } else if ( input === MapStyle . SATELLITE || input === MapStyle . SATELLITE . toString ( ) ) {
3844
+ } else if ( input === MapStyle . SATELLITE ) {
3880
3845
return Style . SATELLITE ;
3881
- } else if ( input === MapStyle . SATELLITE_STREETS || input === MapStyle . SATELLITE_STREETS . toString ( ) ) {
3846
+ } else if ( input === MapStyle . SATELLITE_STREETS ) {
3882
3847
return Style . SATELLITE_STREETS ;
3883
- } else if ( input === MapStyle . TRAFFIC_DAY || input === MapStyle . TRAFFIC_DAY . toString ( ) ) {
3848
+ } else if ( input === MapStyle . TRAFFIC_DAY ) {
3884
3849
return Style . TRAFFIC_DAY ;
3885
- } else if ( input === MapStyle . TRAFFIC_NIGHT || input === MapStyle . TRAFFIC_NIGHT . toString ( ) ) {
3850
+ } else if ( input === MapStyle . TRAFFIC_NIGHT ) {
3886
3851
return Style . TRAFFIC_NIGHT ;
3887
3852
} else {
3888
3853
// default
@@ -4041,7 +4006,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
4041
4006
return new Promise ( ( resolve , reject ) => {
4042
4007
try {
4043
4008
if ( Trace . isEnabled ( ) ) {
4044
- CLog ( CLogTypes . info , 'showUserLocationMarker(): top ' ) ;
4009
+ CLog ( CLogTypes . info , 'showUserLocationMarker()' ) ;
4045
4010
}
4046
4011
4047
4012
if ( ! this . _mapboxMapInstance ) {
@@ -4074,21 +4039,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
4074
4039
4075
4040
const componentOptions = componentOptionsBuilder . build ( ) ;
4076
4041
4077
- if ( Trace . isEnabled ( ) ) {
4078
- CLog ( CLogTypes . info , 'showUserLocationMarker(): after componentOptions.build()' ) ;
4079
- }
4080
4042
4081
4043
this . _locationComponent = this . _mapboxMapInstance . getLocationComponent ( ) ;
4082
4044
4083
- if ( Trace . isEnabled ( ) ) {
4084
- CLog ( CLogTypes . info , 'showUserLocationMarker(): after getLocationComponent' ) ;
4085
- }
4086
4045
4087
4046
const activationOptionsBuilder = com . mapbox . mapboxsdk . location . LocationComponentActivationOptions . builder ( Application . android . context , this . _mapboxMapInstance . getStyle ( ) ) ;
4088
4047
4089
- if ( Trace . isEnabled ( ) ) {
4090
- CLog ( CLogTypes . info , 'showUserLocationMarker(): after activationOptionsBuilder' ) ;
4091
- }
4092
4048
4093
4049
activationOptionsBuilder . locationComponentOptions ( componentOptions ) ;
4094
4050
@@ -4097,23 +4053,11 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
4097
4053
if ( typeof options . useDefaultLocationEngine != 'undefined' ) {
4098
4054
useDefaultEngine = options . useDefaultLocationEngine ;
4099
4055
}
4100
-
4101
- if ( Trace . isEnabled ( ) ) {
4102
- CLog ( CLogTypes . info , 'showUserLocationMarker(): before useDefaultEngine' ) ;
4103
- }
4104
-
4105
4056
activationOptionsBuilder . useDefaultLocationEngine ( useDefaultEngine ) ;
4106
4057
4107
- if ( Trace . isEnabled ( ) ) {
4108
- CLog ( CLogTypes . info , 'showUserLocationMarker(): after useDefaultEngine' ) ;
4109
- }
4110
4058
4111
4059
const locationComponentActivationOptions = activationOptionsBuilder . build ( ) ;
4112
4060
4113
- if ( Trace . isEnabled ( ) ) {
4114
- CLog ( CLogTypes . info , 'showUserLocationMarker(): after ActivationOptions' ) ;
4115
- }
4116
-
4117
4061
this . _locationComponent . activateLocationComponent ( locationComponentActivationOptions ) ;
4118
4062
this . _locationComponent . setLocationComponentEnabled ( true ) ;
4119
4063
0 commit comments