diff --git a/packages/editor/src/API/EditorOptions.ts b/packages/editor/src/API/EditorOptions.ts index aec0fe4c8..600c50759 100644 --- a/packages/editor/src/API/EditorOptions.ts +++ b/packages/editor/src/API/EditorOptions.ts @@ -21,6 +21,11 @@ import {JSUtils} from '@here/xyz-maps-common'; import {TileLayer} from '@here/xyz-maps-core'; import {Feature} from '../features/feature/Feature'; +export enum EDIT_RESTRICTION { + GEOMETRY = 1, + REMOVE = 2 +} + /** * Options to configure the map editor ({@link editor.Editor}). */ diff --git a/packages/editor/src/features/ObjectManager.ts b/packages/editor/src/features/ObjectManager.ts index c6be08a65..2cc26fb46 100644 --- a/packages/editor/src/features/ObjectManager.ts +++ b/packages/editor/src/features/ObjectManager.ts @@ -25,12 +25,19 @@ import History from './History'; import ObjectOverlay from './Overlay'; import {createOverlayLayer, OverlayProvider} from '../providers/OverlayLayer'; import {split, SplitOptions} from './LinkSplitter'; -import {TileLayer, FeatureProvider, EditableFeatureProvider, EditableRemoteTileProvider, GeoJSONCoordinate} from '@here/xyz-maps-core'; +import { + TileLayer, + FeatureProvider, + EditableFeatureProvider, + EditableRemoteTileProvider, + GeoJSONCoordinate +} from '@here/xyz-maps-core'; import {Map, JSUtils, geotools, vec3} from '@here/xyz-maps-common'; import {getClosestPntOnLine, intersectBBox, rayIntersectPlane} from '../geometry'; import {Navlink} from './link/Navlink'; import InternalEditor from '../IEditor'; import {Feature} from './feature/Feature'; +import {EDIT_RESTRICTION} from '../API/EditorOptions'; type Options = { ignore?: (feature: Navlink) => boolean @@ -278,7 +285,7 @@ class ObjectManager { if ( // if delete is triggered by a split-operation -> edit-restriction should be ignored! - params.split || !objManager.iEdit._config.editRestrictions(obj, 2) + params.split || !objManager.iEdit._config.editRestrictions(obj, EDIT_RESTRICTION.REMOVE) ) { const animation = params.animation == null ? true : params.animation; diff --git a/packages/editor/src/features/area/AreaShape.ts b/packages/editor/src/features/area/AreaShape.ts index 6bb079386..550215b44 100644 --- a/packages/editor/src/features/area/AreaShape.ts +++ b/packages/editor/src/features/area/AreaShape.ts @@ -21,8 +21,8 @@ import {intersectLineLine} from '../../geometry'; import InternalEditor from '../../IEditor'; import {Area} from './Area'; import {FeatureProvider, Feature, GeoJSONCoordinate, GeoJSONFeature} from '@here/xyz-maps-core'; -import {geotools} from '@here/xyz-maps-common'; import PolyTools, {ConnectedArea} from './PolygonTools'; +import {EDIT_RESTRICTION} from '../../API/EditorOptions'; type PolygonTools = typeof PolyTools; @@ -213,7 +213,7 @@ class AreaShape extends Feature<'Point'> { // TODO: cleanup provider add/attach to feature super(geojson, internalEditor.objects.overlay.layer.getProvider()); - const shapePnt = this; + const shapePnt: AreaShape = this; const overlay = internalEditor.objects.overlay; @@ -245,6 +245,9 @@ class AreaShape extends Feature<'Point'> { } function moveShape(e, dx, dy, cx, cy) { + const cfg = internalEditor._config; + if (cfg.editRestrictions(area, EDIT_RESTRICTION.GEOMETRY)) return; + if (!isMoved) {// first move ? isMoved = true; polygonTools.hideShape(polygonTools.private(area, 'midShapePnts'), overlay); @@ -253,7 +256,6 @@ class AreaShape extends Feature<'Point'> { triggerEvents(e, 'dragStart'); } - const cfg = internalEditor._config; const index = shapePnt.getIndex(); const polyIndex = shapePnt.properties.poly; const holeIndex = shapePnt.properties.hole; @@ -277,12 +279,12 @@ class AreaShape extends Feature<'Point'> { } polygonTools.markAsModified(area); - } - area.__.hk?.show(); - polygonTools.addVShapes(area); + area.__.hk?.show(); + polygonTools.addVShapes(area); - triggerEvents(e, isMoved ? 'dragStop' : UNDEF); + triggerEvents(e, isMoved ? 'dragStop' : UNDEF); + } } this.__ = { diff --git a/packages/editor/src/features/link/NavlinkShape.ts b/packages/editor/src/features/link/NavlinkShape.ts index 9d9366776..19502d8e2 100644 --- a/packages/editor/src/features/link/NavlinkShape.ts +++ b/packages/editor/src/features/link/NavlinkShape.ts @@ -26,7 +26,7 @@ import {Feature as EditableFeature} from '../feature/Feature'; import NavlinkTools from './NavlinkTools'; import {defaultBehavior} from '../line/LineShape'; import {dragFeatureCoordinate} from '../oTools'; -import {Coordinate} from '../line/LineTools'; +import {EDIT_RESTRICTION} from '../../API/EditorOptions'; const EDITOR_NS = '@ns:com:here:editor'; @@ -185,7 +185,7 @@ function onMouseMoveShape(ev, dx, dy) { let curPos = dragFeatureCoordinate(ev.mapX, ev.mapY, shp, coordinate, EDITOR); - if (!cfg.editRestrictions(link, 1)) { + if (!cfg.editRestrictions(link, EDIT_RESTRICTION.GEOMETRY)) { if (geoFence.isPntInFence(curPos)) { !geoFence.isHidden() && geoFence.hide(); @@ -421,8 +421,7 @@ class NavlinkShape extends Feature { prv.pointerup = onMouseUpShape; - - if (!EDITOR._config.editRestrictions(line, 1)) { + if (!EDITOR._config.editRestrictions(line, EDIT_RESTRICTION.GEOMETRY)) { prv.pointerenter = mouseInHandler; prv.pointerleave = mouseOutHandler; } @@ -565,7 +564,7 @@ class NavlinkShape extends Feature { remove() { const link = this.getLink(); - if (!link._e()._config.editRestrictions((link || this), 2)) { + if (!link._e()._config.editRestrictions((link || this), EDIT_RESTRICTION.REMOVE)) { linkTools.deleteShape(link, this); } }; @@ -625,6 +624,7 @@ class NavlinkShape extends Feature { linkTools.refreshGeometry(line); } + /** * Unselect the NavlinkShape and remove from current selection. */ @@ -695,6 +695,7 @@ class NavlinkShape extends Feature { } return childs; }; + /** * Will return true or false whether the Shape is currently selected. */ diff --git a/packages/editor/src/features/link/NavlinkTools.ts b/packages/editor/src/features/link/NavlinkTools.ts index 4ddb83eb4..0b7692b3c 100644 --- a/packages/editor/src/features/link/NavlinkTools.ts +++ b/packages/editor/src/features/link/NavlinkTools.ts @@ -28,6 +28,7 @@ import {Navlink} from './Navlink'; import {EditStates} from '../feature/Feature'; import FeatureTools from '../feature/FeatureTools'; import InternalEditor from '../../IEditor'; +import {EDIT_RESTRICTION} from '../../API/EditorOptions'; type LocationId = string | number; @@ -470,7 +471,7 @@ var tools = { createAddShapePnts: function(line: Navlink) { const addShapePnts = getPrivate(line, 'vShps'); - if (!addShapePnts.length && !line.editState('removed') && !line._e()._config.editRestrictions(line, 1)) { + if (!addShapePnts.length && !line.editState('removed') && !line._e()._config.editRestrictions(line, EDIT_RESTRICTION.GEOMETRY)) { const path = line.geometry.coordinates; for (let i = 1, p1, p2; i < path.length; i++) { @@ -543,7 +544,7 @@ var tools = { shp.__.cLinks.forEach((clinkData) => { let clink = clinkData.link; - let isGeoModAllowed = !line._e()._config.editRestrictions(clink, 1); + let isGeoModAllowed = !line._e()._config.editRestrictions(clink, EDIT_RESTRICTION.GEOMETRY); if (isGeoModAllowed) { tools.moveShapeAtIndexTo(clink, clinkData.index, position); } diff --git a/packages/editor/src/features/location/RoutingPoint.ts b/packages/editor/src/features/location/RoutingPoint.ts index 19596e04e..82a77a792 100644 --- a/packages/editor/src/features/location/RoutingPoint.ts +++ b/packages/editor/src/features/location/RoutingPoint.ts @@ -30,6 +30,7 @@ import {Navlink} from '../link/Navlink'; import {Location} from './Location'; import {Feature, GeoJSONCoordinate} from '@here/xyz-maps-core'; import LocationTools from './LocationTools'; +import {EDIT_RESTRICTION} from '../../API/EditorOptions'; // will be set in constructor to avoid circular dep warnings let locTools: typeof LocationTools; let linkTools; @@ -88,7 +89,7 @@ class NvtRoutingPoint { function pressMove(ev, dx, dy) { const {cLink, location, ignoreZ} = that; - if (cLink && !iEditor._config.editRestrictions(location, 1)) { + if (cLink && !iEditor._config.editRestrictions(location, EDIT_RESTRICTION.GEOMETRY)) { // let curPos = dragFeatureCoordinate(ev.mapX, ev.mapY, this, this.geometry.coordinates, iEditor); diff --git a/packages/editor/src/features/marker/MarkerTools.ts b/packages/editor/src/features/marker/MarkerTools.ts index 1fd2871b3..35c1e6065 100644 --- a/packages/editor/src/features/marker/MarkerTools.ts +++ b/packages/editor/src/features/marker/MarkerTools.ts @@ -22,6 +22,7 @@ import {GeoJSONCoordinate} from '@here/xyz-maps-core'; import {Feature} from '../feature/Feature'; import FeatureTools from '../feature/FeatureTools'; import {dragFeatureCoordinate} from '../oTools'; +import {EDIT_RESTRICTION} from '../../API/EditorOptions'; const DRAG_STOP = 'dragStop'; const DRAG_MOVE = 'dragMove'; @@ -136,7 +137,7 @@ const tools = { if ( prv.isEditable && prv.isSelected && - !EDITOR._config.editRestrictions(feature, 1) + !EDITOR._config.editRestrictions(feature, EDIT_RESTRICTION.GEOMETRY) ) { let coordinate = [...feature.geometry.coordinates];