UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

55 lines (54 loc) 1.84 kB
import DragHelper from './draghelper.js'; import GirafeSingleton from '../../../base/GirafeSingleton.js'; class DragManager extends GirafeSingleton { layer; destination; dragAfter = false; dragBefore = false; dragHelper = new DragHelper(this.context.stateManager); dragStart(layer) { this.layer = layer; } dragEnd() { if (this.layer && this.destination && this.layer.parent === this.destination.parent) { if (this.layer.order < this.destination.order) { this.dragHelper.moveLayerAfter(this.layer, this.destination); } else if (this.layer.order > this.destination.order) { this.dragHelper.moveLayerBefore(this.layer, this.destination); } else { throw Error('Orders are equal. Not managed yet'); } this.layer = undefined; this.destination = undefined; } else { // Just do nothing, this move is not possible. console.debug('Illegal drag&drop'); } } dragEnter(target) { if (this.layer && this.layer !== target && this.layer?.parent === target.parent) { // Same parent, but different item this.destination = target; if (this.layer.order > target.order) { this.dragBefore = true; } else { this.dragAfter = true; } return true; } return false; } dragLeave(target) { if (this.layer?.treeItemId !== target.treeItemId && this.layer?.parent?.treeItemId === target.parent?.treeItemId) { this.dragAfter = false; this.dragBefore = false; return true; } return false; } } export default DragManager;