From c74629ede85e85c720fcc34f9cbf677f3d85483d Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 10 Dec 2014 23:30:09 -0500 Subject: [PATCH] handle relation selections, cleanup code, closes #2469, #2470 --- js/id/modes/select.js | 123 +++++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 50 deletions(-) diff --git a/js/id/modes/select.js b/js/id/modes/select.js index 787a2eef0..3447eb741 100644 --- a/js/id/modes/select.js +++ b/js/id/modes/select.js @@ -21,26 +21,43 @@ iD.modes.Select = function(context, selectedIDs) { var wrap = context.container() .select('.inspector-wrap'); + function singular() { if (selectedIDs.length === 1) { return context.entity(selectedIDs[0]); } } - function positionMenu() { - var entity = singular(); + function closeMenu() { + if (radialMenu) { + context.surface().call(radialMenu.close); + } + } - if (entity && entity.type === 'node') { + function positionMenu() { + if (suppressMenu || !radialMenu) { return; } + + var entity = singular(); + if (entity && context.geometry(entity.id) === 'relation') { + suppressMenu = true; + } else if (entity && entity.type === 'node') { radialMenu.center(context.projection(entity.loc)); } else { - radialMenu.center(context.mouse()); + var point = context.mouse(), + viewport = iD.geo.Extent(context.projection.clipExtent()).polygon(); + if (iD.geo.pointInPolygon(point, viewport)) { + radialMenu.center(point); + } else { + suppressMenu = true; + } } } function showMenu() { - context.surface() - .call(radialMenu.close) - .call(radialMenu); + closeMenu(); + if (!suppressMenu && radialMenu) { + context.surface().call(radialMenu); + } } mode.selectedIDs = function() { @@ -70,51 +87,14 @@ iD.modes.Select = function(context, selectedIDs) { }; mode.enter = function() { - behaviors.forEach(function(behavior) { - context.install(behavior); - }); - - var operations = _.without(d3.values(iD.operations), iD.operations.Delete) - .map(function(o) { return o(selectedIDs, context); }) - .filter(function(o) { return o.available(); }); - operations.unshift(iD.operations.Delete(selectedIDs, context)); - - keybinding.on('⎋', function() { - context.enter(iD.modes.Browse(context)); - }, true); - - operations.forEach(function(operation) { - operation.keys.forEach(function(key) { - keybinding.on(key, function() { - if (!operation.disabled()) { - operation(); - } - }); - }); - }); - - radialMenu = iD.ui.RadialMenu(context, operations); - - context.ui().sidebar - .select(singular() ? singular().id : null, newFeature); - - context.history() - .on('undone.select', update) - .on('redone.select', update); - function update() { - context.surface().call(radialMenu.close); - + closeMenu(); if (_.any(selectedIDs, function(id) { return !context.hasEntity(id); })) { // Exit mode if selected entity gets undone context.enter(iD.modes.Browse(context)); } } - context.map().on('move.select', function() { - context.surface().call(radialMenu.close); - }); - function dblclick() { var target = d3.select(d3.event.target), datum = target.datum(); @@ -135,10 +115,13 @@ iD.modes.Select = function(context, selectedIDs) { } } - d3.select(document) - .call(keybinding); - function selectElements() { + var entity = singular(); + if (entity && context.geometry(entity.id) === 'relation') { + suppressMenu = true; + return; + } + var selection = context.surface() .selectAll(iD.util.entityOrMemberSelector(selectedIDs, context.graph())); @@ -151,7 +134,47 @@ iD.modes.Select = function(context, selectedIDs) { } } - context.map().on('drawn.select', selectElements); + + behaviors.forEach(function(behavior) { + context.install(behavior); + }); + + var operations = _.without(d3.values(iD.operations), iD.operations.Delete) + .map(function(o) { return o(selectedIDs, context); }) + .filter(function(o) { return o.available(); }); + + operations.unshift(iD.operations.Delete(selectedIDs, context)); + + keybinding.on('⎋', function() { + context.enter(iD.modes.Browse(context)); + }, true); + + operations.forEach(function(operation) { + operation.keys.forEach(function(key) { + keybinding.on(key, function() { + if (!operation.disabled()) { + operation(); + } + }); + }); + }); + + d3.select(document) + .call(keybinding); + + radialMenu = iD.ui.RadialMenu(context, operations); + + context.ui().sidebar + .select(singular() ? singular().id : null, newFeature); + + context.history() + .on('undone.select', update) + .on('redone.select', update); + + context.map() + .on('move.select', closeMenu) + .on('drawn.select', selectElements); + selectElements(); var show = d3.event && !suppressMenu; @@ -185,13 +208,13 @@ iD.modes.Select = function(context, selectedIDs) { }); keybinding.off(); + closeMenu(); context.history() .on('undone.select', null) .on('redone.select', null); context.surface() - .call(radialMenu.close) .on('dblclick.select', null) .selectAll('.selected') .classed('selected', false);