diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0007f93..f0b10c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,14 @@
[iOS SDK](https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/CHANGELOG.md)
-## [4.1.0](https://github.com/EddyVerbruggen/nativescript-mapbox/tree/4.1.0) (2018-06-28)
+## [4.1.1](https://github.com/EddyVerbruggen/nativescript-mapbox/tree/4.1.1) (2018-07-03)
+[Full Changelog](https://github.com/EddyVerbruggen/nativescript-mapbox/compare/4.1.0...4.1.1)
+
+**Implemented enhancements:**
+
+- Add a method to remove polygons [\#237](https://github.com/EddyVerbruggen/nativescript-mapbox/issues/237)
+
+## [4.1.0](https://github.com/EddyVerbruggen/nativescript-mapbox/tree/4.1.0) (2018-07-02)
[Full Changelog](https://github.com/EddyVerbruggen/nativescript-mapbox/compare/4.0.0...4.1.0)
**Fixed bugs:**
diff --git a/README.md b/README.md
index c6d1561..e5ec9ae 100755
--- a/README.md
+++ b/README.md
@@ -185,7 +185,7 @@ exports.onMapReady = onMapReady;
```
The methods you can invoke like this from an XML-declared map are:
-`addMarkers`, `setViewport`, `removeMarkers`, `getCenter`, `setCenter`, `getZoomLevel`, `setZoomLevel`, `getViewport`, `getTilt`, `setTilt`, `setMapStyle`, `animateCamera`, `addPolygon`, `addPolyline`, `removePolylines`, `getUserLocation`, `trackUser`, `setOnMapClickListener` and `destroy`.
+`addMarkers`, `setViewport`, `removeMarkers`, `getCenter`, `setCenter`, `getZoomLevel`, `setZoomLevel`, `getViewport`, `getTilt`, `setTilt`, `setMapStyle`, `animateCamera`, `addPolygon`, `removePolygons`, `addPolyline`, `removePolylines`, `getUserLocation`, `trackUser`, `setOnMapClickListener` and `destroy`.
Check out the usage details on the functions below.
@@ -458,7 +458,7 @@ The first person to tweet a snowman drawn with this function gets a T-shirt.
// after adding this, scroll to Amsterdam to see a semi-transparent red square
mapbox.addPolygon(
{
- id: 1,
+ id: 1, // optional, can be used in 'removePolygons'
fillColor: new Color("red"),
fillOpacity: 0.7,
@@ -494,6 +494,18 @@ The first person to tweet a snowman drawn with this function gets a T-shirt.
.catch((error: string) => console.log("mapbox addPolygon error: " + error));
```
+### removePolygons
+You can either remove all polygons by not passing in an argument,
+or remove specific polygon id's (which you specified previously).
+
+```js
+ // remove all polygons
+ mapbox.removePolygons();
+
+ // remove specific polygons by id
+ mapbox.removePolygons([1, 2]);
+```
+
### addPolyline
Draw a polyline. Connect the points given as parameters.
diff --git a/demo/app/main-page.xml b/demo/app/main-page.xml
index 9e64bbd..159e8dc 100644
--- a/demo/app/main-page.xml
+++ b/demo/app/main-page.xml
@@ -108,9 +108,10 @@
-
-
-
+
+
+
+
diff --git a/demo/app/main-view-model.ts b/demo/app/main-view-model.ts
index 7fd8580..a75af9c 100644
--- a/demo/app/main-view-model.ts
+++ b/demo/app/main-view-model.ts
@@ -596,12 +596,15 @@ export class HelloWorldModel extends Observable {
public doRemovePolyline(): void {
this.mapbox.removePolylines([1]).then(
- result => {
- console.log("Mapbox removePolylines done");
- },
- (error: string) => {
- console.log("mapbox removePolylines error: " + error);
- }
+ result => console.log("Mapbox removePolylines done"),
+ (error: string) => console.log("mapbox removePolylines error: " + error)
+ );
+ }
+
+ public doRemovePolygon(): void {
+ this.mapbox.removePolygons([1]).then(
+ result => console.log("Mapbox removePolygons done"),
+ (error: string) => console.log("mapbox removePolygons error: " + error)
);
}
diff --git a/publish/package-lock.json b/publish/package-lock.json
new file mode 100644
index 0000000..92f4843
--- /dev/null
+++ b/publish/package-lock.json
@@ -0,0 +1,111 @@
+{
+ "name": "nativescript-publish",
+ "version": "1.0.0",
+ "lockfileVersion": 1,
+ "requires": true,
+ "dependencies": {
+ "balanced-match": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
+ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
+ "dev": true
+ },
+ "brace-expansion": {
+ "version": "1.1.8",
+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
+ "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
+ "dev": true,
+ "requires": {
+ "balanced-match": "1.0.0",
+ "concat-map": "0.0.1"
+ }
+ },
+ "concat-map": {
+ "version": "0.0.1",
+ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
+ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
+ "dev": true
+ },
+ "fs.realpath": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
+ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
+ "dev": true
+ },
+ "glob": {
+ "version": "7.1.2",
+ "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
+ "integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=",
+ "dev": true,
+ "requires": {
+ "fs.realpath": "1.0.0",
+ "inflight": "1.0.6",
+ "inherits": "2.0.3",
+ "minimatch": "3.0.4",
+ "once": "1.4.0",
+ "path-is-absolute": "1.0.1"
+ }
+ },
+ "inflight": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
+ "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
+ "dev": true,
+ "requires": {
+ "once": "1.4.0",
+ "wrappy": "1.0.2"
+ }
+ },
+ "inherits": {
+ "version": "2.0.3",
+ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
+ "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
+ "dev": true
+ },
+ "minimatch": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
+ "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=",
+ "dev": true,
+ "requires": {
+ "brace-expansion": "1.1.8"
+ }
+ },
+ "ncp": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz",
+ "integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=",
+ "dev": true
+ },
+ "once": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
+ "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
+ "dev": true,
+ "requires": {
+ "wrappy": "1.0.2"
+ }
+ },
+ "path-is-absolute": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
+ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
+ "dev": true
+ },
+ "rimraf": {
+ "version": "2.6.2",
+ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
+ "integrity": "sha1-LtgVDSShbqhlHm1u8PR8QVjOejY=",
+ "dev": true,
+ "requires": {
+ "glob": "7.1.2"
+ }
+ },
+ "wrappy": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
+ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
+ "dev": true
+ }
+ }
+}
diff --git a/src/mapbox.android.ts b/src/mapbox.android.ts
index 7af3ad6..161c220 100755
--- a/src/mapbox.android.ts
+++ b/src/mapbox.android.ts
@@ -41,6 +41,7 @@ let _mapbox: any = {};
let _accessToken: string;
let _markers = [];
let _polylines = [];
+let _polygons = [];
let _markerIconDownloadCache = [];
let _locationEngine = null;
let _locationLayerPlugin = null;
@@ -91,6 +92,7 @@ export class MapboxView extends MapboxViewBase {
this.mapView.mapboxMap = mbMap;
// note that this is not multi-map friendly, but I don't think that's used in real apps anyway
+ _polygons = [];
_polylines = [];
_markers = [];
@@ -491,6 +493,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
_mapbox.mapView.mapboxMap = mbMap;
_polylines = [];
+ _polygons = [];
_markers = [];
_addMarkers(settings.markers, _mapbox.mapView);
@@ -794,8 +797,10 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
if (options.strokeColor) {
polygonOptions.strokeColor(Mapbox.getAndroidColor(options.strokeColor));
}
-
- theMap.mapboxMap.addPolygon(polygonOptions);
+ _polygons.push({
+ id: options.id || new Date().getTime(),
+ android: theMap.mapboxMap.addPolygon(polygonOptions)
+ });
resolve();
} catch (ex) {
console.log("Error in mapbox.addPolygon: " + ex);
@@ -834,6 +839,24 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
});
}
+ removePolygons(ids?: Array, nativeMap?): Promise {
+ return new Promise((resolve, reject) => {
+ try {
+ const theMap = nativeMap || _mapbox;
+ for (let p in _polygons) {
+ let polygon = _polygons[p];
+ if (!ids || (polygon.id && ids.indexOf(polygon.id) > -1)) {
+ theMap.mapboxMap.removePolygon(polygon.android);
+ }
+ }
+ resolve();
+ } catch (ex) {
+ console.log("Error in mapbox.removePolygons: " + ex);
+ reject(ex);
+ }
+ });
+ }
+
removePolylines(ids?: Array, nativeMap?): Promise {
return new Promise((resolve, reject) => {
try {
diff --git a/src/mapbox.common.ts b/src/mapbox.common.ts
index ac8fbc1..acf861b 100755
--- a/src/mapbox.common.ts
+++ b/src/mapbox.common.ts
@@ -346,6 +346,8 @@ export interface MapboxApi {
addPolygon(options: AddPolygonOptions, nativeMap?: any): Promise;
+ removePolygons(ids?: Array, nativeMap?: any): Promise;
+
addPolyline(options: AddPolylineOptions, nativeMap?: any): Promise;
removePolylines(ids?: Array, nativeMap?: any): Promise;
@@ -479,6 +481,8 @@ export interface MapboxViewApi {
addPolygon(options: AddPolygonOptions): Promise;
+ removePolygons(ids?: Array): Promise;
+
addPolyline(options: AddPolylineOptions): Promise;
removePolylines(ids?: Array): Promise;
@@ -573,6 +577,10 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox
return this.mapbox.addPolygon(options, this.getNativeMapView());
}
+ removePolygons(ids?: Array): Promise {
+ return this.mapbox.removePolygons(ids, this.getNativeMapView());
+ }
+
addPolyline(options: AddPolylineOptions): Promise {
return this.mapbox.addPolyline(options, this.getNativeMapView());
}
diff --git a/src/mapbox.ios.ts b/src/mapbox.ios.ts
index 960a943..e05f984 100755
--- a/src/mapbox.ios.ts
+++ b/src/mapbox.ios.ts
@@ -452,10 +452,10 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
coordinateArray.push([points[p].lng, points[p].lat]);
}
- const polygonID = "polyline_" + (options.id || new Date().getTime());
+ const polygonID = "polygon_" + (options.id || new Date().getTime());
if (theMap.style.sourceWithIdentifier(polygonID)) {
- reject("Remove the polyline with this id first with 'removePolylines': " + polygonID);
+ reject("Remove the polygon with this id first with 'removePolygons': " + polygonID);
return;
}
@@ -527,23 +527,34 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
});
}
- private removePolylineById(theMap, id: any): void {
- const polylineID = "polyline_" + id;
- const layer = theMap.style.layerWithIdentifier(polylineID);
+ private removePolyById(theMap, id: string): void {
+ let layer = theMap.style.layerWithIdentifier(id);
if (layer !== null) {
theMap.style.removeLayer(layer);
}
- const source = theMap.style.sourceWithIdentifier(polylineID);
+ // polygons may have a 'stroke' layer
+ layer = theMap.style.layerWithIdentifier(id + "_stroke");
+ if (layer !== null) {
+ theMap.style.removeLayer(layer);
+ }
+ const source = theMap.style.sourceWithIdentifier(id);
if (source !== null) {
- console.log(">>> removing source " + polylineID);
theMap.style.removeSource(source);
}
}
+ removePolygons(ids?: Array, nativeMap?): Promise {
+ return new Promise((resolve, reject) => {
+ let theMap: MGLMapView = nativeMap || _mapbox.mapView;
+ ids.map(id => this.removePolyById(theMap, "polygon_" + id));
+ resolve();
+ });
+ }
+
removePolylines(ids?: Array, nativeMap?): Promise {
return new Promise((resolve, reject) => {
let theMap: MGLMapView = nativeMap || _mapbox.mapView;
- ids.map(id => this.removePolylineById(theMap, id));
+ ids.map(id => this.removePolyById(theMap, "polyline_" + id));
resolve();
});
}
diff --git a/src/package-lock.json b/src/package-lock.json
index 71666da..0407889 100644
--- a/src/package-lock.json
+++ b/src/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "nativescript-mapbox",
- "version": "4.1.0",
+ "version": "4.1.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/src/package.json b/src/package.json
index 6f03eb7..b91b0f8 100644
--- a/src/package.json
+++ b/src/package.json
@@ -1,6 +1,6 @@
{
"name": "nativescript-mapbox",
- "version": "4.1.0",
+ "version": "4.1.1",
"description": "Native Maps, by Mapbox.",
"main": "mapbox",
"typings": "index.d.ts",
diff --git a/src/platforms/ios/Podfile b/src/platforms/ios/Podfile
index 999a9b6..d565857 100644
--- a/src/platforms/ios/Podfile
+++ b/src/platforms/ios/Podfile
@@ -1,4 +1 @@
pod 'Mapbox-iOS-SDK', '~> 4.0.2'
-#pod 'MapboxDirections.swift', :git => 'https://github.com/mapbox/MapboxDirections.swift.git', :tag => 'v0.6.0'
-
-#pod 'MapboxNavigation', '~> 0.18'