Skip to content

Commit fe2e5af

Browse files
fix: Added safechecks to prevent IOS | Android crashes
1 parent b9d339c commit fe2e5af

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

src/map-view-common.ts

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

281281
public removeAllPolylines() {
282+
if(!this._shapes) return null;
282283
this._shapes.forEach(shape => {
283284
if (shape.shape === 'polyline') {
284285
this.removeShape(shape);
@@ -287,6 +288,7 @@ export abstract class MapViewBase extends View implements MapView {
287288
}
288289

289290
public removeAllPolygons() {
291+
if(!this._shapes) return null;
290292
this._shapes.forEach(shape => {
291293
if (shape.shape === 'polygon') {
292294
this.removeShape(shape);
@@ -295,6 +297,7 @@ export abstract class MapViewBase extends View implements MapView {
295297
}
296298

297299
public removeAllCircles() {
300+
if(!this._shapes) return null;
298301
this._shapes.forEach(shape => {
299302
if (shape.shape === 'circle') {
300303
this.removeShape(shape);

src/map-view.android.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,15 @@ export class MapView extends MapViewBase {
381381
}
382382

383383
addMarker(...markers: Marker[]) {
384+
if(!markers || !this.gMap) return null;
384385
markers.forEach(marker => {
385386
marker.android = this.gMap.addMarker(marker.android);
386387
this._markers.push(marker);
387388
});
388389
}
389390

390391
removeMarker(...markers: Marker[]) {
392+
if(!markers || !this.gMap) return null;
391393
markers.forEach(marker => {
392394
this._unloadInfoWindowContent(marker);
393395
marker.android.remove();
@@ -396,6 +398,7 @@ export class MapView extends MapViewBase {
396398
}
397399

398400
removeAllMarkers() {
401+
if(!this._markers || !this.gMap) return null;
399402
this._markers.forEach(marker => {
400403
this._unloadInfoWindowContent(marker);
401404
marker.android.remove();
@@ -404,54 +407,62 @@ export class MapView extends MapViewBase {
404407
}
405408

406409
findMarker(callback: (marker: Marker) => boolean): Marker {
410+
if(!this._markers) return null;
407411
return this._markers.find(callback);
408412
}
409413

410414
addPolyline(shape: Polyline) {
415+
if(!this.gMap) return null;
411416
shape.loadPoints();
412417
shape.android = this.gMap.addPolyline(shape.android);
413418
this._shapes.push(shape);
414419
}
415420

416421
addPolygon(shape: Polygon) {
422+
if(!this.gMap) return null;
417423
shape.loadPoints();
418424
shape.loadHoles();
419425
shape.android = this.gMap.addPolygon(shape.android);
420426
this._shapes.push(shape);
421427
}
422428

423429
addCircle(shape: Circle) {
430+
if(!this._shapes || !this.gMap) return null;
424431
shape.android = this.gMap.addCircle(shape.android);
425432
this._shapes.push(shape);
426433
}
427434

428435
removeShape(shape: ShapeBase) {
436+
if(!this._shapes) return null;
429437
shape.android.remove();
430438
this._shapes.splice(this._shapes.indexOf(shape), 1);
431439
}
432440

433441
removeAllShapes() {
442+
if(!this._shapes) return null;
434443
this._shapes.forEach(shape => {
435444
shape.android.remove();
436445
});
437446
this._shapes = [];
438447
}
439448

440-
clear() {
441-
this._markers = [];
442-
this._shapes = [];
443-
this.gMap.clear();
444-
}
445-
446449
setStyle(style: StyleBase): boolean {
450+
if(!this.gMap) return null;
447451
let styleOptions = new com.google.android.gms.maps.model.MapStyleOptions(JSON.stringify(style));
448452
return this.gMap.setMapStyle(styleOptions);
449453
}
450454

451455
findShape(callback: (shape: ShapeBase) => boolean): ShapeBase {
456+
if(!this._shapes) return null;
452457
return this._shapes.find(callback);
453458
}
454459

460+
clear() {
461+
this._markers = [];
462+
this._shapes = [];
463+
this.gMap.clear();
464+
}
465+
455466
}
456467

457468
export class UISettings extends UISettingsBase {

src/map-view.ios.ts

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

315315
addMarker(...markers: Marker[]) {
316+
if(!markers || !this.gMap) return null;
316317
markers.forEach(marker => {
317318
marker.ios.map = this.gMap;
318319
this._markers.push(marker);
319320
});
320321
}
321322

322323
removeMarker(...markers: Marker[]) {
324+
if(!markers || !this.gMap) return null;
323325
markers.forEach(marker => {
324326
this._unloadInfoWindowContent(marker);
325327
marker.ios.map = null;
@@ -328,6 +330,7 @@ export class MapView extends MapViewBase {
328330
}
329331

330332
removeAllMarkers() {
333+
if(!this._markers) return null;
331334
this._markers.forEach(marker => {
332335
this._unloadInfoWindowContent(marker);
333336
marker.ios.map = null;
@@ -336,38 +339,45 @@ export class MapView extends MapViewBase {
336339
}
337340

338341
findMarker(callback: (marker: Marker) => boolean): Marker {
342+
if(!this._markers) return null;
339343
return this._markers.find(callback);
340344
}
341345

342346
addPolyline(shape: Polyline) {
347+
if(!this._shapes) return null;
343348
shape.loadPoints();
344349
shape.ios.map = this.gMap;
345350
this._shapes.push(shape);
346351
}
347352

348353
addPolygon(shape: Polygon) {
354+
if(!this._shapes) return null;
349355
shape.ios.map = this.gMap;
350356
this._shapes.push(shape);
351357
}
352358

353359
addCircle(shape: Circle) {
360+
if(!this._shapes) return null;
354361
shape.ios.map = this.gMap;
355362
this._shapes.push(shape);
356363
}
357364

358365
removeShape(shape: ShapeBase) {
366+
if(!this._shapes) return null;
359367
shape.ios.map = null;
360368
this._shapes.splice(this._shapes.indexOf(shape), 1);
361369
}
362370

363371
removeAllShapes() {
372+
if(!this._shapes) return null;
364373
this._shapes.forEach(shape => {
365374
shape.ios.map = null;
366375
});
367376
this._shapes = [];
368377
}
369378

370379
findShape(callback: (shape: ShapeBase) => boolean): ShapeBase {
380+
if(!this._shapes) return null;
371381
return this._shapes.find(callback);
372382
}
373383

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)