Skip to content

Commit dd02b35

Browse files
authored
Merge pull request #440 from kefahB/master
feat: support for NS7
2 parents 168bab3 + 2d62b55 commit dd02b35

20 files changed

+462
-216
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,22 @@ exports.onCameraMove = onCameraMove;
242242
```
243243

244244
## Custom Info Windows (Beta)
245+
>[!WARNING]
246+
> if you are using NS7 `infoWindowTemplate` won't work from a xml file! a temporary solution will be declaring infoWindow Template from the code behind like this :
247+
248+
```ts
249+
var mapView = null;
250+
251+
export function onMapReady(args) {
252+
mapView = args.object;
253+
mapView.infoWindowTemplate = `<StackLayout orientation="vertical" width="200" height="150" >
254+
<Label text="{{title}}" className="title" width="125" />
255+
<Label text="{{snippet}}" className="snippet" width="125" />
256+
<Label text="{{'LAT: ' + position.latitude}}" className="infoWindowCoordinates" />
257+
<Label text="{{'LON: ' + position.longitude}}" className="infoWindowCoordinates" />
258+
</StackLayout>`;
259+
}
260+
```
245261

246262
To use custom marker info windows, define a template in your view like so:
247263

demo/app/app.js

-19
This file was deleted.

demo/app/app.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Application} from "@nativescript/core";
2+
3+
declare var GMSServices: any;
4+
if(Application.ios) {
5+
GMSServices.provideAPIKey("AIzaSyAtRVvG3Be3xXiZFR7xp-K-9hy4nZ4hMFs");
6+
}
7+
8+
Application.run({ moduleName: "main-page" });
9+
10+
/*
11+
Do not place any code after the application has been started as it will not
12+
be executed on iOS.
13+
*/

demo/app/bundle-config.js

-7
This file was deleted.

demo/app/main-page.js demo/app/main-page.ts

+46-48
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
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";
75
var style = require('./map-style.json');
86

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+
917
function wait(milliSeconds) {
1018
return new Promise(function(resolve, reject) {
1119
setTimeout(function(){
@@ -16,7 +24,7 @@ function wait(milliSeconds) {
1624

1725
function requestPermissions() {
1826
return new Promise(function(resolve, reject) {
19-
if (!application.android) return resolve(true);
27+
if (!Application.android) return resolve(true);
2028
permissions.requestPermission([
2129
android.Manifest.permission.ACCESS_FINE_LOCATION,
2230
android.Manifest.permission.ACCESS_COARSE_LOCATION],
@@ -47,15 +55,9 @@ function printUISettings(settings) {
4755
}, undefined, 2));
4856
}
4957

50-
function pageLoaded(args) {
51-
var page = args.object;
52-
page.bindingContext = vmModule.mainViewModel;
53-
}
54-
exports.pageLoaded = pageLoaded;
55-
5658
var mapView = null;
5759

58-
function onMapReady(args) {
60+
export function onMapReady(args) {
5961
mapView = args.object;
6062

6163
console.log("onMapReady");
@@ -123,11 +125,11 @@ function onMapReady(args) {
123125
mapView.addMarker(marker);
124126

125127
// Custom Info Window Marker
126-
marker = new mapsModule.Marker();
128+
/*marker = new mapsModule.Marker();
127129
marker.position = mapsModule.Position.positionFromLatLng(-33.22, 151.20);
128130
marker.infoWindowTemplate = 'testWindow';
129131
mapView.addMarker(marker);
130-
marker.showInfoWindow();
132+
marker.showInfoWindow();*/
131133

132134
requestPermissions().then(function(granted) {
133135
if(granted) {
@@ -146,67 +148,71 @@ function onMapReady(args) {
146148
marker.rotation = 45;
147149
console.log("Removing Point from polyline...", polyline, point);
148150
polyline.removePoint(point);
149-
return wait(3000);
151+
return wait(delay);
150152
}).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);
155157
}).then(function () {
156158
polyline.addPoint(mapsModule.Position.positionFromLatLng(-33.33, 151.08));
157159
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);
160162
}).then(function () {
161163
polygon.addPoint(mapsModule.Position.positionFromLatLng(-34.22, 151.20));
162164
console.log("Adding point to Polygon...", polygon);
163-
return wait(3000);
165+
return wait(delay);
164166
}).then(function () {
165167
var marker = mapView.findMarker(function (marker) {
166168
return marker.userData.index === 2;
167169
});
168170
marker.visible = true;
169-
return wait(3000);
171+
return wait(delay);
170172
}).then(function () {
171173
var marker = mapView.findMarker(function (marker) {
172174
return marker.userData.index === 2;
173175
});
174176
// marker.position = mapsModule.Position.positionFromLatLng(-32.89,151.44);
175177
marker.anchor = [1, 1];
176178
marker.alpha = 0.8;
177-
return wait(3000);
179+
return wait(delay);
178180
}).then(function () {
179181
console.log("Changing to dark mode...");
180182
mapView.setStyle(style);
181-
return wait(3000);
182-
}).then(function () {
183+
return wait(delay);
184+
})
185+
/*.then(function () {
183186
var marker = mapView.findMarker(function (marker) {
187+
console.log("marker.userData")
188+
console.log(marker)
184189
return marker.userData.index === 1;
185190
});
186191
console.log("Removing marker...", marker.userData);
187192
mapView.removeMarker(marker);
188-
return wait(3000);
189-
}).then(function () {
193+
return wait(delay);
194+
})*/
195+
.then(function () {
190196
console.log("Removing all circles...");
191197
mapView.removeAllCircles();
192198
console.log("Removing all polylines...");
193199
mapView.removeAllPolylines();
194200
console.log("Removing all polygons...");
195201
mapView.removeAllPolygons();
196-
return wait(3000);
202+
return wait(delay);
197203
}).then(function () {
198204
console.log("Hiding compass...");
199205
mapView.settings.compassEnabled = false;
200206
printUISettings(mapView.settings);
201-
return wait(3000);
207+
return wait(delay);
202208
}).then(function () {
203209
console.log("Changing bounds...");
204210
var bounds = mapsModule.Bounds.fromCoordinates(
205211
mapsModule.Position.positionFromLatLng(-33.88, 151.16),
206212
mapsModule.Position.positionFromLatLng(-33.78, 151.24)
207213
);
208214
mapView.setViewport(bounds);
209-
return wait(3000);
215+
return wait(delay);
210216
}).then(function () {
211217
var marker = new mapsModule.Marker();
212218
marker.position = mapsModule.Position.positionFromLatLng(mapView.latitude, mapView.longitude);
@@ -220,18 +226,18 @@ function onMapReady(args) {
220226
});
221227
}
222228

223-
function onCoordinateTapped(args) {
229+
export function onCoordinateTapped(args) {
224230
console.log("Coordinate Tapped, Lat: " + args.position.latitude + ", Lon: " + args.position.longitude, args);
225231
}
226232

227-
function onMarkerEvent(args) {
233+
export function onMarkerEvent(args) {
228234
console.log("Marker Event: '" + args.eventName
229235
+ "' triggered on: " + args.marker.title
230236
+ ", Lat: " + args.marker.position.latitude + ", Lon: " + args.marker.position.longitude, args);
231237
}
232238

233239
var lastCamera = null;
234-
function onCameraChanged(args) {
240+
export function onCameraChanged(args) {
235241
console.log("Camera changed: "+JSON.stringify(args.camera), JSON.stringify(args.camera) === lastCamera);
236242
lastCamera = JSON.stringify(args.camera);
237243
var bounds = mapView.projection.visibleRegion.bounds;
@@ -241,22 +247,14 @@ function onCameraChanged(args) {
241247
}));
242248
}
243249

244-
function onCameraMove(args) {
250+
export function onCameraMove(args) {
245251
console.log("Camera moving: "+JSON.stringify(args.camera));
246252
}
247253

248-
function onIndoorBuildingFocused(args) {
254+
export function onIndoorBuildingFocused(args) {
249255
console.log("Building focus changed: " + JSON.stringify(args.indoorBuilding));
250256
}
251257

252-
function onIndoorLevelActivated(args) {
258+
export function onIndoorLevelActivated(args) {
253259
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+
}

demo/app/main-page.xml

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@
2525
</StackLayout>
2626
</maps:mapView.infoWindowTemplate>
2727
<maps:mapView.infoWindowTemplates>
28-
<template key="testWindow">
28+
<!--<template key="testWindow">
2929
<StackLayout orientation="vertical" width="160" height="160" >
3030
<Image src="res://icon" stretch="fill" height="100" width="100" className="infoWindowImage" />
3131
<Label text="Let's Begin!" className="title" />
3232
</StackLayout>
33-
</template>
33+
</template>-->
34+
<StackLayout orientation="vertical" width="200" height="150" >
35+
<Label text="{{title}}" className="title" width="125" />
36+
<Label text="{{snippet}}" className="snippet" width="125" />
37+
<Label text="{{'LAT: ' + position.latitude}}" className="infoWindowCoordinates" />
38+
<Label text="{{'LON: ' + position.longitude}}" className="infoWindowCoordinates" />
39+
</StackLayout>
3440
</maps:mapView.infoWindowTemplates>
3541
</maps:mapView>
3642
</GridLayout>
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
var observable = require("data/observable");
2-
var HelloWorldModel = (function (_super) {
3-
__extends(HelloWorldModel, _super);
4-
function HelloWorldModel() {
5-
_super.call(this);
1+
import { Observable } from "@nativescript/core";
2+
3+
4+
export class HelloWorldModel extends Observable {
5+
constructor() {
6+
super();
67
this.set("latitude", -33.86);
78
this.set("longitude", 151.20);
89
this.set("zoom", 8);
@@ -13,8 +14,4 @@ var HelloWorldModel = (function (_super) {
1314
this.set("padding", [80, 40, 40, 40]);
1415
this.set("mapAnimationsEnabled", true);
1516
}
16-
17-
return HelloWorldModel;
18-
})(observable.Observable);
19-
exports.HelloWorldModel = HelloWorldModel;
20-
exports.mainViewModel = new HelloWorldModel();
17+
}

demo/nativescript.config.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NativeScriptConfig } from '@nativescript/core'
2+
3+
export default {
4+
id: 'org.nativescript.demo',
5+
appResourcesPath: 'app/App_Resources',
6+
android: {
7+
v8Flags: '--expose_gc',
8+
markingMode: 'none',
9+
},
10+
appPath: 'app',
11+
} as NativeScriptConfig

demo/package.json

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
{
2-
"nativescript": {
3-
"id": "org.nativescript.demo",
4-
"tns-ios": {
5-
"version": "6.2.0"
6-
},
7-
"tns-android": {
8-
"version": "6.2.0"
9-
}
10-
},
112
"dependencies": {
12-
"nativescript-google-maps-sdk": "../src",
3+
"nativescript-google-maps-sdk": "file:../src",
134
"nativescript-permissions": "^1.2.3",
14-
"tns-core-modules": "~6.2.0"
5+
"@nativescript/core": "~7.0.12"
156
},
167
"devDependencies": {
8+
"@nativescript/android": "7.0.1",
9+
"@nativescript/ios": "7.0.4",
10+
"@nativescript/types": "^7.0.4",
11+
"@nativescript/webpack": "~3.0.0",
1712
"babel-traverse": "^6.26.0",
1813
"babel-types": "^6.26.0",
1914
"babylon": "6.7.0",
15+
"eslint": "^7.5.0",
2016
"filewalker": "0.1.2",
2117
"lazy": "1.0.11",
22-
"nativescript-dev-webpack": "~1.3.0"
23-
}
18+
"ts-node": "^9.0.0",
19+
"typescript": "~3.9.0"
20+
},
21+
"main": "app.js"
2422
}

demo/references.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference path="./node_modules/@nativescript/types/index.d.ts" />

0 commit comments

Comments
 (0)