75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
import debugLog from './utils.mjs'
|
|
|
|
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
|
|
}
|
|
|
|
} |