Skip to content

Commit b8b279f

Browse files
author
Chris Vietor
committed
fix: (android) actually removing source from the map in "removeSource"
1 parent 3a944b3 commit b8b279f

File tree

2 files changed

+45
-29
lines changed

2 files changed

+45
-29
lines changed

demo/app/main-view-model.ts

+40-29
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ export class HelloWorldModel extends Observable {
419419
}
420420

421421
public doAddLayerAndSource(): void {
422+
try {
423+
422424
this.mapbox
423425
.addSource('custom-collection-1', {
424426
type: 'geojson',
@@ -506,34 +508,41 @@ export class HelloWorldModel extends Observable {
506508
.then(() => console.log('circle-layer-1 added to source custom-collection-1'));
507509
});
508510

509-
this.mapbox.addLayer({
510-
id: 'layer-with-source-object',
511-
type: 'line',
512-
source: {
513-
type: 'geojson',
514-
data: {
515-
type: 'Feature',
516-
properties: {},
517-
geometry: {
518-
type: 'LineString',
519-
coordinates: [
520-
[4.80926513671875, 52.27403984182285],
521-
[4.9383544921875, 52.30931825948968],
522-
],
523-
},
524-
}
525-
},
526-
layout: {
527-
'line-cap': 'square',
528-
'line-join': 'round',
529-
'line-blur': 15
530-
},
531-
paint: {
532-
'line-color': '#5dbcd2',
533-
'line-width': 8,
534-
'line-opacity': 0.5
511+
this.mapbox.addLayer({
512+
id: 'layer-with-source-object',
513+
type: 'line',
514+
source: {
515+
type: 'geojson',
516+
data: {
517+
type: 'Feature',
518+
properties: {},
519+
geometry: {
520+
type: 'LineString',
521+
coordinates: [
522+
[4.80926513671875, 52.27403984182285],
523+
[4.9383544921875, 52.30931825948968],
524+
],
525+
},
535526
}
536-
}).then(() => console.log('layer-with-source-object added'));
527+
},
528+
layout: {
529+
'line-cap': 'square',
530+
'line-join': 'round',
531+
'line-blur': 15
532+
},
533+
paint: {
534+
'line-color': '#5dbcd2',
535+
'line-width': 8,
536+
'line-opacity': 0.5
537+
}
538+
}).then(() => console.log('layer-with-source-object added'));
539+
540+
} catch (error) {
541+
console.error('Mapbox doAddLayerAndSource error :', error);
542+
543+
}
544+
545+
537546
}
538547

539548
public doRemoveLayerAndSource(): void {
@@ -542,8 +551,10 @@ export class HelloWorldModel extends Observable {
542551
this.mapbox.removeLayer('circle-layer-1'),
543552
this.mapbox.removeLayer('layer-with-source-object')
544553
]).then(() => {
545-
this.mapbox.removeSource('custom-collection-1');
546-
this.mapbox.removeSource('layer-with-source-object_source');
554+
return Promise.all([
555+
this.mapbox.removeSource('custom-collection-1'),
556+
this.mapbox.removeSource('layer-with-source-object_source')
557+
]);
547558
})
548559
}
549560

src/mapbox.android.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,11 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
28542854
return;
28552855
}
28562856

2857+
const isRemoved = theMap.getStyle().removeSource(id);
2858+
if (!isRemoved) {
2859+
reject(`Could not remove source with id: ${id}`)
2860+
}
2861+
28572862
// if we've cached the underlying feature, remove it.
28582863
//
28592864
// since we don't know if it's a line or a circle we have to check both lists.

0 commit comments

Comments
 (0)