Commit 123cd520 authored by Barnabas Kendall's avatar Barnabas Kendall

fix geojson output

parent c7a23d9c
Pipeline #158388774 passed with stage
in 0 seconds
......@@ -34,7 +34,8 @@ export function createMap (target) {
map.getView().fit(source.getExtent())
})
interactions.modify.setActive(false)
// initially in editing mode
interactions.modify.setActive(true)
interactions.drawPolygon.setActive(false)
return { map, source, interactions }
......@@ -64,22 +65,34 @@ export function geoJSONToFeatures (json, props) {
}
export function featureToGeoJSON (mapFeature, dataFeature) {
if (dataFeature) mapFeature.setProperties(dataFeature.properties)
return geoJSONFormat.writeFeatureObject(mapFeature, { decimals: 7 })
const output = geoJSONFormat.writeFeatureObject(mapFeature, { decimals: 7 })
if (dataFeature) {
const { fileName, ...other } = dataFeature.properties
output.properties = other
}
return output
}
export function featuresToGeoJSON (mapFeatures, dataFeatures) {
if (dataFeatures) {
mapFeatures.forEach(f => {
const id = f.getId()
if (dataFeatures[id]) f.setProperties(dataFeatures[id].properties)
const output = geoJSONFormat.writeFeaturesObject(mapFeatures, { decimals: 7 })
if (Array.isArray(dataFeatures) && Array.isArray(output.features)) {
const dfMap = {}
dataFeatures.forEach(f => { dfMap[f.id.toString()] = f })
output.features.forEach(f => {
if (dfMap[f.id]) {
const { fileName, ...other } = dfMap[f.id].properties
f.properties = other
}
})
}
return geoJSONFormat.writeFeaturesObject(mapFeatures, { decimals: 7 })
return output
}
export function downloadJsonFile (json, fileName) {
const fileBlob = new Blob([JSON.stringify(json)], { type: 'application/json' })
const blobParts = [JSON.stringify(json, null, 2)]
const fileBlob = new Blob(blobParts, { type: 'application/json' })
const a = document.createElement('a')
a.download = fileName
a.href = URL.createObjectURL(fileBlob)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment