33using Newtonsoft . Json ;
44using Xamarin . Forms ;
55using System . Linq ;
6+ using System . Collections . Generic ;
67
78namespace MapBoxQs
89{
910 public partial class MapBoxQsPage : ContentPage
1011 {
12+
13+ public MapBoxQs . Services . IMapBoxService _MBService = new MapBoxQs . Services . MapBoxService ( ) ;
14+ MainPageViewModel _ViewModel = new MainPageViewModel ( ) ;
1115 public MapBoxQsPage ( )
1216 {
1317 InitializeComponent ( ) ;
@@ -29,10 +33,6 @@ public MapBoxQsPage()
2933 map . Center = positions [ random . Next ( 2 ) % 2 ] ;
3034 } ;
3135
32- map . DidFinishLoadingStyleCommand = new Command < MapStyle > ( ( MapStyle obj ) =>
33- {
34- map . ResetPositionFunc . Execute ( null ) ;
35- } ) ;
3636
3737 map . DidTapOnMapCommand = new Command < Tuple < Position , Point > > ( ( Tuple < Position , Point > obj ) =>
3838 {
@@ -46,16 +46,67 @@ public MapBoxQsPage()
4646 } ) ;
4747 map . DidFinishLoadingStyleCommand = new Command < MapStyle > ( ( obj ) =>
4848 {
49+ map . ResetPositionFunc . Execute ( null ) ;
4950 foreach ( Layer layer in obj . OriginalLayers )
5051 {
5152 System . Diagnostics . Debug . WriteLine ( layer . Id ) ;
5253 }
53- } ) ;
54+
55+ } ) ;
56+ map . ZoomLevel = Device . RuntimePlatform == Device . Android ? 4 : 10 ;
57+
58+
59+ BindingContext = _ViewModel ;
60+ }
61+
62+ protected override void OnAppearing ( )
63+ {
64+ base . OnAppearing ( ) ;
65+ GetAllStyles ( ) ;
66+ }
67+
68+ async void ShowStylesPicker ( object sender , EventArgs args )
69+ {
70+ if ( _Styles == null || _Styles . Length == 0 ) {
71+ await DisplayAlert ( "Error" , "No style available" , "Dismiss" ) ;
72+ return ;
73+ }
74+ var buttons = _Styles . Select ( ( arg ) => arg . Name ) . ToArray ( ) ;
75+
76+ var result = await DisplayActionSheet ( "Change style" , "Cancel" , null , buttons ) ;
77+ if ( ! string . IsNullOrEmpty ( result ) && buttons . Contains ( result ) ) {
78+ _ViewModel . CurrentMapStyle = _Styles . FirstOrDefault ( ( arg ) => arg . Name == result ) ;
79+ }
80+ }
81+
82+ private async void GetAllStyles ( )
83+ {
84+ IsBusy = true ;
85+ _Styles = await _MBService . GetAllStyles ( ) ;
86+ IsBusy = false ;
87+
88+ }
89+
90+ public MapStyle [ ] _Styles
91+ {
92+ get ;
93+ set ;
5494 }
5595
5696 void ReloadStyle ( object sender , EventArgs args )
5797 {
5898 map . ReloadStyleFunc ? . Execute ( sender ) ;
5999 }
100+
101+ void ZoomIn ( object sender , EventArgs args )
102+ {
103+ map . ZoomLevel += 1.0f ;
104+ }
105+
106+ void ZoomOut ( object sender , EventArgs args )
107+ {
108+ map . ZoomLevel -= 1.0f ;
109+ }
110+
60111 }
61112}
0 commit comments