@nativescript-community/ui-mapbox 6.2.15 → 6.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/blueprint.md +922 -0
- package/common.js +1 -1
- package/index.android.js +4 -4
- package/index.ios.js +3 -224
- package/package.json +2 -2
- package/platforms/android/ui_mapbox.aar +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [6.2.19](https://github.com/nativescript-community/ui-mapbox/compare/v6.2.15...v6.2.19) (2022-09-14)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @nativescript-community/ui-mapbox
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [6.2.18](https://github.com/nativescript-community/ui-mapbox/compare/v6.2.15...v6.2.18) (2022-09-14)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @nativescript-community/ui-mapbox
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [6.2.17](https://github.com/nativescript-community/ui-mapbox/compare/v6.2.15...v6.2.17) (2022-09-14)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @nativescript-community/ui-mapbox
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [6.2.16](https://github.com/nativescript-community/ui-mapbox/compare/v6.2.15...v6.2.16) (2022-09-14)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @nativescript-community/ui-mapbox
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
## [6.2.15](https://github.com/nativescript-community/ui-mapbox/compare/v6.2.14...v6.2.15) (2022-03-03)
|
|
7
39
|
|
|
8
40
|
**Note:** Version bump only for package @nativescript-community/ui-mapbox
|
package/blueprint.md
ADDED
|
@@ -0,0 +1,922 @@
|
|
|
1
|
+
{{ load:../../tools/readme/edit-warning.md }}
|
|
2
|
+
{{ template:title }}
|
|
3
|
+
{{ template:badges }}
|
|
4
|
+
{{ template:description }}
|
|
5
|
+
|
|
6
|
+
{{ template:toc }}
|
|
7
|
+
|
|
8
|
+
## Prerequisites
|
|
9
|
+
|
|
10
|
+
You either need your own tile server such as the one provided by [openmaptiles.org](https://openmaptiles.org) or a Mapbox API access token (they have a 🆓 Starter plan!), so [sign up with Mapbox](https://www.mapbox.com/signup/).
|
|
11
|
+
Once you've registered go to your Account > Apps > New token. The 'Default Secret Token' is what you'll need.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
Run the following command from the root of your project:
|
|
15
|
+
|
|
16
|
+
`ns plugin add {{ pkg.name }}`
|
|
17
|
+
|
|
18
|
+
## Configuration
|
|
19
|
+
|
|
20
|
+
Add any other additional configuration instructions here.
|
|
21
|
+
|
|
22
|
+
## Issues
|
|
23
|
+
|
|
24
|
+
If you get an error during iOS build related to Podspec versions, probably the easiest fix is:
|
|
25
|
+
`ns platform remove ios` and `ns platform add ios`.
|
|
26
|
+
|
|
27
|
+
On Android the plugin adds this to the `<application>` node of `app/App_Resources/Android/AndroidManifest.xml` (the plugin already attempts to do so):
|
|
28
|
+
|
|
29
|
+
```xml
|
|
30
|
+
<service android:name="com.mapbox.services.android.telemetry.service.TelemetryService" />
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
If you get an error related to `TelemetryService` then please check it's there.
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### XML
|
|
38
|
+
You can instantiate a map from JS or TS. As the map is yet another view component it will play nice with any NativeScript layout you throw it in. You can also easily add multiple maps to the same page or to different pages in any layout you like.
|
|
39
|
+
|
|
40
|
+
A simple layout could look like this:
|
|
41
|
+
|
|
42
|
+
<img src="https://raw.githubusercontent.com/nativescript-community/ui-mapbox/master/images/ios-xml-declared.png" width="373px" height="361px" />
|
|
43
|
+
|
|
44
|
+
Could be rendered by a definition like this:
|
|
45
|
+
|
|
46
|
+
```xml
|
|
47
|
+
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:map="@nativescript-community/ui-mapbox" navigatingTo="navigatingTo">
|
|
48
|
+
<StackLayout>
|
|
49
|
+
<Label text="Nice map, huh!" class="title"/>
|
|
50
|
+
<ContentView height="240" width="240">
|
|
51
|
+
<map:MapboxView
|
|
52
|
+
accessToken="your_token"
|
|
53
|
+
mapStyle="traffic_night"
|
|
54
|
+
latitude="52.3702160"
|
|
55
|
+
longitude="4.8951680"
|
|
56
|
+
zoomLevel="3"
|
|
57
|
+
showUserLocation="true"
|
|
58
|
+
mapReady="onMapReady">
|
|
59
|
+
</map:MapboxView>
|
|
60
|
+
</ContentView>
|
|
61
|
+
</StackLayout>
|
|
62
|
+
</Page>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Angular
|
|
66
|
+
Component:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { registerElement } from '@nativescript/angular';
|
|
70
|
+
registerElement("Mapbox", () => require("@nativescript-community/ui-mapbox").MapboxView);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
View:
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<ContentView height="100%" width="100%">
|
|
77
|
+
<Mapbox
|
|
78
|
+
accessToken="your_token"
|
|
79
|
+
mapStyle="traffic_day"
|
|
80
|
+
latitude="50.467735"
|
|
81
|
+
longitude="13.427718"
|
|
82
|
+
hideCompass="true"
|
|
83
|
+
zoomLevel="18"
|
|
84
|
+
showUserLocation="false"
|
|
85
|
+
disableZoom="false"
|
|
86
|
+
disableRotation="false"
|
|
87
|
+
disableScroll="false"
|
|
88
|
+
disableTilt="false"
|
|
89
|
+
(mapReady)="onMapReady($event)">
|
|
90
|
+
</Mapbox>
|
|
91
|
+
</ContentView>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## API
|
|
95
|
+
All currently supported options for your XML based map are (__don't__ use other properties - if you need styling wrap the map in a `ContentView` and apply things like `width` to that container!):
|
|
96
|
+
|
|
97
|
+
|option|default|description
|
|
98
|
+
|---|---|---
|
|
99
|
+
|`accesstoken`|-|see 'Prerequisites' above
|
|
100
|
+
|`delay`|0|A delay in milliseconds - you can set this to have better control over when Mapbox is invoked so it won't clash with other computations your app may need to perform.
|
|
101
|
+
|`mapStyle`|streets|streets, light, dark, satellite_streets, satellite, traffic_day, traffic_night, an URL starting with mapbox:// or pointing to a custom JSON definition (http://, https://, or local relative to nativescript app path ~/)
|
|
102
|
+
|`latitude `|-|Set the center of the map by passing this in
|
|
103
|
+
|`longitude`|-|.. and this as well
|
|
104
|
+
|`zoomLevel`|0|0-20
|
|
105
|
+
|`showUserLocation `|false|Requires location permissions on Android which you can remove from `AndroidManifest.xml` if you don't need them
|
|
106
|
+
|`hideCompass `|false|Don't show the compass in the top right corner during rotation of the map
|
|
107
|
+
|`hideLogo`|false|Mapbox requires `false` if you're on a free plan
|
|
108
|
+
|`hideAttribution `|true|Mapbox requires `false` if you're on a free plan
|
|
109
|
+
|`disableZoom`|false|Don't allow the user to zoom in or out (pinch and double-tap)
|
|
110
|
+
|`disableRotation`|false|Don't allow the user to rotate the map (two finger gesture)
|
|
111
|
+
|`disableScroll`|false|Don't allow the user to move the center of the map (one finger drag)
|
|
112
|
+
|`disableTilt`|false|Don't allow the user to tilt the map (two finger drag up or down)
|
|
113
|
+
|`mapReady`|-|The name of a callback function you can declare to interact with the map after it has been drawn
|
|
114
|
+
|`moveBeginEvent`|-|The name of a function to be called when the map has begun to move.
|
|
115
|
+
|`moveEndEvent`|-|The name of a function to be called when the map has completed moving.
|
|
116
|
+
|`locationPermissionGranted`|-|The name of a callback function you can declare to get notified when the user granted location permissions
|
|
117
|
+
|`locationPermissionDenied`|-|The name of a callback function you can declare to get notified when the user denied location permissions (will never fire on iOS because there's nothing to deny)
|
|
118
|
+
|
|
119
|
+
## Markers
|
|
120
|
+
This is where that last option in the table above comes in - `mapReady`.
|
|
121
|
+
It allows you to interact with the map after it has been drawn to the page.
|
|
122
|
+
|
|
123
|
+
Open `main-page.[js|ts]` and add this (see [`addMarkers`](#addmarkers) further below for the full marker API):
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
var mapbox = require("@nativescript-community/ui-mapbox");
|
|
127
|
+
|
|
128
|
+
function onMapReady(args) {
|
|
129
|
+
// you can tap into the native MapView objects (MGLMapView for iOS and com.mapbox.mapboxsdk.maps.MapView for Android)
|
|
130
|
+
var nativeMapView = args.ios ? args.ios : args.android;
|
|
131
|
+
console.log("Mapbox onMapReady for " + (args.ios ? "iOS" : "Android") + ", native object received: " + nativeMapView);
|
|
132
|
+
|
|
133
|
+
// .. or use the convenience methods exposed on args.map, for instance:
|
|
134
|
+
args.map.addMarkers([
|
|
135
|
+
{
|
|
136
|
+
lat: 52.3602160,
|
|
137
|
+
lng: 4.8891680,
|
|
138
|
+
title: 'One-line title here',
|
|
139
|
+
subtitle: 'Really really nice location',
|
|
140
|
+
selected: true, // makes the callout show immediately when the marker is added (note: only 1 marker can be selected at a time)
|
|
141
|
+
onCalloutTap: function(){console.log("'Nice location' marker callout tapped");}
|
|
142
|
+
}]
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
exports.onMapReady = onMapReady;
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Viewport
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
var mapbox = require("@nativescript-community/ui-mapbox");
|
|
153
|
+
|
|
154
|
+
function onMapReady(args) {
|
|
155
|
+
args.map.setViewport(
|
|
156
|
+
{
|
|
157
|
+
bounds: {
|
|
158
|
+
north: 52.4820,
|
|
159
|
+
east: 5.1087,
|
|
160
|
+
south: 52.2581,
|
|
161
|
+
west: 4.6816
|
|
162
|
+
},
|
|
163
|
+
animated: true
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
exports.onMapReady = onMapReady;
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The methods you can invoke like this from an XML-declared map are:
|
|
172
|
+
`addMarkers`, `setViewport`, `removeMarkers`, `getCenter`, `setCenter`, `getZoomLevel`, `setZoomLevel`, `getViewport`, `getTilt`, `setTilt`, `setMapStyle`, `animateCamera`, `addPolygon`, `removePolygons`, `addPolyline`, `removePolylines`, `getUserLocation`, `trackUser`, `setOnMapClickListener`, `setOnMapLongClickListener` and `destroy`.
|
|
173
|
+
|
|
174
|
+
Check out the usage details on the functions below.
|
|
175
|
+
|
|
176
|
+
## Declaring Programmatically
|
|
177
|
+
|
|
178
|
+
Add a container to your view XML where you want to programmatically add the map. Give it an id.
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
<ContentView id="mapContainer" />
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Methods
|
|
185
|
+
|
|
186
|
+
### show
|
|
187
|
+
```ts
|
|
188
|
+
|
|
189
|
+
const contentView : ContentView = <ContentView>page.getViewById( 'mapContainer' );
|
|
190
|
+
|
|
191
|
+
const settings = {
|
|
192
|
+
|
|
193
|
+
// NOTE: passing in the container here.
|
|
194
|
+
|
|
195
|
+
container: contentView,
|
|
196
|
+
accessToken: ACCESS_TOKEN,
|
|
197
|
+
style: MapStyle.LIGHT,
|
|
198
|
+
margins: {
|
|
199
|
+
left: 18,
|
|
200
|
+
right: 18,
|
|
201
|
+
top: isIOS ? 390 : 454,
|
|
202
|
+
bottom: isIOS ? 50 : 8
|
|
203
|
+
},
|
|
204
|
+
center: {
|
|
205
|
+
lat: 52.3702160,
|
|
206
|
+
lng: 4.8951680
|
|
207
|
+
},
|
|
208
|
+
zoomLevel: 9, // 0 (most of the world) to 20, default 0
|
|
209
|
+
showUserLocation: true, // default false
|
|
210
|
+
hideAttribution: true, // default false
|
|
211
|
+
hideLogo: true, // default false
|
|
212
|
+
hideCompass: false, // default false
|
|
213
|
+
disableRotation: false, // default false
|
|
214
|
+
disableScroll: false, // default false
|
|
215
|
+
disableZoom: false, // default false
|
|
216
|
+
disableTilt: false, // default false
|
|
217
|
+
markers: [
|
|
218
|
+
{
|
|
219
|
+
id: 1,
|
|
220
|
+
lat: 52.3732160,
|
|
221
|
+
lng: 4.8941680,
|
|
222
|
+
title: 'Nice location',
|
|
223
|
+
subtitle: 'Really really nice location',
|
|
224
|
+
iconPath: 'res/markers/green_pin_marker.png',
|
|
225
|
+
onTap: () => console.log("'Nice location' marker tapped"),
|
|
226
|
+
onCalloutTap: () => console.log("'Nice location' marker callout tapped")
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
console.log( "main-view-model:: doShow(): creating new MapboxView." );
|
|
232
|
+
|
|
233
|
+
const mapView = new MapboxView();
|
|
234
|
+
|
|
235
|
+
// Bind some event handlers onto our newly created map view.
|
|
236
|
+
|
|
237
|
+
mapView.on( 'mapReady', ( args : any ) => {
|
|
238
|
+
|
|
239
|
+
console.log( "main-view-model: onMapReady fired." );
|
|
240
|
+
|
|
241
|
+
// this is an instance of class MapboxView
|
|
242
|
+
|
|
243
|
+
this.mapboxView = args.map;
|
|
244
|
+
|
|
245
|
+
// get a reference to the Mapbox API shim object so we can directly call its methods.
|
|
246
|
+
|
|
247
|
+
this.mapbox = this.mapboxView.getMapboxApi();
|
|
248
|
+
|
|
249
|
+
this.mapbox.setOnMapClickListener( point => {
|
|
250
|
+
console.log(`>> Map clicked: ${JSON.stringify(point)}`);
|
|
251
|
+
return true;
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
this.mapbox.setOnMapLongClickListener( point => {
|
|
255
|
+
console.log(`>> Map longpressed: ${JSON.stringify(point)}`);
|
|
256
|
+
return true;
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
this.mapbox.setOnScrollListener((point: LatLng) => {
|
|
260
|
+
// console.log(`>> Map scrolled`);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
this.mapbox.setOnFlingListener(() => {
|
|
264
|
+
console.log(`>> Map flinged"`);
|
|
265
|
+
}).catch( err => console.log(err) );
|
|
266
|
+
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
mapView.setConfig( settings );
|
|
270
|
+
contentView.content = mapView;
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### hide
|
|
275
|
+
All further examples assume `mapbox` has been required.
|
|
276
|
+
Also, all functions support promises, but we're leaving out the `.then()` stuff for brevity where it doesn't add value.
|
|
277
|
+
```js
|
|
278
|
+
mapbox.hide();
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### unhide
|
|
282
|
+
If you previously called `hide()` you can quickly unhide the map,
|
|
283
|
+
instead of redrawing it (which is a lot slower and you loose the viewport position, etc).
|
|
284
|
+
|
|
285
|
+
```js
|
|
286
|
+
mapbox.unhide();
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### destroy 💥
|
|
290
|
+
To clean up the map entirely you can destroy instead of hide it:
|
|
291
|
+
|
|
292
|
+
```js
|
|
293
|
+
mapbox.destroy();
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### setMapStyle
|
|
297
|
+
You can update the map style after you've loaded it.
|
|
298
|
+
|
|
299
|
+
> With Mapbox Android SDK 6.1.x (used in plugin version 4.1.0) I've seen Android crash a few seconds after this has been used, so test this well and perhaps don't use it when in doubt.
|
|
300
|
+
|
|
301
|
+
```js
|
|
302
|
+
mapbox.setMapStyle(mapbox.MapStyle.DARK);
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### addMarkers
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { MapboxMarker } from "@nativescript-community/ui-mapbox";
|
|
309
|
+
|
|
310
|
+
const firstMarker = <MapboxMarker>{ //cast as a MapboxMarker to pick up helper functions such as update()
|
|
311
|
+
id: 2, // can be user in 'removeMarkers()'
|
|
312
|
+
lat: 52.3602160, // mandatory
|
|
313
|
+
lng: 4.8891680, // mandatory
|
|
314
|
+
title: 'One-line title here', // no popup unless set
|
|
315
|
+
subtitle: 'Infamous subtitle!',
|
|
316
|
+
// icon: 'res://cool_marker', // preferred way, otherwise use:
|
|
317
|
+
icon: 'http(s)://website/coolimage.png', // from the internet (see the note at the bottom of this readme), or:
|
|
318
|
+
iconPath: '~/assets/markers/home_marker.png',
|
|
319
|
+
selected: true, // makes the callout show immediately when the marker is added (note: only 1 marker can be selected at a time)
|
|
320
|
+
onTap: marker => console.log("Marker tapped with title: '" + marker.title + "'"),
|
|
321
|
+
onCalloutTap: marker => alert("Marker callout tapped with title: '" + marker.title + "'")
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
mapbox.addMarkers([
|
|
325
|
+
firstMarker,
|
|
326
|
+
{
|
|
327
|
+
// more markers..
|
|
328
|
+
}
|
|
329
|
+
])
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Updating markers
|
|
333
|
+
Plugin version 4.2.0 added the option to update makers. Just call `update` on the `MapboxMarker` reference you created above.
|
|
334
|
+
You can update the following properties (all but the icon really):
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
firstMarker.update({
|
|
338
|
+
lat: 52.3622160,
|
|
339
|
+
lng: 4.8911680,
|
|
340
|
+
title: 'One-line title here (UPDATE)',
|
|
341
|
+
subtitle: 'Updated subtitle',
|
|
342
|
+
selected: true, // this will trigger the callout upon update
|
|
343
|
+
onTap: (marker: MapboxMarker) => console.log(`UPDATED Marker tapped with title: ${marker.title}`),
|
|
344
|
+
onCalloutTap: (marker: MapboxMarker) => alert(`UPDATED Marker callout tapped with title: ${marker.title}`)
|
|
345
|
+
})
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### removeMarkers
|
|
349
|
+
You can either remove all markers by not passing in an argument,
|
|
350
|
+
or remove specific marker id's (which you specified previously).
|
|
351
|
+
|
|
352
|
+
```js
|
|
353
|
+
// remove all markers
|
|
354
|
+
mapbox.removeMarkers();
|
|
355
|
+
|
|
356
|
+
// remove specific markers by id
|
|
357
|
+
mapbox.removeMarkers([1, 2]);
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### setViewport
|
|
361
|
+
If you want to for instance make the viewport contain all markers you
|
|
362
|
+
can set the bounds to the lat/lng of the outermost markers using this function.
|
|
363
|
+
|
|
364
|
+
```js
|
|
365
|
+
mapbox.setViewport(
|
|
366
|
+
{
|
|
367
|
+
bounds: {
|
|
368
|
+
north: 52.4820,
|
|
369
|
+
east: 5.1087,
|
|
370
|
+
south: 52.2581,
|
|
371
|
+
west: 4.6816
|
|
372
|
+
},
|
|
373
|
+
animated: true // default true
|
|
374
|
+
}
|
|
375
|
+
)
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### getViewport
|
|
379
|
+
```js
|
|
380
|
+
mapbox.getViewport().then(
|
|
381
|
+
function(result) {
|
|
382
|
+
console.log("Mapbox getViewport done, result: " + JSON.stringify(result));
|
|
383
|
+
}
|
|
384
|
+
)
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
### setCenter
|
|
389
|
+
```js
|
|
390
|
+
mapbox.setCenter(
|
|
391
|
+
{
|
|
392
|
+
lat: 52.3602160, // mandatory
|
|
393
|
+
lng: 4.8891680, // mandatory
|
|
394
|
+
animated: false // default true
|
|
395
|
+
}
|
|
396
|
+
)
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### getCenter
|
|
400
|
+
Here the promise callback makes sense, so adding it to the example:
|
|
401
|
+
```js
|
|
402
|
+
mapbox.getCenter().then(
|
|
403
|
+
function(result) {
|
|
404
|
+
console.log("Mapbox getCenter done, result: " + JSON.stringify(result));
|
|
405
|
+
},
|
|
406
|
+
function(error) {
|
|
407
|
+
console.log("mapbox getCenter error: " + error);
|
|
408
|
+
}
|
|
409
|
+
)
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### setZoomLevel
|
|
413
|
+
```js
|
|
414
|
+
mapbox.setZoomLevel(
|
|
415
|
+
{
|
|
416
|
+
level: 6.5, // mandatory, 0-20
|
|
417
|
+
animated: true // default true
|
|
418
|
+
}
|
|
419
|
+
)
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### getZoomLevel
|
|
423
|
+
```js
|
|
424
|
+
mapbox.getZoomLevel().then(
|
|
425
|
+
function(result) {
|
|
426
|
+
console.log("Mapbox getZoomLevel done, result: " + JSON.stringify(result));
|
|
427
|
+
},
|
|
428
|
+
function(error) {
|
|
429
|
+
console.log("mapbox getZoomLevel error: " + error);
|
|
430
|
+
}
|
|
431
|
+
)
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### animateCamera
|
|
435
|
+
|
|
436
|
+
```js
|
|
437
|
+
// this is a boring triangle drawn near Amsterdam Central Station
|
|
438
|
+
mapbox.animateCamera({
|
|
439
|
+
// this is where we animate to
|
|
440
|
+
target: {
|
|
441
|
+
lat: 52.3732160,
|
|
442
|
+
lng: 4.8941680
|
|
443
|
+
},
|
|
444
|
+
zoomLevel: 17, // Android
|
|
445
|
+
altitude: 2000, // iOS (meters from the ground)
|
|
446
|
+
bearing: 270, // Where the camera is pointing, 0-360 (degrees)
|
|
447
|
+
tilt: 50,
|
|
448
|
+
duration: 5000 // default 10000 (milliseconds)
|
|
449
|
+
})
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### setTilt (Android only)
|
|
453
|
+
```js
|
|
454
|
+
mapbox.setTilt(
|
|
455
|
+
{
|
|
456
|
+
tilt: 40, // default 30 (degrees angle)
|
|
457
|
+
duration: 4000 // default 5000 (milliseconds)
|
|
458
|
+
}
|
|
459
|
+
)
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### getTilt (Android only)
|
|
463
|
+
```js
|
|
464
|
+
mapbox.getTilt().then(
|
|
465
|
+
function(tilt) {
|
|
466
|
+
console.log("Current map tilt: " + tilt);
|
|
467
|
+
}
|
|
468
|
+
)
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### getUserLocation
|
|
472
|
+
If the user's location is shown on the map you can get their coordinates and speed:
|
|
473
|
+
|
|
474
|
+
```js
|
|
475
|
+
mapbox.getUserLocation().then(
|
|
476
|
+
function(userLocation) {
|
|
477
|
+
console.log("Current user location: " + userLocation.location.lat + ", " + userLocation.location.lng);
|
|
478
|
+
console.log("Current user speed: " + userLocation.speed);
|
|
479
|
+
}
|
|
480
|
+
)
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### trackUser
|
|
484
|
+
In case you're showing the user's location, you can have the map track the position.
|
|
485
|
+
The map will continuously move along with the last known location.
|
|
486
|
+
|
|
487
|
+
```js
|
|
488
|
+
mapbox.trackUser({
|
|
489
|
+
mode: "FOLLOW_WITH_HEADING", // "NONE" | "FOLLOW" | "FOLLOW_WITH_HEADING" | "FOLLOW_WITH_COURSE"
|
|
490
|
+
animated: true
|
|
491
|
+
});
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
### addSource
|
|
495
|
+
|
|
496
|
+
https://docs.mapbox.com/mapbox-gl-js/api/#map#addsource
|
|
497
|
+
|
|
498
|
+
Supported source types:
|
|
499
|
+
- Vector
|
|
500
|
+
- GeoJson
|
|
501
|
+
- Raster
|
|
502
|
+
|
|
503
|
+
Adds a vector to GeoJSON source to the map.
|
|
504
|
+
|
|
505
|
+
```js
|
|
506
|
+
mapbox.addSource( id, {
|
|
507
|
+
type: 'vector',
|
|
508
|
+
url: 'url to source'
|
|
509
|
+
} );
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
-or-
|
|
513
|
+
|
|
514
|
+
```js
|
|
515
|
+
mapbox.addSource( id, {
|
|
516
|
+
'type': 'geojson',
|
|
517
|
+
'data': {
|
|
518
|
+
"type": "Feature",
|
|
519
|
+
"geometry": {
|
|
520
|
+
"type": "LineString",
|
|
521
|
+
"coordinates": [ [ lng, lat ], [ lng, lat ], ..... ]
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
);
|
|
526
|
+
```
|
|
527
|
+
### removeSource
|
|
528
|
+
|
|
529
|
+
Remove a source by id
|
|
530
|
+
|
|
531
|
+
```js
|
|
532
|
+
mapbox.removeSource( id );
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
### addLayer
|
|
536
|
+
https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers
|
|
537
|
+
|
|
538
|
+
Supported layer types:
|
|
539
|
+
- Line
|
|
540
|
+
- Circle
|
|
541
|
+
- Fill
|
|
542
|
+
- Symbol
|
|
543
|
+
- Raster
|
|
544
|
+
|
|
545
|
+
To add a line:
|
|
546
|
+
|
|
547
|
+
```js
|
|
548
|
+
mapbox.addLayer({
|
|
549
|
+
'id': someid,
|
|
550
|
+
'type': 'line',
|
|
551
|
+
'source': {
|
|
552
|
+
'type': 'geojson',
|
|
553
|
+
'data': {
|
|
554
|
+
"type": "Feature",
|
|
555
|
+
"geometry": {
|
|
556
|
+
"type": "LineString",
|
|
557
|
+
"coordinates": [ [ lng, lat ], [ lng, lat ], ..... ]
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
'layout': {
|
|
563
|
+
'line-cap': 'round',
|
|
564
|
+
'line-join': 'round'
|
|
565
|
+
},
|
|
566
|
+
'paint': {
|
|
567
|
+
'line-color': '#ed6498',
|
|
568
|
+
'line-width': 5,
|
|
569
|
+
'line-opacity': .8,
|
|
570
|
+
'line-dash-array': [ 1, 1, 1, ..]
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
To add a circle:
|
|
576
|
+
|
|
577
|
+
```js
|
|
578
|
+
mapbox.addLayer({
|
|
579
|
+
"id": someid,
|
|
580
|
+
"type": 'circle',
|
|
581
|
+
"source": {
|
|
582
|
+
"type": 'geojson',
|
|
583
|
+
"data": {
|
|
584
|
+
"type": "Feature",
|
|
585
|
+
"geometry": {
|
|
586
|
+
"type": "Point",
|
|
587
|
+
"coordinates": [ lng, lat ]
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
},
|
|
591
|
+
"paint": {
|
|
592
|
+
"circle-radius": {
|
|
593
|
+
"stops": [
|
|
594
|
+
[0, 0],
|
|
595
|
+
[20, 8000 ]
|
|
596
|
+
],
|
|
597
|
+
"base": 2
|
|
598
|
+
},
|
|
599
|
+
'circle-opacity': 0.05,
|
|
600
|
+
'circle-color': '#ed6498',
|
|
601
|
+
'circle-stroke-width': 2,
|
|
602
|
+
'circle-stroke-color': '#ed6498'
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
Source may be a geojson or vector source description or may be
|
|
608
|
+
the id of a source added using addSource()
|
|
609
|
+
|
|
610
|
+
### removeLayer
|
|
611
|
+
Remove a layer added with addLayer() by id.
|
|
612
|
+
|
|
613
|
+
```js
|
|
614
|
+
mapbox.removeLayer( id );
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
### queryRenderedFeatures
|
|
618
|
+
https://docs.mapbox.com/mapbox-gl-js/api/map/#map#queryrenderedfeatures
|
|
619
|
+
Returns an array of GeoJSON Feature objects representing visible features that satisfy the query parameters.
|
|
620
|
+
|
|
621
|
+
```js
|
|
622
|
+
mapbox
|
|
623
|
+
.queryRenderedFeatures({
|
|
624
|
+
point: {
|
|
625
|
+
lat: 52.3701494345567,
|
|
626
|
+
lng: 4.823684692382513,
|
|
627
|
+
},
|
|
628
|
+
layers: ['circle-with-source-object'],
|
|
629
|
+
filter: ['==', ['get', 'querySample'], '2'],
|
|
630
|
+
})
|
|
631
|
+
.then((result) => console.log('query rendered features', result))
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
### querySourceFeatures
|
|
635
|
+
https://docs.mapbox.com/mapbox-gl-js/api/map/#map#querysourcefeatures
|
|
636
|
+
Returns an array of GeoJSON Feature objects representing features within the specified vector tile or GeoJSON source that satisfy the query parameters.
|
|
637
|
+
|
|
638
|
+
```js
|
|
639
|
+
mapbox
|
|
640
|
+
.querySourceFeatures('source_id', { filter: ['==', ['get', 'querySample'], '2'] })
|
|
641
|
+
.then((result) => console.log('query source features', result));
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
### addLinePoint
|
|
645
|
+
Dynamically add a point to a line.
|
|
646
|
+
|
|
647
|
+
```js
|
|
648
|
+
mapbox.addLinePoint( <id of line layer>, lnglat )
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
where lnglat is an array of two points, a longitude and a latitude.
|
|
652
|
+
|
|
653
|
+
### addPolygon (**deprecated**, use addLayer() instead)
|
|
654
|
+
|
|
655
|
+
Draw a shape. Just connect the dots like we did as a toddler.
|
|
656
|
+
|
|
657
|
+
The first person to tweet a snowman drawn with this function gets a T-shirt (from @eddyverbruggen ;-)).
|
|
658
|
+
|
|
659
|
+
```typescript
|
|
660
|
+
// after adding this, scroll to Amsterdam to see a semi-transparent red square
|
|
661
|
+
mapbox.addPolygon(
|
|
662
|
+
{
|
|
663
|
+
id: 1, // optional, can be used in 'removePolygons'
|
|
664
|
+
fillColor: new Color("red"),
|
|
665
|
+
fillOpacity: 0.7,
|
|
666
|
+
|
|
667
|
+
// stroke-related properties are only effective on iOS
|
|
668
|
+
strokeColor: new Color("green"),
|
|
669
|
+
strokeWidth: 8,
|
|
670
|
+
strokeOpacity: 0.5,
|
|
671
|
+
|
|
672
|
+
points: [
|
|
673
|
+
{
|
|
674
|
+
lat: 52.3923633970718,
|
|
675
|
+
lng: 4.902648925781249
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
lat: 52.35421556258807,
|
|
679
|
+
lng: 4.9308013916015625
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
lat: 52.353796172573944,
|
|
683
|
+
lng: 4.8799896240234375
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
lat: 52.3864966440161,
|
|
687
|
+
lng: 4.8621368408203125
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
lat: 52.3923633970718,
|
|
691
|
+
lng: 4.902648925781249
|
|
692
|
+
}
|
|
693
|
+
]
|
|
694
|
+
})
|
|
695
|
+
.then(result => console.log("Mapbox addPolygon done"))
|
|
696
|
+
.catch((error: string) => console.log("mapbox addPolygon error: " + error));
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
### removePolygons
|
|
700
|
+
You can either remove all polygons by not passing in an argument,
|
|
701
|
+
or remove specific polygon id's (which you specified previously).
|
|
702
|
+
|
|
703
|
+
```js
|
|
704
|
+
// remove all polygons
|
|
705
|
+
mapbox.removePolygons();
|
|
706
|
+
|
|
707
|
+
// remove specific polygons by id
|
|
708
|
+
mapbox.removePolygons([1, 2]);
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
### addPolyline
|
|
712
|
+
Deprecated. Use addLayer() instead.
|
|
713
|
+
|
|
714
|
+
Draw a polyline. Connect the points given as parameters.
|
|
715
|
+
|
|
716
|
+
```js
|
|
717
|
+
// Draw a two segment line near Amsterdam Central Station
|
|
718
|
+
mapbox.addPolyline({
|
|
719
|
+
id: 1, // optional, can be used in 'removePolylines'
|
|
720
|
+
color: '#336699', // Set the color of the line (default black)
|
|
721
|
+
width: 7, // Set the width of the line (default 5)
|
|
722
|
+
opacity: 0.6, //Transparency / alpha, ranging 0-1. Default fully opaque (1).
|
|
723
|
+
points: [
|
|
724
|
+
{
|
|
725
|
+
'lat': 52.3833160, // mandatory
|
|
726
|
+
'lng': 4.8991780 // mandatory
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
'lat': 52.3834160,
|
|
730
|
+
'lng': 4.8991880
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
'lat': 52.3835160,
|
|
734
|
+
'lng': 4.8991980
|
|
735
|
+
}
|
|
736
|
+
]
|
|
737
|
+
});
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
### removePolylines
|
|
741
|
+
Deprecated. Use removeLayer() instead.
|
|
742
|
+
|
|
743
|
+
You can either remove all polylines by not passing in an argument,
|
|
744
|
+
or remove specific polyline id's (which you specified previously).
|
|
745
|
+
|
|
746
|
+
```js
|
|
747
|
+
// remove all polylines
|
|
748
|
+
mapbox.removePolylines();
|
|
749
|
+
|
|
750
|
+
// remove specific polylines by id
|
|
751
|
+
mapbox.removePolylines([1, 2]);
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
### setOnMapClickListener
|
|
755
|
+
Add a listener to retrieve lat and lng of where the user taps the map (not a marker).
|
|
756
|
+
|
|
757
|
+
```typescript
|
|
758
|
+
mapbox.setOnMapClickListener((point: LatLng) => {
|
|
759
|
+
console.log("Map clicked at latitude: " + point.lat + ", longitude: " + point.lng);
|
|
760
|
+
});
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
### setOnMapLongClickListener
|
|
764
|
+
Add a listener to retrieve lat and lng of where the user longpresses the map (not a marker).
|
|
765
|
+
|
|
766
|
+
```typescript
|
|
767
|
+
mapbox.setOnMapLongClickListener((point: LatLng) => {
|
|
768
|
+
console.log("Map longpressed at latitude: " + point.lat + ", longitude: " + point.lng);
|
|
769
|
+
});
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
### setOnScrollListener
|
|
773
|
+
Add a listener to retrieve lat and lng of where the user scrolls to on the map.
|
|
774
|
+
|
|
775
|
+
```typescript
|
|
776
|
+
mapbox.setOnScrollListener((point?: LatLng) => {
|
|
777
|
+
console.log("Map scrolled to latitude: " + point.lat + ", longitude: " + point.lng);
|
|
778
|
+
});
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
## Offline maps
|
|
782
|
+
For situations where you want the user to pre-load certain regions you can use these methods to create and remove offline regions.
|
|
783
|
+
|
|
784
|
+
__Important read:__ [the offline maps documentation by Mapbox](https://www.mapbox.com/help/mobile-offline/).
|
|
785
|
+
|
|
786
|
+
### downloadOfflineRegion
|
|
787
|
+
This example downloads the region 'Amsterdam' on zoom levels 9, 10 and 11 for map style 'outdoors'.
|
|
788
|
+
|
|
789
|
+
```js
|
|
790
|
+
mapbox.downloadOfflineRegion(
|
|
791
|
+
{
|
|
792
|
+
accessToken: accessToken, // required for Android in case no map has been shown yet
|
|
793
|
+
name: "Amsterdam", // this name can be used to delete the region later
|
|
794
|
+
style: mapbox.MapStyle.OUTDOORS,
|
|
795
|
+
minZoom: 9,
|
|
796
|
+
maxZoom: 11,
|
|
797
|
+
bounds: {
|
|
798
|
+
north: 52.4820,
|
|
799
|
+
east: 5.1087,
|
|
800
|
+
south: 52.2581,
|
|
801
|
+
west: 4.6816
|
|
802
|
+
},
|
|
803
|
+
// this function is called many times during a download, so
|
|
804
|
+
// use it to show an awesome progress bar!
|
|
805
|
+
onProgress: function (progress) {
|
|
806
|
+
console.log("Download progress: " + JSON.stringify(progress));
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
).then(
|
|
810
|
+
function() {
|
|
811
|
+
console.log("Offline region downloaded");
|
|
812
|
+
},
|
|
813
|
+
function(error) {
|
|
814
|
+
console.log("Download error: " + error);
|
|
815
|
+
}
|
|
816
|
+
);
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
#### Advanced example: download the current viewport
|
|
820
|
+
Grab the viewport with the `mapbox.getViewport()` function and download it at various zoom levels:
|
|
821
|
+
|
|
822
|
+
```js
|
|
823
|
+
// I spare you the error handling on this one..
|
|
824
|
+
mapbox.getViewport().then(function(viewport) {
|
|
825
|
+
mapbox.downloadOfflineRegion(
|
|
826
|
+
{
|
|
827
|
+
name: "LastViewport", // anything you like really
|
|
828
|
+
style: mapbox.MapStyle.LIGHT,
|
|
829
|
+
minZoom: viewport.zoomLevel,
|
|
830
|
+
maxZoom: viewport.zoomLevel + 2, // higher zoom level is lower to the ground
|
|
831
|
+
bounds: viewport.bounds,
|
|
832
|
+
onProgress: function (progress) {
|
|
833
|
+
console.log("Download %: " + progress.percentage);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
);
|
|
837
|
+
});
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
### listOfflineRegions
|
|
841
|
+
To help you manage offline regions there's a `listOfflineRegions` function you can use. You can then fi. call `deleteOfflineRegion` (see below) and pass in the `name` to remove any cached region(s) you like.
|
|
842
|
+
|
|
843
|
+
```js
|
|
844
|
+
mapbox.listOfflineRegions({
|
|
845
|
+
// required for Android in case no map has been shown yet
|
|
846
|
+
accessToken: accessToken
|
|
847
|
+
}).then(
|
|
848
|
+
function(regions) {
|
|
849
|
+
console.log(JSON.stringify(JSON.stringify(regions));
|
|
850
|
+
},
|
|
851
|
+
function(error) {
|
|
852
|
+
console.log("Error while listing offline regions: " + error);
|
|
853
|
+
}
|
|
854
|
+
);
|
|
855
|
+
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
### deleteOfflineRegion
|
|
859
|
+
You can remove regions you've previously downloaded. Any region(s) matching the `name` param will be removed locally.
|
|
860
|
+
|
|
861
|
+
```js
|
|
862
|
+
mapbox.deleteOfflineRegion({
|
|
863
|
+
name: "Amsterdam"
|
|
864
|
+
}).then(
|
|
865
|
+
function() {
|
|
866
|
+
console.log("Offline region deleted");
|
|
867
|
+
},
|
|
868
|
+
function(error) {
|
|
869
|
+
console.log("Error while deleting an offline region: " + error);
|
|
870
|
+
}
|
|
871
|
+
);
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
## Permissions
|
|
876
|
+
|
|
877
|
+
### hasFineLocationPermission / requestFineLocationPermission
|
|
878
|
+
On Android 6 you need to request permission to be able to show the user's position on the map at runtime when targeting API level 23+.
|
|
879
|
+
Even if the `uses-permission` tag for `ACCESS_FINE_LOCATION` is present in `AndroidManifest.xml`.
|
|
880
|
+
|
|
881
|
+
**You don't need to do this with plugin version 2.4.0+ as permission is request when required while rendering the map. You're welcome :)**
|
|
882
|
+
|
|
883
|
+
Note that `hasFineLocationPermission` will return true when:
|
|
884
|
+
* You're running this on iOS, or
|
|
885
|
+
* You're targeting an API level lower than 23, or
|
|
886
|
+
* You're using Android < 6, or
|
|
887
|
+
* You've already granted permission.
|
|
888
|
+
|
|
889
|
+
```js
|
|
890
|
+
mapbox.hasFineLocationPermission().then(
|
|
891
|
+
function(granted) {
|
|
892
|
+
// if this is 'false' you probably want to call 'requestFineLocationPermission' now
|
|
893
|
+
console.log("Has Location Permission? " + granted);
|
|
894
|
+
}
|
|
895
|
+
);
|
|
896
|
+
|
|
897
|
+
// if no permission was granted previously this will open a user consent screen
|
|
898
|
+
mapbox.requestFineLocationPermission().then(
|
|
899
|
+
function() {
|
|
900
|
+
console.log("Location permission requested");
|
|
901
|
+
}
|
|
902
|
+
);
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
Note that the `show` function will also check for permission if you passed in `showUserLocation : true`.
|
|
906
|
+
If you didn't request permission before showing the map, and permission was needed, the plugin will ask the user permission while rendering the map.
|
|
907
|
+
|
|
908
|
+
## Using marker images from the internet
|
|
909
|
+
If you specify `icon: 'http(s)://some-remote-image'`, then on iOS you'll need to whitelist
|
|
910
|
+
the domain. Google for iOS ATS for detailed options, but for a quick test you can add this to
|
|
911
|
+
`app/App_Resources/iOS/Info.plist`:
|
|
912
|
+
|
|
913
|
+
```xml
|
|
914
|
+
<key>NSAppTransportSecurity</key>
|
|
915
|
+
<dict>
|
|
916
|
+
<key>NSAllowsArbitraryLoads</key>
|
|
917
|
+
<true/>
|
|
918
|
+
</dict>
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
{{ load:../../tools/readme/demos-and-development.md }}
|
|
922
|
+
{{ load:../../tools/readme/questions.md }}
|
package/common.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContentView, Property, Trace, booleanConverter } from '@nativescript/core';
|
|
1
|
+
import { Color, ContentView, ImageSource, Property, Trace, booleanConverter } from '@nativescript/core';
|
|
2
2
|
export * from './geo.utils';
|
|
3
3
|
export * from './expression/expression-parser';
|
|
4
4
|
export * from './layers/layer-factory';
|
package/index.android.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { request } from '@nativescript-community/perms';
|
|
2
|
-
import { AndroidApplication, Application, Color, File, Http, ImageSource, Trace, Utils, knownFolders, path } from '@nativescript/core';
|
|
2
|
+
import { AndroidApplication, Application, Color, File, Http, Image, ImageSource, Trace, Utils, knownFolders, path } from '@nativescript/core';
|
|
3
3
|
import { ExpressionParser } from './expression/expression-parser';
|
|
4
4
|
import { Layer, LayerFactory } from './layers/layer-factory';
|
|
5
|
-
import { CLog, CLogTypes, MapStyle, MapboxCommon, MapboxViewBase, telemetryProperty } from './common';
|
|
5
|
+
import { CLog, CLogTypes, MapStyle, MapboxCommon, MapboxTraceCategory, MapboxViewBase, telemetryProperty } from './common';
|
|
6
6
|
export * from './common';
|
|
7
7
|
function _getLocation(loc) {
|
|
8
8
|
if (loc === null) {
|
|
@@ -843,13 +843,13 @@ export class Mapbox extends MapboxCommon {
|
|
|
843
843
|
markerOptions.setPosition(new com.mapbox.mapboxsdk.geometry.LatLng(parseFloat(marker.lat), parseFloat(marker.lng)));
|
|
844
844
|
if (marker.icon) {
|
|
845
845
|
if (marker.icon.startsWith('res://')) {
|
|
846
|
-
let cached = this.iconCache[marker.
|
|
846
|
+
let cached = this.iconCache[marker.icon];
|
|
847
847
|
if (!cached) {
|
|
848
848
|
const resourcename = marker.icon.substring(6);
|
|
849
849
|
const res = Utils.ad.getApplicationContext().getResources();
|
|
850
850
|
const identifier = res.getIdentifier(resourcename, 'drawable', Utils.ad.getApplication().getPackageName());
|
|
851
851
|
if (identifier !== 0) {
|
|
852
|
-
cached = this.iconCache[marker.
|
|
852
|
+
cached = this.iconCache[marker.icon] = iconFactory.fromResource(identifier);
|
|
853
853
|
}
|
|
854
854
|
}
|
|
855
855
|
if (cached) {
|
package/index.ios.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Color, File, Http, ImageSource, Trace, Utils, knownFolders, path } from '@nativescript/core';
|
|
2
|
-
import { CLog, CLogTypes, MapStyle, MapboxCommon, MapboxViewBase, telemetryProperty } from './common';
|
|
2
|
+
import { CLog, CLogTypes, MapStyle, MapboxCommon, MapboxTraceCategory, MapboxViewBase, telemetryProperty } from './common';
|
|
3
3
|
import { Layer, LayerFactory } from './layers/layer-factory';
|
|
4
4
|
import { ExpressionParser } from './expression/expression-parser';
|
|
5
5
|
var MGLMapViewDelegateImpl = /** @class */ (function (_super) {
|
|
@@ -42,7 +42,7 @@ var MGLMapViewDelegateImpl = /** @class */ (function (_super) {
|
|
|
42
42
|
* set user location marker modes
|
|
43
43
|
*/
|
|
44
44
|
MGLMapViewDelegateImpl.prototype.changeUserLocationRenderMode = function (userLocationRenderMode) {
|
|
45
|
-
|
|
45
|
+
// nothing to do here
|
|
46
46
|
};
|
|
47
47
|
/**
|
|
48
48
|
* set the camera changd listener callback
|
|
@@ -234,19 +234,6 @@ var MGLMapViewDelegateImpl = /** @class */ (function (_super) {
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
|
-
/**
|
|
238
|
-
* override the standard location marker
|
|
239
|
-
*/
|
|
240
|
-
MGLMapViewDelegateImpl.prototype.mapViewViewForAnnotation = function (mapView, annotation) {
|
|
241
|
-
if (Trace.isEnabled()) {
|
|
242
|
-
CLog(CLogTypes.info, 'MGLMapViewDelegateImpl::mapViewViewForAnnotation() top');
|
|
243
|
-
}
|
|
244
|
-
if (annotation.isKindOfClass(MGLUserLocation.class())) {
|
|
245
|
-
this.userLocationAnnotationView = CustomUserLocationAnnotationView.alloc().init();
|
|
246
|
-
return this.userLocationAnnotationView;
|
|
247
|
-
}
|
|
248
|
-
return null;
|
|
249
|
-
};
|
|
250
237
|
MGLMapViewDelegateImpl.prototype.mapViewRegionIsChangingWithReason = function (mapView, reason) {
|
|
251
238
|
if (Trace.isEnabled()) {
|
|
252
239
|
CLog(CLogTypes.info, 'MGLMapViewDelegateImpl::mapViewRegionIsChanging()');
|
|
@@ -658,214 +645,6 @@ export class MapboxView extends MapboxViewBase {
|
|
|
658
645
|
NSUserDefaults.standardUserDefaults.setBoolForKey(false, 'MGLMapboxMetricsEnabled');
|
|
659
646
|
}
|
|
660
647
|
}
|
|
661
|
-
var CustomUserLocationAnnotationView = /** @class */ (function (_super) {
|
|
662
|
-
__extends(CustomUserLocationAnnotationView, _super);
|
|
663
|
-
function CustomUserLocationAnnotationView() {
|
|
664
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* init
|
|
668
|
-
*
|
|
669
|
-
* @link https://docs.nativescript.org/core-concepts/ios-runtime/HelloWorld
|
|
670
|
-
*/
|
|
671
|
-
CustomUserLocationAnnotationView.prototype.init = function () {
|
|
672
|
-
this.size = 48;
|
|
673
|
-
_super.prototype.initWithFrame.call(this, CGRectMake(0, 0, this.size, this.size));
|
|
674
|
-
this.renderModeChanged = true;
|
|
675
|
-
this.userLocationRenderMode = 'NORMAL';
|
|
676
|
-
return this;
|
|
677
|
-
};
|
|
678
|
-
/**
|
|
679
|
-
* update
|
|
680
|
-
*
|
|
681
|
-
* The note from the Objective-C sample indicates this method may be called quite
|
|
682
|
-
* often so it needs to be kept lightweight.
|
|
683
|
-
*/
|
|
684
|
-
CustomUserLocationAnnotationView.prototype.update = function () {
|
|
685
|
-
if (CLLocationCoordinate2DIsValid(this.userLocation.coordinate)) {
|
|
686
|
-
// if it's the first time here, setup the layers that make up the
|
|
687
|
-
// location marker.
|
|
688
|
-
if (!this.dot) {
|
|
689
|
-
this.drawNonTrackingLocationMarker();
|
|
690
|
-
}
|
|
691
|
-
if (this.userLocationRenderMode === 'GPS') {
|
|
692
|
-
this.updateHeading();
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
/**
|
|
697
|
-
* Draw the GPS tracking arrow.
|
|
698
|
-
*
|
|
699
|
-
* @link https://docs.nativescript.org/ns-framework-modules/color
|
|
700
|
-
*/
|
|
701
|
-
CustomUserLocationAnnotationView.prototype.drawTrackingLocationMarker = function () {
|
|
702
|
-
if (Trace.isEnabled()) {
|
|
703
|
-
CLog(CLogTypes.info, 'CustomerUserLocationAnnotatinView::drawTrackingLocationMarker()');
|
|
704
|
-
}
|
|
705
|
-
this.drawTrackingDot();
|
|
706
|
-
this.drawArrow();
|
|
707
|
-
}; // end of setupLayers()
|
|
708
|
-
/**
|
|
709
|
-
* draw the non-tracking marker
|
|
710
|
-
*/
|
|
711
|
-
CustomUserLocationAnnotationView.prototype.drawNonTrackingLocationMarker = function () {
|
|
712
|
-
if (Trace.isEnabled()) {
|
|
713
|
-
CLog(CLogTypes.info, 'CustomerUserLocationAnnotatinView::drawNonTrackingLocationMarker()');
|
|
714
|
-
}
|
|
715
|
-
this.drawNonTrackingDot();
|
|
716
|
-
if (this.arrow) {
|
|
717
|
-
this.arrow.removeFromSuperlayer();
|
|
718
|
-
this.arrow = null;
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
/**
|
|
722
|
-
* draw the tracking dot.
|
|
723
|
-
*/
|
|
724
|
-
CustomUserLocationAnnotationView.prototype.drawTrackingDot = function () {
|
|
725
|
-
this.size = 48;
|
|
726
|
-
// we need to adjust the size of the bounds of the marker. The Tracking marker
|
|
727
|
-
// is larger than the non tracking marker.
|
|
728
|
-
this.bounds = CGRectMake(0, 0, this.size, this.size);
|
|
729
|
-
var dot = CALayer.layer();
|
|
730
|
-
dot.frame = this.bounds;
|
|
731
|
-
// user corner radius to turn the layer into a circle
|
|
732
|
-
dot.cornerRadius = this.size / 2;
|
|
733
|
-
dot.backgroundColor = this.tintColor.CGColor;
|
|
734
|
-
dot.borderWidth = 4;
|
|
735
|
-
var whiteColor = new Color('#FFFFFF');
|
|
736
|
-
dot.borderColor = whiteColor.ios.CGColor;
|
|
737
|
-
if (!this.dot) {
|
|
738
|
-
this.layer.addSublayer(dot);
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
this.layer.replaceSublayerWith(this.dot, dot);
|
|
742
|
-
}
|
|
743
|
-
// QUESTION: does GC catch this?
|
|
744
|
-
this.dot = dot;
|
|
745
|
-
};
|
|
746
|
-
/**
|
|
747
|
-
* draw the non-tracking dot.
|
|
748
|
-
*/
|
|
749
|
-
CustomUserLocationAnnotationView.prototype.drawNonTrackingDot = function () {
|
|
750
|
-
this.size = 24;
|
|
751
|
-
this.bounds = CGRectMake(0, 0, this.size, this.size);
|
|
752
|
-
var dot = CALayer.layer();
|
|
753
|
-
dot.frame = this.bounds;
|
|
754
|
-
// user corner radius to turn the layer into a circle
|
|
755
|
-
dot.cornerRadius = this.size / 2;
|
|
756
|
-
dot.backgroundColor = this.tintColor.CGColor;
|
|
757
|
-
dot.borderWidth = 1;
|
|
758
|
-
var whiteColor = new Color('#FFFFFF');
|
|
759
|
-
dot.borderColor = whiteColor.ios.CGColor;
|
|
760
|
-
if (!this.dot) {
|
|
761
|
-
this.layer.addSublayer(dot);
|
|
762
|
-
}
|
|
763
|
-
else {
|
|
764
|
-
this.layer.replaceSublayerWith(this.dot, dot);
|
|
765
|
-
}
|
|
766
|
-
// QUESTION: does GC catch this?
|
|
767
|
-
this.dot = dot;
|
|
768
|
-
};
|
|
769
|
-
/**
|
|
770
|
-
* draw an arrow
|
|
771
|
-
*/
|
|
772
|
-
CustomUserLocationAnnotationView.prototype.drawArrow = function () {
|
|
773
|
-
var arrow = CAShapeLayer.layer();
|
|
774
|
-
arrow.path = this.arrowPath();
|
|
775
|
-
arrow.frame = CGRectMake(0, 0, this.size / 2, this.size / 2);
|
|
776
|
-
arrow.position = CGPointMake(CGRectGetMidX(this.dot.frame), CGRectGetMidY(this.dot.frame));
|
|
777
|
-
arrow.fillColor = this.dot.borderColor;
|
|
778
|
-
if (!this.arrow) {
|
|
779
|
-
this.layer.addSublayer(arrow);
|
|
780
|
-
}
|
|
781
|
-
else {
|
|
782
|
-
this.layer.replaceSublayerWith(this.arrow, arrow);
|
|
783
|
-
}
|
|
784
|
-
// QUESTION: Does GC catch this?
|
|
785
|
-
this.arrow = arrow;
|
|
786
|
-
};
|
|
787
|
-
/**
|
|
788
|
-
* update arrow heading
|
|
789
|
-
*
|
|
790
|
-
* @link https://docs.nativescript.org/core-concepts/ios-runtime/types/C-Functions
|
|
791
|
-
*/
|
|
792
|
-
CustomUserLocationAnnotationView.prototype.updateHeading = function () {
|
|
793
|
-
// just to avoid a possible race condition where the arrow isnt' drawn yet
|
|
794
|
-
if (!this.arrow) {
|
|
795
|
-
return;
|
|
796
|
-
}
|
|
797
|
-
if (typeof this.userLocation == 'undefined') {
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
if (typeof this.userLocation.heading == 'undefined' || this.userLocation.heading === null) {
|
|
801
|
-
return;
|
|
802
|
-
}
|
|
803
|
-
if (typeof this.userLocation.heading.trueHeading == 'undefined' || this.userLocation.heading.trueHeading === null) {
|
|
804
|
-
return;
|
|
805
|
-
}
|
|
806
|
-
if (this.userLocation.heading.trueHeading > 0) {
|
|
807
|
-
this.arrow.hidden = false;
|
|
808
|
-
// get the difference between the map's current direction and the
|
|
809
|
-
// user's heading, then convert it from degrees to radians
|
|
810
|
-
//
|
|
811
|
-
// The original Objective-C example uses the inline C function MGLRadiansFromDegrees but because
|
|
812
|
-
// it's declared as inline it is not available for NativeScript. See linked article above.
|
|
813
|
-
// let rotation : number = MGLRadiansFromDegrees( this.mapView.direction - this.userLocation.heading.trueHeading );
|
|
814
|
-
var degrees = this.mapView.direction - this.userLocation.heading.trueHeading;
|
|
815
|
-
// in radians
|
|
816
|
-
var rotation = (degrees * Math.PI) / 180;
|
|
817
|
-
rotation = -rotation;
|
|
818
|
-
// if the difference would be perceptible, rotate the arrow.
|
|
819
|
-
if (fabs(rotation) > 0.01) {
|
|
820
|
-
// Disable implicit animations of this rotation, which reduces lag between updates
|
|
821
|
-
CATransaction.begin();
|
|
822
|
-
CATransaction.setDisableActions(true);
|
|
823
|
-
this.arrow.setAffineTransform(CGAffineTransformRotate(CGAffineTransformIdentity, rotation));
|
|
824
|
-
CATransaction.commit();
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
else {
|
|
828
|
-
this.arrow.hidden = true;
|
|
829
|
-
}
|
|
830
|
-
};
|
|
831
|
-
/**
|
|
832
|
-
* Calculate the vector path for an arrow
|
|
833
|
-
*/
|
|
834
|
-
CustomUserLocationAnnotationView.prototype.arrowPath = function () {
|
|
835
|
-
var max = this.size / 2;
|
|
836
|
-
var pad = 3;
|
|
837
|
-
var top = CGPointMake(max * 0.5, 0);
|
|
838
|
-
var left = CGPointMake(0 + pad, max - pad);
|
|
839
|
-
var right = CGPointMake(max - pad, max - pad);
|
|
840
|
-
var center = CGPointMake(max * 0.5, max * 0.6);
|
|
841
|
-
var bezierPath = UIBezierPath.bezierPath();
|
|
842
|
-
bezierPath.moveToPoint(top);
|
|
843
|
-
bezierPath.addLineToPoint(left);
|
|
844
|
-
bezierPath.addLineToPoint(center);
|
|
845
|
-
bezierPath.addLineToPoint(right);
|
|
846
|
-
bezierPath.addLineToPoint(top);
|
|
847
|
-
bezierPath.closePath();
|
|
848
|
-
return bezierPath.CGPath;
|
|
849
|
-
};
|
|
850
|
-
/**
|
|
851
|
-
* change Render mode
|
|
852
|
-
*
|
|
853
|
-
* @param {string} renderMode
|
|
854
|
-
*/
|
|
855
|
-
CustomUserLocationAnnotationView.prototype.changeUserLocationRenderMode = function (renderMode) {
|
|
856
|
-
if (Trace.isEnabled()) {
|
|
857
|
-
CLog(CLogTypes.info, "CustomUserLocationAnnotatinView::changeUserLocationRenderMode(): changing mode to '" + renderMode + "'");
|
|
858
|
-
}
|
|
859
|
-
this.userLocationRenderMode = renderMode;
|
|
860
|
-
if (renderMode === 'GPS') {
|
|
861
|
-
this.drawTrackingLocationMarker();
|
|
862
|
-
}
|
|
863
|
-
else {
|
|
864
|
-
this.drawNonTrackingLocationMarker();
|
|
865
|
-
}
|
|
866
|
-
};
|
|
867
|
-
return CustomUserLocationAnnotationView;
|
|
868
|
-
}(MGLUserLocationAnnotationView));
|
|
869
648
|
export class Mapbox extends MapboxCommon {
|
|
870
649
|
constructor() {
|
|
871
650
|
super(...arguments);
|
|
@@ -2343,7 +2122,7 @@ export class Mapbox extends MapboxCommon {
|
|
|
2343
2122
|
return;
|
|
2344
2123
|
}
|
|
2345
2124
|
const layer = theMap.style.layerWithIdentifier(name);
|
|
2346
|
-
resolve(new Layer(layer));
|
|
2125
|
+
resolve(layer ? new Layer(layer) : null);
|
|
2347
2126
|
}
|
|
2348
2127
|
catch (ex) {
|
|
2349
2128
|
if (Trace.isEnabled()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nativescript-community/ui-mapbox",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.19",
|
|
4
4
|
"description": "Interactive, thoroughly customizable maps powered by vector tiles and OpenGL.",
|
|
5
5
|
"main": "index",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@nativescript-community/perms": "^2.2.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "ee66b091255e4c94685c927f8ab652ad66b5a5be"
|
|
58
58
|
}
|
|
Binary file
|