Skip to content

Commit

Permalink
fix(geojsonSource): fill data with empty FeatureCollection
Browse files Browse the repository at this point in the history
It seems that source.setData don't do anything if the source if empty. This fix handle cases when you create a source without immediate data.
  • Loading branch information
Wykks committed Nov 14, 2017
1 parent 3b1b08a commit a8df1cd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/app/lib/source/geojson/geojson-source.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export class GeoJSONSourceComponent implements OnInit, OnDestroy, OnChanges, Geo
) { }

ngOnInit() {
if (!this.data) {
this.data = {
type: 'FeatureCollection',
features: []
};
}
this.MapService.mapLoaded$.subscribe(() => {
this.MapService.addSource(this.id, {
type: 'geojson',
Expand Down Expand Up @@ -81,12 +87,6 @@ export class GeoJSONSourceComponent implements OnInit, OnDestroy, OnChanges, Geo
}

addFeature(feature: GeoJSON.Feature<GeoJSON.GeometryObject>) {
if (!this.data) {
this.data = {
type: 'FeatureCollection',
features: []
};
}
const collection = <GeoJSON.FeatureCollection<GeoJSON.GeometryObject>>this.data;
collection.features.push(feature);
this.updateFeatureData.next();
Expand Down

0 comments on commit a8df1cd

Please sign in to comment.