1
- var vmModule = require ( "./main-view-model" ) ;
2
- var builder = require ( "ui/builder" ) ;
3
- var mapsModule = require ( "nativescript-google-maps-sdk" ) ;
4
- var permissions = require ( "nativescript-permissions" ) ;
5
- var application = require ( "application" ) ;
6
- var Color = require ( "color" ) . Color ;
1
+ import { HelloWorldModel } from "./main-view-model" ;
2
+ import * as mapsModule from "nativescript-google-maps-sdk" ;
3
+ import * as permissions from "nativescript-permissions" ;
4
+ import { Application , Color } from "@nativescript/core" ;
7
5
var style = require ( './map-style.json' ) ;
8
6
7
+ declare var android : any ;
8
+ let vmModule : HelloWorldModel = null ;
9
+ const delay = 1000 ;
10
+
11
+ export function pageLoaded ( args ) {
12
+ var page = args . object ;
13
+ vmModule = new HelloWorldModel ( ) ;
14
+ page . bindingContext = vmModule ;
15
+ }
16
+
9
17
function wait ( milliSeconds ) {
10
18
return new Promise ( function ( resolve , reject ) {
11
19
setTimeout ( function ( ) {
@@ -16,7 +24,7 @@ function wait(milliSeconds) {
16
24
17
25
function requestPermissions ( ) {
18
26
return new Promise ( function ( resolve , reject ) {
19
- if ( ! application . android ) return resolve ( true ) ;
27
+ if ( ! Application . android ) return resolve ( true ) ;
20
28
permissions . requestPermission ( [
21
29
android . Manifest . permission . ACCESS_FINE_LOCATION ,
22
30
android . Manifest . permission . ACCESS_COARSE_LOCATION ] ,
@@ -47,15 +55,9 @@ function printUISettings(settings) {
47
55
} , undefined , 2 ) ) ;
48
56
}
49
57
50
- function pageLoaded ( args ) {
51
- var page = args . object ;
52
- page . bindingContext = vmModule . mainViewModel ;
53
- }
54
- exports . pageLoaded = pageLoaded ;
55
-
56
58
var mapView = null ;
57
59
58
- function onMapReady ( args ) {
60
+ export function onMapReady ( args ) {
59
61
mapView = args . object ;
60
62
61
63
console . log ( "onMapReady" ) ;
@@ -123,11 +125,11 @@ function onMapReady(args) {
123
125
mapView . addMarker ( marker ) ;
124
126
125
127
// Custom Info Window Marker
126
- marker = new mapsModule . Marker ( ) ;
128
+ /* marker = new mapsModule.Marker();
127
129
marker.position = mapsModule.Position.positionFromLatLng(-33.22, 151.20);
128
130
marker.infoWindowTemplate = 'testWindow';
129
131
mapView.addMarker(marker);
130
- marker . showInfoWindow ( ) ;
132
+ marker.showInfoWindow();*/
131
133
132
134
requestPermissions ( ) . then ( function ( granted ) {
133
135
if ( granted ) {
@@ -146,67 +148,71 @@ function onMapReady(args) {
146
148
marker . rotation = 45 ;
147
149
console . log ( "Removing Point from polyline..." , polyline , point ) ;
148
150
polyline . removePoint ( point ) ;
149
- return wait ( 3000 ) ;
151
+ return wait ( delay ) ;
150
152
} ) . then ( function ( ) {
151
- vmModule . mainViewModel . set ( "mapAnimationsEnabled" , false ) ;
152
- vmModule . mainViewModel . set ( "zoom" , 9 ) ;
153
- console . log ( "Zooming in (no animation)..." , vmModule . mainViewModel ) ;
154
- return wait ( 3000 ) ;
153
+ vmModule . set ( "mapAnimationsEnabled" , false ) ;
154
+ vmModule . set ( "zoom" , 9 ) ;
155
+ console . log ( "Zooming in (no animation)..." , vmModule ) ;
156
+ return wait ( delay ) ;
155
157
} ) . then ( function ( ) {
156
158
polyline . addPoint ( mapsModule . Position . positionFromLatLng ( - 33.33 , 151.08 ) ) ;
157
159
console . log ( "Adding point to Polyline..." , polyline ) ;
158
- vmModule . mainViewModel . set ( "padding" , [ 30 , 60 , 40 , 40 ] ) ;
159
- return wait ( 3000 ) ;
160
+ vmModule . set ( "padding" , [ 30 , 60 , 40 , 40 ] ) ;
161
+ return wait ( delay ) ;
160
162
} ) . then ( function ( ) {
161
163
polygon . addPoint ( mapsModule . Position . positionFromLatLng ( - 34.22 , 151.20 ) ) ;
162
164
console . log ( "Adding point to Polygon..." , polygon ) ;
163
- return wait ( 3000 ) ;
165
+ return wait ( delay ) ;
164
166
} ) . then ( function ( ) {
165
167
var marker = mapView . findMarker ( function ( marker ) {
166
168
return marker . userData . index === 2 ;
167
169
} ) ;
168
170
marker . visible = true ;
169
- return wait ( 3000 ) ;
171
+ return wait ( delay ) ;
170
172
} ) . then ( function ( ) {
171
173
var marker = mapView . findMarker ( function ( marker ) {
172
174
return marker . userData . index === 2 ;
173
175
} ) ;
174
176
// marker.position = mapsModule.Position.positionFromLatLng(-32.89,151.44);
175
177
marker . anchor = [ 1 , 1 ] ;
176
178
marker . alpha = 0.8 ;
177
- return wait ( 3000 ) ;
179
+ return wait ( delay ) ;
178
180
} ) . then ( function ( ) {
179
181
console . log ( "Changing to dark mode..." ) ;
180
182
mapView . setStyle ( style ) ;
181
- return wait ( 3000 ) ;
182
- } ) . then ( function ( ) {
183
+ return wait ( delay ) ;
184
+ } )
185
+ /*.then(function () {
183
186
var marker = mapView.findMarker(function (marker) {
187
+ console.log("marker.userData")
188
+ console.log(marker)
184
189
return marker.userData.index === 1;
185
190
});
186
191
console.log("Removing marker...", marker.userData);
187
192
mapView.removeMarker(marker);
188
- return wait ( 3000 ) ;
189
- } ) . then ( function ( ) {
193
+ return wait(delay);
194
+ })*/
195
+ . then ( function ( ) {
190
196
console . log ( "Removing all circles..." ) ;
191
197
mapView . removeAllCircles ( ) ;
192
198
console . log ( "Removing all polylines..." ) ;
193
199
mapView . removeAllPolylines ( ) ;
194
200
console . log ( "Removing all polygons..." ) ;
195
201
mapView . removeAllPolygons ( ) ;
196
- return wait ( 3000 ) ;
202
+ return wait ( delay ) ;
197
203
} ) . then ( function ( ) {
198
204
console . log ( "Hiding compass..." ) ;
199
205
mapView . settings . compassEnabled = false ;
200
206
printUISettings ( mapView . settings ) ;
201
- return wait ( 3000 ) ;
207
+ return wait ( delay ) ;
202
208
} ) . then ( function ( ) {
203
209
console . log ( "Changing bounds..." ) ;
204
210
var bounds = mapsModule . Bounds . fromCoordinates (
205
211
mapsModule . Position . positionFromLatLng ( - 33.88 , 151.16 ) ,
206
212
mapsModule . Position . positionFromLatLng ( - 33.78 , 151.24 )
207
213
) ;
208
214
mapView . setViewport ( bounds ) ;
209
- return wait ( 3000 ) ;
215
+ return wait ( delay ) ;
210
216
} ) . then ( function ( ) {
211
217
var marker = new mapsModule . Marker ( ) ;
212
218
marker . position = mapsModule . Position . positionFromLatLng ( mapView . latitude , mapView . longitude ) ;
@@ -220,18 +226,18 @@ function onMapReady(args) {
220
226
} ) ;
221
227
}
222
228
223
- function onCoordinateTapped ( args ) {
229
+ export function onCoordinateTapped ( args ) {
224
230
console . log ( "Coordinate Tapped, Lat: " + args . position . latitude + ", Lon: " + args . position . longitude , args ) ;
225
231
}
226
232
227
- function onMarkerEvent ( args ) {
233
+ export function onMarkerEvent ( args ) {
228
234
console . log ( "Marker Event: '" + args . eventName
229
235
+ "' triggered on: " + args . marker . title
230
236
+ ", Lat: " + args . marker . position . latitude + ", Lon: " + args . marker . position . longitude , args ) ;
231
237
}
232
238
233
239
var lastCamera = null ;
234
- function onCameraChanged ( args ) {
240
+ export function onCameraChanged ( args ) {
235
241
console . log ( "Camera changed: " + JSON . stringify ( args . camera ) , JSON . stringify ( args . camera ) === lastCamera ) ;
236
242
lastCamera = JSON . stringify ( args . camera ) ;
237
243
var bounds = mapView . projection . visibleRegion . bounds ;
@@ -241,22 +247,14 @@ function onCameraChanged(args) {
241
247
} ) ) ;
242
248
}
243
249
244
- function onCameraMove ( args ) {
250
+ export function onCameraMove ( args ) {
245
251
console . log ( "Camera moving: " + JSON . stringify ( args . camera ) ) ;
246
252
}
247
253
248
- function onIndoorBuildingFocused ( args ) {
254
+ export function onIndoorBuildingFocused ( args ) {
249
255
console . log ( "Building focus changed: " + JSON . stringify ( args . indoorBuilding ) ) ;
250
256
}
251
257
252
- function onIndoorLevelActivated ( args ) {
258
+ export function onIndoorLevelActivated ( args ) {
253
259
console . log ( "Indoor level changed: " + JSON . stringify ( args . activateLevel ) ) ;
254
- }
255
-
256
- exports . onMapReady = onMapReady ;
257
- exports . onCoordinateTapped = onCoordinateTapped ;
258
- exports . onMarkerEvent = onMarkerEvent ;
259
- exports . onCameraChanged = onCameraChanged ;
260
- exports . onCameraMove = onCameraMove ;
261
- exports . onIndoorBuildingFocused = onIndoorBuildingFocused ;
262
- exports . onIndoorLevelActivated = onIndoorLevelActivated ;
260
+ }
0 commit comments