Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
refactor: passe les properties construites à geojsonBuild
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisromain committed Mar 18, 2020
1 parent 5255db0 commit 15015e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
28 changes: 27 additions & 1 deletion public-build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,20 @@ const geojsonsBuild = async (definitions, query, metas) =>

const couleur = domainesCouleurs[definition.domainesIds[0]]

const geojson = geojsonFormat(titres, couleur, {
const fichier = fileNameFormat({
domaines,
types,
statuts
})

const properties = {
fichier,
couleur,
...metasFormat(metas)
}

const geojson = geojsonFormat(titres, properties)

return (await geojsons).concat(geojson)
}, Promise.resolve([]))

Expand All @@ -86,6 +94,24 @@ const infosFileCreate = async infos => {
console.log(`${infos.length} fichiers générés`)
}

const fileNameFormat = ({ domaines, types, statuts }) => {
return `titres-${domaines.map(d => d.id).join('-')}-${types
.map(t => t.id)
.join('-')}-${statuts.map(s => s.id).join('-')}.geojson`
}

// pour chaque definition (domainesIds, typesIds, statutsIds)
// retourne un tableau avec les noms correspondant aux ids
// - domaines: []
// - types: []
// - statuts: []
const metasFormat = metas =>
Object.keys(metas).reduce((metasObj, metaName) => {
metasObj[metaName] = metas[metaName].map(m => m.nom || m.type.nom)

return metasObj
}, {})

// ------------------------------------
// process
// ------------------------------------
Expand Down
28 changes: 2 additions & 26 deletions utils/geojson-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,34 +107,10 @@ const titreFormat = ({
}
}

const fileNameFormat = ({ domaines, types, statuts }) => {
return `titres-${domaines.map(d => d.id).join('-')}-${types
.map(t => t.id)
.join('-')}-${statuts.map(s => s.id).join('-')}.geojson`
}

// pour chaque definition (domainesIds, typesIds, statutsIds)
// retourne un tableau avec les noms correspondant aux ids
// - domaines: []
// - types: []
// - statuts: []
const metasFormat = metas =>
Object.keys(metas).reduce((metasObj, metaName) => {
metasObj[`${metaName.slice(0, -1)}Ids`] = metas[metaName].map(
m => m.nom || m.type.nom
)

return metasObj
}, {})

// pour une definition, retourne le contenu du geojson formaté
const geojsonFormat = (titres, couleur, metas) => ({
const geojsonFormat = (titres, properties) => ({
type: 'FeatureCollection',
properties: {
fichier: fileNameFormat(metas),
couleur,
...metasFormat(metas)
},
properties,
features: titres.map(titreFormat)
})

Expand Down

0 comments on commit 15015e7

Please sign in to comment.