Skip to content

Commit 6cb4dc6

Browse files
authored
Merge pull request #395 from TwistedTamarin/master
Extended safecheks for IOS | Android
2 parents 480acb7 + 37adb10 commit 6cb4dc6

File tree

5 files changed

+42
-23
lines changed

5 files changed

+42
-23
lines changed

src/map-view-common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ export abstract class MapViewBase extends View implements MapView {
282282
public abstract clear(): void;
283283

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

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

300302
public removeAllCircles() {
303+
if(!this._shapes) return null;
301304
this._shapes.forEach(shape => {
302305
if (shape.shape === 'circle') {
303306
this.removeShape(shape);

src/map-view.android.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,15 @@ export class MapView extends MapViewBase {
420420
}
421421

422422
addMarker(...markers: Marker[]) {
423-
if(!this.gMap)
424-
return;
423+
if(!markers || !this._markers || !this.gMap) return null;
425424
markers.forEach(marker => {
426425
marker.android = this.gMap.addMarker(marker.android);
427426
this._markers.push(marker);
428427
});
429428
}
430429

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

439439
removeAllMarkers() {
440-
if(!this._markers || !this._markers.length)
441-
return;
440+
if(!this._markers || !this.gMap || !this._markers.length) return null;
442441
this._markers.forEach(marker => {
443442
this._unloadInfoWindowContent(marker);
444443
marker.android.remove();
@@ -447,54 +446,62 @@ export class MapView extends MapViewBase {
447446
}
448447

449448
findMarker(callback: (marker: Marker) => boolean): Marker {
449+
if(!this._markers) return null;
450450
return this._markers.find(callback);
451451
}
452452

453453
addPolyline(shape: Polyline) {
454+
if(!this.gMap) return null;
454455
shape.loadPoints();
455456
shape.android = this.gMap.addPolyline(shape.android);
456457
this._shapes.push(shape);
457458
}
458459

459460
addPolygon(shape: Polygon) {
461+
if(!this.gMap) return null;
460462
shape.loadPoints();
461463
shape.loadHoles();
462464
shape.android = this.gMap.addPolygon(shape.android);
463465
this._shapes.push(shape);
464466
}
465467

466468
addCircle(shape: Circle) {
469+
if(!this._shapes || !this.gMap) return null;
467470
shape.android = this.gMap.addCircle(shape.android);
468471
this._shapes.push(shape);
469472
}
470473

471474
removeShape(shape: ShapeBase) {
475+
if(!this._shapes) return null;
472476
shape.android.remove();
473477
this._shapes.splice(this._shapes.indexOf(shape), 1);
474478
}
475479

476480
removeAllShapes() {
481+
if(!this._shapes) return null;
477482
this._shapes.forEach(shape => {
478483
shape.android.remove();
479484
});
480485
this._shapes = [];
481486
}
482487

483-
clear() {
484-
this._markers = [];
485-
this._shapes = [];
486-
this.gMap.clear();
487-
}
488-
489488
setStyle(style: StyleBase): boolean {
489+
if(!this.gMap) return null;
490490
let styleOptions = new com.google.android.gms.maps.model.MapStyleOptions(JSON.stringify(style));
491491
return this.gMap.setMapStyle(styleOptions);
492492
}
493493

494494
findShape(callback: (shape: ShapeBase) => boolean): ShapeBase {
495+
if(!this._shapes) return null;
495496
return this._shapes.find(callback);
496497
}
497498

499+
clear() {
500+
this._markers = [];
501+
this._shapes = [];
502+
this.gMap.clear();
503+
}
504+
498505
}
499506

500507
export class UISettings extends UISettingsBase {

src/map-view.ios.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,15 @@ export class MapView extends MapViewBase {
374374
}
375375

376376
addMarker(...markers: Marker[]) {
377+
if(!markers || !this._markers || !this.gMap) return null;
377378
markers.forEach(marker => {
378379
marker.ios.map = this.gMap;
379380
this._markers.push(marker);
380381
});
381382
}
382383

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

391393
removeAllMarkers() {
394+
if(!this._markers) return null;
392395
this._markers.forEach(marker => {
393396
this._unloadInfoWindowContent(marker);
394397
marker.ios.map = null;
@@ -397,38 +400,45 @@ export class MapView extends MapViewBase {
397400
}
398401

399402
findMarker(callback: (marker: Marker) => boolean): Marker {
403+
if(!this._markers) return null;
400404
return this._markers.find(callback);
401405
}
402406

403407
addPolyline(shape: Polyline) {
408+
if(!this._shapes) return null;
404409
shape.loadPoints();
405410
shape.ios.map = this.gMap;
406411
this._shapes.push(shape);
407412
}
408413

409414
addPolygon(shape: Polygon) {
415+
if(!this._shapes) return null;
410416
shape.ios.map = this.gMap;
411417
this._shapes.push(shape);
412418
}
413419

414420
addCircle(shape: Circle) {
421+
if(!this._shapes) return null;
415422
shape.ios.map = this.gMap;
416423
this._shapes.push(shape);
417424
}
418425

419426
removeShape(shape: ShapeBase) {
427+
if(!this._shapes) return null;
420428
shape.ios.map = null;
421429
this._shapes.splice(this._shapes.indexOf(shape), 1);
422430
}
423431

424432
removeAllShapes() {
433+
if(!this._shapes) return null;
425434
this._shapes.forEach(shape => {
426435
shape.ios.map = null;
427436
});
428437
this._shapes = [];
429438
}
430439

431440
findShape(callback: (shape: ShapeBase) => boolean): ShapeBase {
441+
if(!this._shapes) return null;
432442
return this._shapes.find(callback);
433443
}
434444

src/package-lock.json

Lines changed: 12 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

0 commit comments

Comments
 (0)