Skip to content

Commit

Permalink
feat(markers-for-cluster): support dynamic cluster data change (#209)
Browse files Browse the repository at this point in the history
fix #206
  • Loading branch information
Wykks authored Feb 9, 2020
1 parent 0560871 commit 3e0ccad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@angular/core';
import { MapboxGeoJSONFeature, MapSourceDataEvent } from 'mapbox-gl';
import { fromEvent, merge, Subscription } from 'rxjs';
import { filter, startWith, switchMap, take } from 'rxjs/operators';
import { filter, startWith, switchMap, switchMapTo } from 'rxjs/operators';
import { MapService } from '../map/map.service';

@Directive({ selector: 'ng-template[mglPoint]' })
Expand Down Expand Up @@ -58,14 +58,12 @@ export class MarkersForClustersComponent implements OnDestroy, AfterContentInit
constructor(private MapService: MapService, private ChangeDetectorRef: ChangeDetectorRef, private zone: NgZone) {}

ngAfterContentInit() {
const clusterDataUpdate$ = fromEvent<MapSourceDataEvent>(<any>this.MapService.mapInstance, 'data').pipe(
filter((e) => e.sourceId === this.source && e.isSourceLoaded && e.sourceDataType !== 'metadata')
);
const sub = this.MapService.mapCreated$
.pipe(
switchMap(() =>
fromEvent<MapSourceDataEvent>(<any>this.MapService.mapInstance, 'data').pipe(
filter((e) => e.sourceId === this.source && e.isSourceLoaded && e.sourceDataType !== 'metadata'),
take(1)
)
),
switchMapTo(clusterDataUpdate$),
switchMap(() =>
merge(
fromEvent(<any>this.MapService.mapInstance, 'move'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ import { GeoJSONSourceComponent } from 'ngx-mapbox-gl';
styleUrls: ['./examples.css', './ngx-cluster-html.component.css']
})
export class NgxClusterHtmlComponent implements OnInit {
earthquakes: object;
earthquakes: GeoJSON.FeatureCollection;
selectedCluster: { geometry: GeoJSON.Point; properties: any };

async ngOnInit() {
this.earthquakes = await import('./earthquakes.geo.json');
const earthquakes: GeoJSON.FeatureCollection = <any>await import('./earthquakes.geo.json');
setInterval(() => {
if (earthquakes.features.length) {
earthquakes.features.pop();
}
this.earthquakes = { ...earthquakes };
}, 500);
}

selectCluster(event: MouseEvent, feature: any) {
Expand Down

0 comments on commit 3e0ccad

Please sign in to comment.