Skip to content

Commit

Permalink
Refresh inspector when loading new entities from the OSM API
Browse files Browse the repository at this point in the history
(re: #1311)
  • Loading branch information
bhousel committed Jan 30, 2024
1 parent ed13e4c commit e658175
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions modules/ui/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,45 @@ export function uiInspector(context) {
let wrap = d3_select(null);
let presetPane = d3_select(null);
let editorPane = d3_select(null);
let _selection;
let _state = 'select';
let _entityIDs;
let _newFeature = false;

// Add or replace merge handler
editor.off('merge', _onMerge);
editor.on('merge', _onMerge);


// If the inspector is showing `_entityIDs` already,
// and we get new versions of them loaded from the server
// refresh this component and its children. Rapid#1311
function _onMerge(newIDs) {
if (!(newIDs instanceof Set)) return;
if (!(Array.isArray(_entityIDs))) return;

let needsRedraw = false;
for (const entityID of _entityIDs) {
if (newIDs.has(entityID)) {
needsRedraw = true;
break;
}
}

if (needsRedraw) {
render();
}
}


function inspector(selection) {
_selection = selection;
render();
}


function render() {
if (!_selection) return; // called too soon?
const graph = editor.staging.graph;

presetList
Expand All @@ -47,7 +80,7 @@ export function uiInspector(context) {
.entityIDs(_entityIDs)
.on('choose', selected => inspector.showPresetList(selected, true)); // true = animate in

wrap = selection.selectAll('.panewrap')
wrap = _selection.selectAll('.panewrap')
.data([0]);

let enter = wrap.enter()
Expand All @@ -72,7 +105,7 @@ export function uiInspector(context) {
inspector.showEntityEditor();
}

let footer = selection.selectAll('.footer')
let footer = _selection.selectAll('.footer')
.data([0]);

footer = footer.enter()
Expand Down

0 comments on commit e658175

Please sign in to comment.