From 8d9ab103fb72365accf113db5af5282432d65f29 Mon Sep 17 00:00:00 2001 From: Jack Grossman Date: Mon, 13 May 2019 10:10:40 -0400 Subject: [PATCH] working on suppressing drawing for non-active layer --- modules/Hoot/ui/sidebar/layerAdd.js | 4 ++-- modules/Hoot/ui/sidebar/sidebar.js | 6 ++--- modules/behavior/draw.js | 34 ++++++++++++++++++++--------- modules/services/osm.js | 2 +- modules/ui/raw_membership_editor.js | 2 -- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/modules/Hoot/ui/sidebar/layerAdd.js b/modules/Hoot/ui/sidebar/layerAdd.js index d2d54f1ce2..881422d942 100644 --- a/modules/Hoot/ui/sidebar/layerAdd.js +++ b/modules/Hoot/ui/sidebar/layerAdd.js @@ -202,7 +202,7 @@ export default class LayerAdd extends SidebarForm { name: d ? d.name : this.selectedLayer.name, id: d ? d.id : this.selectedLayer.id, refType: this.formMeta.refType, - activeLayer: d ? this.checkActiveLayers() : this.selectedLayer.activeLayer, + activeLayer: d ? d.activeLayer : this.selectedLayer.activeLayer, color }; @@ -213,7 +213,7 @@ export default class LayerAdd extends SidebarForm { Hoot.events.emit( 'load-layer' ); // return this.checkForReview( layer ); - this.checkActiveLayers(); + //this.checkActiveLayers(); } checkActiveLayers() { diff --git a/modules/Hoot/ui/sidebar/sidebar.js b/modules/Hoot/ui/sidebar/sidebar.js index e816d5c200..651db7d991 100644 --- a/modules/Hoot/ui/sidebar/sidebar.js +++ b/modules/Hoot/ui/sidebar/sidebar.js @@ -222,11 +222,11 @@ export default class Sidebar { referenceState = referenceActive; if (secondaryState) { - secondaryState.activeLayer = false; - referenceState.activeLayer = true; + secondaryState.activeLayer = false; + referenceState.activeLayer = true; } else { - referenceState.activeLayer = true; + referenceState.activeLayer = true; } changeActive.selectedLayer = referenceState; }); diff --git a/modules/behavior/draw.js b/modules/behavior/draw.js index 3081d21534..9653523664 100644 --- a/modules/behavior/draw.js +++ b/modules/behavior/draw.js @@ -12,13 +12,13 @@ import { behaviorHover } from './hover'; import { behaviorTail } from './tail'; import { geoChooseEdge, geoVecLength } from '../geo'; import { utilKeybinding, utilRebind } from '../util'; +import _find from 'lodash-es/find'; var _usedTails = {}; var _disableSpace = false; var _lastSpace = null; - export function behaviorDraw(context) { var dispatch = d3_dispatch( 'move', 'click', 'clickWay', 'clickNode', 'undo', 'cancel', 'finish' @@ -124,19 +124,33 @@ export function behaviorDraw(context) { function click() { var d = datum(); var target = d && d.properties && d.properties.entity; + var _activeLayer = _find( Hoot.layers.loadedLayers, function(a, b) { return a.activeLayer === true ? a : null; }); if (target && target.type === 'node') { // Snap to a node - dispatch.call('clickNode', this, target, d); - return; + if (_activeLayer.id === Number(target.mapId)) { + console.log(target.name + ' (' + target.id + ')' + ' is an active layer' ); + dispatch.call('clickNode', this, target, d); + return; + } else { + return ({ message: 'Selected layer is not active', status: -2 }, target.name); + } + // dispatch.call('clickNode', this, target, d); + // return; } else if (target && target.type === 'way') { // Snap to a way - var choice = geoChooseEdge( - context.childNodes(target), context.mouse(), context.projection, context.activeID() - ); - if (choice) { - var edge = [target.nodes[choice.index - 1], target.nodes[choice.index]]; - dispatch.call('clickWay', this, choice.loc, edge, d); - return; + // eslint-disable-next-line radix + if (_activeLayer.id === Number(target.mapId)) { + console.log(target.id + ' is an active layer' ); + var choice = geoChooseEdge( + context.childNodes(target), context.mouse(), context.projection, context.activeID() + ); + if (choice) { + var edge = [target.nodes[choice.index - 1], target.nodes[choice.index]]; + dispatch.call('clickWay', this, choice.loc, edge, d); + return; + } + } else { + return ({ message: 'Selected layer is not active', status: -2 }, target.name); } } dispatch.call('click', this, context.map().mouseCoordinates(), d); diff --git a/modules/services/osm.js b/modules/services/osm.js index a50a09cae6..c1ab7d0bf6 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -634,7 +634,7 @@ export default { filterChanges: function( changes ) { let ways = _filter( _flatten( _map( changes, featArr => featArr ) ), feat => feat.type !== 'node' ), checkLayers = Hoot.layers.loadedLayers, - visLayers = _map( _filter( _values( checkLayers ), layer => layer.visible ), layer => layer.id ), + visLayers = _map( _filter( _values( checkLayers ), layer => layer.visible ), layer => layer.id ), activeLayer = _find(checkLayers, function(a, b) { return a.activeLayer === true ? a : null; }), defaultMapId; diff --git a/modules/ui/raw_membership_editor.js b/modules/ui/raw_membership_editor.js index be2b8b3a2a..d0ae3ad254 100644 --- a/modules/ui/raw_membership_editor.js +++ b/modules/ui/raw_membership_editor.js @@ -25,13 +25,11 @@ import { svgIcon } from '../svg'; import { uiDisclosure } from './disclosure'; import { utilDisplayName, utilNoAuto, utilHighlightEntity } from '../util'; - export function uiRawMembershipEditor(context) { var taginfo = services.taginfo; var _entityID; var _showBlank; - function selectRelation(d) { d3_event.preventDefault();