Skip to content

Commit

Permalink
fix: Ensure that fallback presets do not break iD Editor
Browse files Browse the repository at this point in the history
iD Editor requires that presets `point`, `area`, `line`, `relation` are
always defined. The user can override these via mapeo config to give
them custom names and fields, however the user could also accidentally
set the `tags` and `geometry` properties on these presets to something
that breaks iD. This fix ensures that these "special" presets always
have the correct tags so that iD does not break.
  • Loading branch information
gmaclennan committed Nov 15, 2020
1 parent 56cb2b5 commit ed61a84
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/renderer/components/MapEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,16 @@ const fallbackFields = {
*/
function convertPresets (presetsObj) {
const fields = { ...fallbackFields, ...presetsObj.fields }
const presets = { ...fallbackPresets, ...presetsObj.presets }
// Fallback presets need to override presets with the same id, since in iD it
// is essential that tags {} is empty, matchScore is 0.1 & geometry is correct
const presets = { ...presetsObj.presets, ...fallbackPresets }

// Copy the name and fields for fallback presets from the user-defined presets
Object.keys(fallbackPresets).forEach(presetId => {
if (!presetsObj.presets[presetId]) return
fallbackPresets[presetId].name = presetsObj.presets[presetId].name
fallbackPresets[presetId].fields = presetsObj.presets[presetId].fields
})

// In Mapeo Mobile (and Observation View) we do not yet use the preset.tags
// property to match presets to entities on the map. Instead we match based on
Expand Down

0 comments on commit ed61a84

Please sign in to comment.