2023-07-30 18:41:47 +02:00
|
|
|
import debugLog from './utils.mjs'
|
2023-07-30 18:37:07 +02:00
|
|
|
|
|
|
|
export default class {
|
|
|
|
config = {}
|
|
|
|
constructor(mappingConfig){
|
|
|
|
|
|
|
|
this.setConfig(mappingConfig)
|
|
|
|
}
|
|
|
|
setConfig(mappingConfig){
|
|
|
|
this.config = mappingConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
mapFeaturePoint(featurePointGeoJson){
|
|
|
|
|
|
|
|
let geoJSONConvertedPoint = {}
|
|
|
|
geoJSONConvertedPoint.properties = {... this.config.default_properties_of_point};
|
|
|
|
geoJSONConvertedPoint.type = featurePointGeoJson.type;
|
|
|
|
geoJSONConvertedPoint.geometry = featurePointGeoJson.geometry
|
|
|
|
|
|
|
|
let props = featurePointGeoJson.properties
|
|
|
|
|
|
|
|
props.forEach((key,value)=>{
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return geoJSONConvertedPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isBooleanKey (pointKeyName) {
|
|
|
|
|
|
|
|
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* retuns the converted element from mapping config if present, null otherwise
|
|
|
|
*/
|
|
|
|
mapElementFromConf (featurePoint, mappingConfig) {
|
|
|
|
let mappingKeys = Object.keys(mappingConfig)
|
|
|
|
let featurePointPropertiesKeys = Object.keys(featurePoint.properties)
|
|
|
|
|
|
|
|
debugLog('keys', mappingKeys, featurePointPropertiesKeys)
|
|
|
|
|
|
|
|
let newProperties = defaultPropertiesOfPoint
|
|
|
|
|
|
|
|
// reinit properties of current point
|
|
|
|
let basePoint = Object.create(featurePoint)
|
|
|
|
basePoint.type = featurePoint.type
|
|
|
|
basePoint.geometry = featurePoint.geometry
|
|
|
|
basePoint.properties = newProperties
|
|
|
|
|
|
|
|
// apply new properties if found in mapping config
|
|
|
|
featurePointPropertiesKeys.forEach(pointKeyName => {
|
|
|
|
|
|
|
|
if (mappingKeys.indexOf(pointKeyName) !== -1) {
|
|
|
|
debugLog('found element', pointKeyName, '=>', mappingConfig[pointKeyName], 'value : ', featurePoint.properties[pointKeyName])
|
|
|
|
let convertedValue = ''
|
|
|
|
if (isBooleanKey(pointKeyName)) {
|
|
|
|
|
|
|
|
convertedValue = featurePoint.properties[pointKeyName].toLowerCase() == 'true' ? 'yes' : 'no'
|
|
|
|
} else {
|
|
|
|
convertedValue = featurePoint.properties[pointKeyName]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (convertedValue) {
|
|
|
|
newProperties[mappingConfig[pointKeyName]] = convertedValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
debugLog('basePoint', basePoint)
|
|
|
|
return basePoint
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|