Skip to content

Commit

Permalink
fix(dash): allow map geojson to be on Url or local file path
Browse files Browse the repository at this point in the history
  • Loading branch information
billyc committed Jul 20, 2021
1 parent ca53b72 commit 17e79e6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/charts/choropleth-map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as turf from '@turf/turf'
import { FileSystemConfig } from '@/Globals'
import PolygonAndCircleMap from '@/components/PolygonAndCircleMap.vue'
import HTTPFileSystem from '@/js/HTTPFileSystem'
@Component({ components: { PolygonAndCircleMap } })
export default class VueComponent extends Vue {
Expand All @@ -32,6 +33,7 @@ export default class VueComponent extends Vue {
@Prop({ required: true }) files!: string[]
@Prop({ required: true }) config!: any
private fileApi!: HTTPFileSystem
private thread!: any
private boundaries: any[] = []
private centroids: any[] = []
Expand All @@ -54,6 +56,7 @@ export default class VueComponent extends Vue {
}
private async mounted() {
this.fileApi = new HTTPFileSystem(this.fileSystemConfig)
// bulmaSlider.attach()
// load the boundaries and the dataset, use promises so we can clear
// the spinner when things are finished
Expand All @@ -66,12 +69,18 @@ export default class VueComponent extends Vue {
if (!this.config.boundaries) return
try {
const boundaries = await fetch(this.config.boundaries).then(async r => await r.json())
this.boundaries = boundaries.features
this.calculateCentroids()
if (this.config.boundaries.startsWith('http')) {
const boundaries = await fetch(this.config.boundaries).then(async r => await r.json())
this.boundaries = boundaries.features
} else {
const boundaries = await this.fileApi.getFileJson(this.config.boundaries)
this.boundaries = boundaries.features
}
} catch (e) {
console.error(e)
return
}
this.calculateCentroids()
}
private calculateCentroids() {
Expand Down

0 comments on commit 17e79e6

Please sign in to comment.