diff --git a/modules/core/context.js b/modules/core/context.js index 22cae0e69..20a15d36c 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -503,8 +503,8 @@ export function coreContext() { features.init(); if (utilStringQs(window.location.hash).presets) { var external = utilStringQs(window.location.hash).presets; - presets.fromExternal(external, function(externalPresets){ - presets = externalPresets; // default + external presets... + presets.fromExternal(external, function(externalPresets) { + context.presets = function() { return externalPresets; }; // default + external presets... areaKeys = presets.areaKeys(); }); } else { diff --git a/modules/presets/index.js b/modules/presets/index.js index fa641cc5c..b99309e78 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -73,7 +73,6 @@ export function presetIndex() { if (address && (!match || match.isFallback())) { match = address; } - return match || all.item(geometry); }); }; @@ -139,13 +138,23 @@ export function presetIndex() { if (d.presets) { _forEach(d.presets, function(d, id) { - all.collection.push(presetPreset(id, d, _fields, visible)); + var existing = all.collection.findIndex(function(p) { return p.id === id; }); + if (existing !== -1) { + all.collection[existing] = presetPreset(id, d, _fields, visible); + } else { + all.collection.push(presetPreset(id, d, _fields, visible)); + } }); } if (d.categories) { _forEach(d.categories, function(d, id) { - all.collection.push(presetCategory(id, d, all)); + var existing = all.collection.findIndex(function(p) { return p.id === id; }); + if (existing !== -1) { + all.collection[existing] = presetCategory(id, d, all); + } else { + all.collection.push(presetCategory(id, d, all)); + } }); } @@ -165,7 +174,7 @@ export function presetIndex() { var geometry = preset.geometry; for (var j = 0; j < geometry.length; j++) { - var g = _index[geometry[j]]; + var g = _index[geometry[j]]; for (var k in preset.tags) { (g[k] = g[k] || []).push(preset); } diff --git a/modules/ui/entity_editor.js b/modules/ui/entity_editor.js index 68f41dea6..b857c7cb2 100644 --- a/modules/ui/entity_editor.js +++ b/modules/ui/entity_editor.js @@ -218,6 +218,8 @@ export function uiEntityEditor(context) { // A "weak" preset doesn't set any tags. (e.g. "Address") // Don't replace a weak preset with a fallback preset (e.g. "Point") if (!(weakPreset && match.isFallback())) { + match.visible(true); + context.presets().choose(match); entityEditor.preset(match); } entityEditor.modified(_base !== graph); @@ -250,6 +252,7 @@ export function uiEntityEditor(context) { context.overwrite(actionChangeTags(_entityID, tags), annotation); } else { context.perform(actionChangeTags(_entityID, tags), annotation); + // context.presets().choose(context.presets().match(context.graph)) _coalesceChanges = !!onInput; } }