11var vmModule = require ( "./main-view-model" ) ;
2- var observableModule = require ( "data/observable" ) ;
2+ var observableModule = require ( "tns-core-modules/data/observable" ) ;
3+ var platform = require ( "tns-core-modules/platform" ) ;
34var GoogleMaps = require ( "nativescript-google-maps-sdk" ) ;
45var GoogleMapsUtils = require ( "nativescript-google-maps-utils" ) ;
56// var GoogleMapsUtils = require("./dev");
@@ -23,73 +24,90 @@ function pageLoaded(args) {
2324}
2425exports . pageLoaded = pageLoaded ;
2526
26- function onMapReady ( args ) {
27- debug ( "onMapReady" ) ;
2827
29- var mapView = args . object ;
28+ function configureMap ( mapView , options ) {
3029
31- if ( mapView . android ) {
32-
33- function configure ( mapView , options ) {
34-
35- options = options || { } ;
36-
37- var uiSetting = mapView . gMap . getUiSettings ( ) ;
38-
39- if ( 'allGesturesEnabled' in options ) {
40- uiSetting . setAllGesturesEnabled ( options . allGesturesEnabled ) ;
41- }
42- if ( 'compassEnabled' in options ) {
43- uiSetting . setCompassEnabled ( options . compassEnabled ) ;
44- }
45- if ( 'indoorLevelPickerEnabled' in options ) {
46- uiSetting . setIndoorLevelPickerEnabled ( options . indoorLevelPickerEnabled ) ;
47- }
48- if ( 'mapToolbarEnabled' in options ) {
49- uiSetting . setMapToolbarEnabled ( options . mapToolbarEnabled ) ;
50- }
51- if ( 'myLocationButtonEnabled' in options ) {
52- uiSetting . setMyLocationButtonEnabled ( options . myLocationButtonEnabled ) ;
53- }
54- if ( 'rotateGesturesEnabled' in options ) {
55- uiSetting . setRotateGesturesEnabled ( options . rotateGesturesEnabled ) ;
56- }
57- if ( 'scrollGesturesEnabled' in options ) {
58- uiSetting . setScrollGesturesEnabled ( options . scrollGesturesEnabled ) ;
59- }
60- if ( 'tiltGesturesEnabled' in options ) {
61- uiSetting . setTiltGesturesEnabled ( options . tiltGesturesEnabled ) ;
62- }
63- if ( 'zoomControlsEnabled' in options ) {
64- uiSetting . setZoomControlsEnabled ( options . zoomControlsEnabled ) ;
65- }
66- if ( 'zoomGesturesEnabled' in options ) {
67- uiSetting . setZoomGesturesEnabled ( options . zoomGesturesEnabled ) ;
68- }
69-
70- if ( 'myLocationEnabled' in options ) {
71- mapView . gMap . setMyLocationEnabled ( options . myLocationEnabled ) ;
72- }
73- if ( 'trafficEnabled' in options ) {
74- mapView . gMap . setTrafficEnabled ( options . trafficEnabled ) ;
75- }
30+ if ( platform . isAndroid ) {
7631
77- }
32+ options = options || { } ;
7833
34+ var uiSetting = mapView . gMap . getUiSettings ( ) ;
7935
80- configure ( mapView , {
81- compassEnabled : true ,
82- zoomControlsEnabled : true ,
83- myLocationButtonEnabled : false ,
84- mapToolbarEnabled : true ,
85- allGesturesEnabled : true ,
86- myLocationEnabled : false ,
87- trafficEnabled : true ,
88- } ) ;
36+ if ( 'allGesturesEnabled' in options ) {
37+ uiSetting . setAllGesturesEnabled ( options . allGesturesEnabled ) ;
38+ }
39+ if ( 'compassEnabled' in options ) {
40+ uiSetting . setCompassEnabled ( options . compassEnabled ) ;
41+ }
42+ if ( 'indoorLevelPickerEnabled' in options ) {
43+ uiSetting . setIndoorLevelPickerEnabled ( options . indoorLevelPickerEnabled ) ;
44+ }
45+ if ( 'mapToolbarEnabled' in options ) {
46+ uiSetting . setMapToolbarEnabled ( options . mapToolbarEnabled ) ;
47+ }
48+ if ( 'myLocationButtonEnabled' in options ) {
49+ uiSetting . setMyLocationButtonEnabled ( options . myLocationButtonEnabled ) ;
50+ }
51+ if ( 'rotateGesturesEnabled' in options ) {
52+ uiSetting . setRotateGesturesEnabled ( options . rotateGesturesEnabled ) ;
53+ }
54+ if ( 'scrollGesturesEnabled' in options ) {
55+ uiSetting . setScrollGesturesEnabled ( options . scrollGesturesEnabled ) ;
56+ }
57+ if ( 'tiltGesturesEnabled' in options ) {
58+ uiSetting . setTiltGesturesEnabled ( options . tiltGesturesEnabled ) ;
59+ }
60+ if ( 'zoomControlsEnabled' in options ) {
61+ uiSetting . setZoomControlsEnabled ( options . zoomControlsEnabled ) ;
62+ }
63+ if ( 'zoomGesturesEnabled' in options ) {
64+ uiSetting . setZoomGesturesEnabled ( options . zoomGesturesEnabled ) ;
65+ }
8966
67+ if ( 'myLocationEnabled' in options ) {
68+ mapView . gMap . setMyLocationEnabled ( options . myLocationEnabled ) ;
69+ }
70+ if ( 'trafficEnabled' in options ) {
71+ mapView . gMap . setTrafficEnabled ( options . trafficEnabled ) ;
72+ }
9073
9174 }
9275
76+ }
77+
78+ function generateRandomPosition ( position , distance ) {
79+ var r = distance / 111300 ;
80+
81+ var x = position [ 0 ] ;
82+ var y = position [ 1 ] ;
83+
84+ var u = Math . random ( ) ;
85+ var v = Math . random ( ) ;
86+
87+ var w = r * Math . sqrt ( u ) ;
88+ var t = 2 * Math . PI * v ;
89+
90+ var dx = w * Math . cos ( t ) / Math . cos ( y ) ;
91+ var xy = w * Math . sin ( t ) ;
92+
93+ return [ x + dx , y + xy ] ;
94+ }
95+
96+ function onMapReady ( args ) {
97+ debug ( "onMapReady" ) ;
98+
99+ var mapView = args . object ;
100+
101+ configureMap ( mapView , {
102+ compassEnabled : true ,
103+ zoomControlsEnabled : true ,
104+ myLocationButtonEnabled : false ,
105+ mapToolbarEnabled : true ,
106+ allGesturesEnabled : true ,
107+ myLocationEnabled : false ,
108+ trafficEnabled : true ,
109+ } ) ;
110+
93111 debug ( "Setting a marker..." ) ;
94112
95113 var marker = new GoogleMaps . Marker ( ) ;
@@ -105,24 +123,6 @@ function onMapReady(args) {
105123 var positionSet ;
106124 var makerSet ;
107125
108- function generateRandomPosition ( position , distance ) {
109- var r = distance / 111300 ;
110-
111- var x = position [ 0 ] ;
112- var y = position [ 1 ] ;
113-
114- var u = Math . random ( ) ;
115- var v = Math . random ( ) ;
116-
117- var w = r * Math . sqrt ( u ) ;
118- var t = 2 * Math . PI * v ;
119-
120- var dx = w * Math . cos ( t ) / Math . cos ( y ) ;
121- var xy = w * Math . sin ( t ) ;
122-
123- return [ x + dx , y + xy ] ;
124- }
125-
126126 positionSet = [ ] ;
127127 for ( var i = 0 ; i < 200 ; i ++ ) {
128128 positionSet . push ( generateRandomPosition ( [ 36.845026 , 10.325454 ] , 10000 ) ) ;
0 commit comments