Skip to content

Commit

Permalink
Merge pull request #395 from TwistedTamarin/master
Browse files Browse the repository at this point in the history
Extended safecheks for IOS | Android
  • Loading branch information
dapriett authored Dec 22, 2019
2 parents 480acb7 + 37adb10 commit 6cb4dc6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
3 changes: 3 additions & 0 deletions src/map-view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export abstract class MapViewBase extends View implements MapView {
public abstract clear(): void;

public removeAllPolylines() {
if(!this._shapes) return null;
this._shapes.forEach(shape => {
if (shape.shape === 'polyline') {
this.removeShape(shape);
Expand All @@ -290,6 +291,7 @@ export abstract class MapViewBase extends View implements MapView {
}

public removeAllPolygons() {
if(!this._shapes) return null;
this._shapes.forEach(shape => {
if (shape.shape === 'polygon') {
this.removeShape(shape);
Expand All @@ -298,6 +300,7 @@ export abstract class MapViewBase extends View implements MapView {
}

public removeAllCircles() {
if(!this._shapes) return null;
this._shapes.forEach(shape => {
if (shape.shape === 'circle') {
this.removeShape(shape);
Expand Down
27 changes: 17 additions & 10 deletions src/map-view.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,15 @@ export class MapView extends MapViewBase {
}

addMarker(...markers: Marker[]) {
if(!this.gMap)
return;
if(!markers || !this._markers || !this.gMap) return null;
markers.forEach(marker => {
marker.android = this.gMap.addMarker(marker.android);
this._markers.push(marker);
});
}

removeMarker(...markers: Marker[]) {
if(!markers || !this._markers || !this.gMap) return null;
markers.forEach(marker => {
this._unloadInfoWindowContent(marker);
marker.android.remove();
Expand All @@ -437,8 +437,7 @@ export class MapView extends MapViewBase {
}

removeAllMarkers() {
if(!this._markers || !this._markers.length)
return;
if(!this._markers || !this.gMap || !this._markers.length) return null;
this._markers.forEach(marker => {
this._unloadInfoWindowContent(marker);
marker.android.remove();
Expand All @@ -447,54 +446,62 @@ export class MapView extends MapViewBase {
}

findMarker(callback: (marker: Marker) => boolean): Marker {
if(!this._markers) return null;
return this._markers.find(callback);
}

addPolyline(shape: Polyline) {
if(!this.gMap) return null;
shape.loadPoints();
shape.android = this.gMap.addPolyline(shape.android);
this._shapes.push(shape);
}

addPolygon(shape: Polygon) {
if(!this.gMap) return null;
shape.loadPoints();
shape.loadHoles();
shape.android = this.gMap.addPolygon(shape.android);
this._shapes.push(shape);
}

addCircle(shape: Circle) {
if(!this._shapes || !this.gMap) return null;
shape.android = this.gMap.addCircle(shape.android);
this._shapes.push(shape);
}

removeShape(shape: ShapeBase) {
if(!this._shapes) return null;
shape.android.remove();
this._shapes.splice(this._shapes.indexOf(shape), 1);
}

removeAllShapes() {
if(!this._shapes) return null;
this._shapes.forEach(shape => {
shape.android.remove();
});
this._shapes = [];
}

clear() {
this._markers = [];
this._shapes = [];
this.gMap.clear();
}

setStyle(style: StyleBase): boolean {
if(!this.gMap) return null;
let styleOptions = new com.google.android.gms.maps.model.MapStyleOptions(JSON.stringify(style));
return this.gMap.setMapStyle(styleOptions);
}

findShape(callback: (shape: ShapeBase) => boolean): ShapeBase {
if(!this._shapes) return null;
return this._shapes.find(callback);
}

clear() {
this._markers = [];
this._shapes = [];
this.gMap.clear();
}

}

export class UISettings extends UISettingsBase {
Expand Down
10 changes: 10 additions & 0 deletions src/map-view.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,15 @@ export class MapView extends MapViewBase {
}

addMarker(...markers: Marker[]) {
if(!markers || !this._markers || !this.gMap) return null;
markers.forEach(marker => {
marker.ios.map = this.gMap;
this._markers.push(marker);
});
}

removeMarker(...markers: Marker[]) {
if(!markers || !this._markers || !this.gMap) return null;
markers.forEach(marker => {
this._unloadInfoWindowContent(marker);
marker.ios.map = null;
Expand All @@ -389,6 +391,7 @@ export class MapView extends MapViewBase {
}

removeAllMarkers() {
if(!this._markers) return null;
this._markers.forEach(marker => {
this._unloadInfoWindowContent(marker);
marker.ios.map = null;
Expand All @@ -397,38 +400,45 @@ export class MapView extends MapViewBase {
}

findMarker(callback: (marker: Marker) => boolean): Marker {
if(!this._markers) return null;
return this._markers.find(callback);
}

addPolyline(shape: Polyline) {
if(!this._shapes) return null;
shape.loadPoints();
shape.ios.map = this.gMap;
this._shapes.push(shape);
}

addPolygon(shape: Polygon) {
if(!this._shapes) return null;
shape.ios.map = this.gMap;
this._shapes.push(shape);
}

addCircle(shape: Circle) {
if(!this._shapes) return null;
shape.ios.map = this.gMap;
this._shapes.push(shape);
}

removeShape(shape: ShapeBase) {
if(!this._shapes) return null;
shape.ios.map = null;
this._shapes.splice(this._shapes.indexOf(shape), 1);
}

removeAllShapes() {
if(!this._shapes) return null;
this._shapes.forEach(shape => {
shape.ios.map = null;
});
this._shapes = [];
}

findShape(callback: (shape: ShapeBase) => boolean): ShapeBase {
if(!this._shapes) return null;
return this._shapes.find(callback);
}

Expand Down
25 changes: 12 additions & 13 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/platforms/android/nativescript_google_maps_sdk.aar
Binary file not shown.

0 comments on commit 6cb4dc6

Please sign in to comment.