47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
import { observable, computed } from 'mobx'
|
|
import { asyncComputed } from 'computed-async-mobx'
|
|
|
|
import algorithms from './algorithms/index.js'
|
|
|
|
class State {
|
|
@observable tileLayer = 'osmDE'
|
|
@observable originalActive = true
|
|
@observable simplifiedActive = true
|
|
|
|
@observable algorithmId = 'nth_point'
|
|
@observable topoJSON = false
|
|
@computed
|
|
get selectedAlgorithm() {
|
|
return algorithms.filter(algo => algo.id === this.algorithmId)[0]
|
|
}
|
|
@computed
|
|
get algoParams() {
|
|
return this.selectedAlgorithm.fields.map(f => f.value)
|
|
}
|
|
|
|
@observable originalText = '{"type": "FeatureCollection", "features": []}'
|
|
@observable originalName = ''
|
|
@computed
|
|
get original() {
|
|
return JSON.parse(this.originalText)
|
|
}
|
|
|
|
simplifiedPromise = asyncComputed(this.original, 500, async () => {
|
|
return await this.selectedAlgorithm.simplifyGeoJSON(
|
|
this.original,
|
|
this.algoParams
|
|
)
|
|
})
|
|
|
|
@computed
|
|
get simplified() {
|
|
return this.simplifiedPromise.get()
|
|
}
|
|
@computed
|
|
get simplifiedText() {
|
|
return JSON.stringify(this.simplified)
|
|
}
|
|
}
|
|
|
|
export default new State()
|