Skip to content

Commit

Permalink
fixed(editor): Ensure [EditRestrictions](https://heremaps.github.io/x…
Browse files Browse the repository at this point in the history
…yz-maps/docs/editor.editoroptions.html#editrestrictions) are evaluated during AreaShape drag operations

Signed-off-by: Tim Deubler <[email protected]>
  • Loading branch information
TerminalTim committed Aug 2, 2024
1 parent 9b36717 commit 1ee8cb2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
5 changes: 5 additions & 0 deletions packages/editor/src/API/EditorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}).
*/
Expand Down
11 changes: 9 additions & 2 deletions packages/editor/src/features/ObjectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
16 changes: 9 additions & 7 deletions packages/editor/src/features/area/AreaShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -213,7 +213,7 @@ class AreaShape extends Feature<'Point'> {
// TODO: cleanup provider add/attach to feature
super(geojson, <FeatureProvider>internalEditor.objects.overlay.layer.getProvider());

const shapePnt = this;
const shapePnt: AreaShape = this;
const overlay = internalEditor.objects.overlay;


Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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.__ = {
Expand Down
11 changes: 6 additions & 5 deletions packages/editor/src/features/link/NavlinkShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -185,7 +185,7 @@ function onMouseMoveShape(ev, dx, dy) {

let curPos = <GeoJSONCoordinate>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();

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -565,7 +564,7 @@ class NavlinkShape extends Feature {
remove() {
const link = this.getLink();

if (!link._e()._config.editRestrictions(<EditableFeature>(link || this), 2)) {
if (!link._e()._config.editRestrictions(<EditableFeature>(link || this), EDIT_RESTRICTION.REMOVE)) {
linkTools.deleteShape(link, this);
}
};
Expand Down Expand Up @@ -625,6 +624,7 @@ class NavlinkShape extends Feature {

linkTools.refreshGeometry(line);
}

/**
* Unselect the NavlinkShape and remove from current selection.
*/
Expand Down Expand Up @@ -695,6 +695,7 @@ class NavlinkShape extends Feature {
}
return childs;
};

/**
* Will return true or false whether the Shape is currently selected.
*/
Expand Down
5 changes: 3 additions & 2 deletions packages/editor/src/features/link/NavlinkTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/features/location/RoutingPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = <GeoJSONCoordinate>dragFeatureCoordinate(ev.mapX, ev.mapY, this, this.geometry.coordinates, iEditor);


Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/features/marker/MarkerTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = <GeoJSONCoordinate>[...feature.geometry.coordinates];

Expand Down

0 comments on commit 1ee8cb2

Please sign in to comment.