ngx-mapbox-gl icon indicating copy to clipboard operation
ngx-mapbox-gl copied to clipboard

[BUG] dynamic change of clusterMaxZoom in mgl-geojson-source not working

Open firashamila33 opened this issue 4 years ago • 7 comments

BUG:

Updating the clusterMaxZoom in mgl-geojson-source is throwing an error

Error:

Screenshot 2020-05-27 at 09 30 42

Assumption:

when I debugged the library code , the code seems not removing the layers related before updating ( removing / adding again ) the source.

BUG reproduced:

Here is a stackblitz where I reproduced the BUG: https://stackblitz.com/edit/ngx-mapbox-gl-playground-jqudva

firashamila33 avatar May 27 '20 07:05 firashamila33

@Wykks is this is a known bug ? (correct me if its not a bug please)

firashamila33 avatar May 27 '20 09:05 firashamila33

a workaround I did , is triggering the removal /addition of sources layers in the correct order , before and after changing the vehiclesClusterMaxZoom,

sequence in ts file

        this.toggleLayerRendering({isRendered: false});
        this.toggleSourceRendering({isRendered: false});
        setTimeout(() => {
            this.clusterMaxZoom = clusterMaxZoom;
            this.toggleSourceRendering({isRendered: true});
            this.toggleLayerRendering({isRendered: true});
        }, 0);

and then the layers/source is rendered according to the toggles :

html file

<mgl-geojson-source
        *ngIf="isSourceRendered"
        [id]="source"
        [data]="source.data"
        [cluster]="source.cluster"
        [clusterMaxZoom]="vehiclesClusterMaxZoom".  // <= value to update dynamically
        [clusterRadius]="source.clusterRadius"
>
</mgl-geojson-source>

<mgl-layer
         *ngIf="isLayerRendered"
          [id]="layer.id"
          [type]="layer.type"
          [paint]="layer.paint"
          [filter]="layer.filter"
          [layout]="layer.layout"
          [source]="layer.source"
 >
</mgl-layer>

firashamila33 avatar May 27 '20 12:05 firashamila33

@firashamila33 Try updating your sample to the latest version of ngx-mapbox-gl, mapbox-gl & @types/mapbox-gl and then let me know if the problem still exists.

dmytro-gokun avatar Jul 25 '20 19:07 dmytro-gokun

@dmytro-gokun , still same issue here , updated in the stackblitz example and also in my project , but same issue

firashamila33 avatar Jul 27 '20 12:07 firashamila33

Screenshot 2020-07-27 at 14 43 04

firashamila33 avatar Jul 27 '20 12:07 firashamila33

@firashamila33 Thanks for update. I'll try to look at this issue shortly.

dmytro-gokun avatar Jul 27 '20 13:07 dmytro-gokun

@dmytro-gokun any updates on this ?

firashamila33 avatar Dec 06 '21 12:12 firashamila33