Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions src/controls/editor/edithandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ let modifyDrawSnapInteraction;
let modifyDrawInteraction;
let component;

function isActive() {
// FIXME: this only happens at startup as they are set to null on closing. If checking for null/falsley/not truely it could work as isVisible with
// the exption that it can not determine if it is visble before interactions are set, i.e. it can't be used to determine if interactions should be set.
// Right now it does not matter as it is not used anywhere critical.
if (modify === undefined || select === undefined) {
return false;
}
return true;
}

function setActive(editType) {
map.removeInteraction(modifyDrawSnapInteraction);
modifyDrawSnapInteraction = null;
Expand Down Expand Up @@ -513,24 +503,22 @@ function addSnapInteraction(sources) {
}

function removeInteractions() {
if (isActive()) {
map.removeInteraction(modify);
map.removeInteraction(select);
map.removeInteraction(draw);
if (snap) {
snap.forEach((snapInteraction) => {
map.removeInteraction(snapInteraction);
});
}

modify = null;
select = null;
draw = null;
snap = null;
// The select interaction is deleted and recreated so we must send the select event manually as
// the selection collection events are not fired when interaction is destroyed effectively selecting nothing.
component.dispatch('select', []);
map.removeInteraction(modify);
map.removeInteraction(select);
map.removeInteraction(draw);
if (snap) {
snap.forEach((snapInteraction) => {
map.removeInteraction(snapInteraction);
});
}

modify = null;
select = null;
draw = null;
snap = null;
// The select interaction is deleted and recreated so we must send the select event manually as
// the selection collection events are not fired when interaction is destroyed effectively selecting nothing.
component.dispatch('select', []);
}

function setAllowedOperations() {
Expand Down Expand Up @@ -837,8 +825,8 @@ function setEditProps(options) {
const layer = viewer.getLayer(layerName);
const layerProperties = layerProps;
const snapLayers = options.snapLayers || editableLayers;
snap = 'snap' in options ? options.snap : true;
layer.set('snap', snap);
const snapOn = 'snap' in options ? options.snap : true;
layer.set('snap', snapOn);
layer.set('snapLayers', snapLayers);
layerProperties[layerName] = layer;
return layerProps;
Expand Down Expand Up @@ -916,7 +904,7 @@ function onDeleteSelected() {
function startDraw() {
if (!editLayers[currentLayer].get('geometryType')) {
alert(`"geometryType" har inte angivits för ${editLayers[currentLayer].get('name')}`);
} else if (hasDraw !== true && isActive()) {
} else if (!hasDraw) {
setActive('draw');
hasDraw = true;
dispatcher.emitChangeEdit('draw', true);
Expand Down
Loading