Skip to content

Commit

Permalink
added ability to select specific line/navlink shapes on userspace api
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Deubler <tim.deubler@here.com>
  • Loading branch information
TerminalTim committed Aug 21, 2023
1 parent 9e0dea9 commit 479ddf7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
23 changes: 23 additions & 0 deletions packages/editor/src/features/line/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ class Line extends Feature {
}
return tools.isMultiLineString(line) ? selected : selected[0];
}

/**
* Sets the selected state of the shapes at their respective indices.
*
* @param selectedShapeIndicies Array of Boolean values indicating whether the corresponding shape is selected at index or not
*/
setSelectedShapes(selectedShapeIndicies: boolean[] | boolean[][]) {
const line = this;
const selectedShapes = tools.private(line, 'selectedShapes');
const coordinates = tools.getCoordinates(line);

if (!Array.isArray(selectedShapeIndicies?.[0])) {
selectedShapeIndicies = [selectedShapeIndicies as boolean[]];
}

for (let ls = 0; ls < coordinates.length; ls++) {
selectedShapes[ls] ||= [];
for (let i = 0; i < coordinates[ls].length; i++) {
selectedShapes[ls][i] = Boolean(selectedShapeIndicies?.[ls]?.[i]);
}
}
tools.displayShapes(line);
}
}

(<any>Line).prototype.class = 'LINE';
Expand Down
2 changes: 0 additions & 2 deletions packages/editor/src/features/line/LineShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,12 @@ class LineShape extends Feature {
select() {
const shape = this;
const line = shape.getLine();
const editor = line._e();

const selectedShapes = lineTools.private(line, 'selectedShapes');
const {lineStringIndex, index} = shape.properties;

selectedShapes[lineStringIndex] ||= [];
selectedShapes[lineStringIndex][index] = true;

shape.properties[EDITOR_NS].selected = true;

lineTools.displayShapes(line);
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/features/line/LineTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const tools = {

_select: function(line: Line) {
if (line._e().objects.selection.select(line)) {
getPrivate(line, 'selectedShapes').length = 0;
triggerDisplayRefresh(line, 'selected', true);
tools.displayShapes(line);
}
Expand Down
18 changes: 17 additions & 1 deletion packages/editor/src/features/link/Navlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class Navlink extends Feature {
};

/**
* Returns an array of Boolean values indicating whether the corresponding shape is selected at index or not.
* Returns an array of Boolean values indicating whether the corresponding shape is selected at coordinate-index or not.
*/
getSelectedShapes(): boolean[] | boolean[][] {
const line = this;
Expand All @@ -330,6 +330,22 @@ export class Navlink extends Feature {
return selected;
}

/**
* Sets the selected state of the shapes at their respective coordinate-indices.
*
* @param selectedShapeIndicies Array of Boolean values indicating whether the corresponding shape is selected at index or not
*/
setSelectedShapes(selectedShapeIndicies: boolean[] | boolean[][]) {
const line = this;
const selectedShapes = oTools.private(line, 'selectedShapes');
const coordinates = <GeoJSONCoordinate[]>line.geometry.coordinates;

for (let i = 0; i < coordinates.length; i++) {
selectedShapes[i] = Boolean(selectedShapeIndicies[i]);
}
oTools.refreshGeometry(line);
}

/**
* Set the z-levels for the coordinates of the Navlink Feature.
* For each coordinate of the Navlink, the respective z-level must be provided.
Expand Down
2 changes: 0 additions & 2 deletions packages/editor/src/features/link/NavlinkShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ function onMouseMoveShape(ev, dx, dy) {

let curPos = <GeoJSONCoordinate>dragFeatureCoordinate(ev.mapX, ev.mapY, shp, coordinate, EDITOR);

console.log('onMouseMoveShape', dx, dy);

if (!cfg.editRestrictions(link, 1)) {
if (geoFence.isPntInFence(curPos)) {
!geoFence.isHidden() && geoFence.hide();
Expand Down
4 changes: 1 addition & 3 deletions packages/editor/src/features/link/NavlinkTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ var tools = {
deHighlight: function(line: Navlink) {
if (getPrivate(line, 'isSelected')) {
// line.toggleHover( line.allowEdit );

getPrivate(line, 'selectedShapes').length = 0;

triggerDisplayRefresh(line, {'selected': false, 'hovered': false});

tools.removeShapePnts(line);
Expand Down Expand Up @@ -287,6 +284,7 @@ var tools = {

_select: function(line: Navlink) {
if (!getPrivate(line, 'isSelected')) {
getPrivate(line, 'selectedShapes').length = 0;
line._e().objects.selection.select(line);

line._e().dump(line, 'info');
Expand Down

0 comments on commit 479ddf7

Please sign in to comment.