Skip to content

Commit

Permalink
fixed(editor): Highlighted crossings links are reset in all cases.
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 Oct 17, 2024
1 parent b298ac2 commit 3d054ec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
9 changes: 7 additions & 2 deletions packages/editor/src/IEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export default class InternalEditor {
return JSUtils.extend(true, [], style);
};

getCustomStyle(feature: Feature): StyleGroup {
return this.getLayer(feature)._getCustomStyleGroup(feature);
};

getStyleProperty(feature: Feature, property: string) {
const styleGroup = this.getStyle(feature);
for (let style of styleGroup) {
Expand Down Expand Up @@ -223,9 +227,10 @@ export default class InternalEditor {
// and a refresh for possible style update of styleAttributeFunctions is triggered.
style = layer._getCustomStyleGroup(feature);
} else if (style == 'default') {
style = UNDEF;
// __default is used to preserve previously applied custom styles that may have been "overwritten"
// when the editor itself applies custom styles.
style = (layer._getCustomStyleGroup(feature) as StyleGroup & {__default?: StyleGroup}).__default || UNDEF;
}

// @ts-ignore: merge attribute is "internal"
layer.setStyleGroup(feature, style, merge);
};
Expand Down
46 changes: 30 additions & 16 deletions packages/editor/src/features/link/NavlinkShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
*/

import {JSUtils, geotools, vec3} from '@here/xyz-maps-common';
import {FeatureProvider, Feature, GeoJSONFeature, GeoJSONCoordinate, LineStyle} from '@here/xyz-maps-core';
import {
FeatureProvider,
Feature,
GeoJSONFeature,
GeoJSONCoordinate,
StyleGroup
} from '@here/xyz-maps-core';
import GeoFence from './GeoFence';
import {Navlink} from './Navlink';
import {TurnRestrictionEditor} from '../../tools/turnrestriction/TrEditor';
Expand Down Expand Up @@ -240,11 +246,6 @@ function onMouseUpShape(ev) {

prv._cls = null;

// reenabale mouse move event for all connected links of the shape
// orgCLinks.forEach(function(cl){
// cl.link.toggleHover( true )
// });

if (isMoved) {
AFInfo = linkTools.fixGeo(navlink, index);

Expand All @@ -258,6 +259,8 @@ function onMouseUpShape(ev) {
index = AFInfo;
}
}

setConnectedLinksDefault(this);
}

linkTools.showDirection(navlink);
Expand Down Expand Up @@ -298,13 +301,10 @@ function onMouseUpShape(ev) {
}

// make sure valid shape object is available even if shape changed due to geometry restrictions
navlink._e().listeners.trigger(
ev,

navlink._e().listeners.trigger(ev,
navlink.editState('removed')
? shp// _simplified
: linkTools.private(navlink, 'shps')[index], // ._simplified,

isMoved
? 'dragStop'
: undefined
Expand All @@ -316,17 +316,22 @@ function onMouseUpShape(ev) {
}
}

const setConnectedLinksDefault = (shapePnt) => {
getPrivate(shapePnt).cLinks.forEach((cl) => {
linkTools.defaults(cl.link, null, true);
});
};

function mouseOutHandler() {
const shapePnt = this;
const prv = getPrivate(shapePnt);
document.body.style.cursor = 'default';

prv.cLinks.forEach((cl) => {
linkTools.defaults(cl.link);
});
setConnectedLinksDefault(shapePnt);

delete this.properties[EDITOR_NS].hovered;


prv.line._e().setStyle(this);
}

Expand All @@ -338,13 +343,22 @@ function mouseInHandler() {

document.body.style.cursor = 'move';

prv.cLinks.forEach((cl) => {
const style = EDITOR.getStyle(cl.link) as LineStyle[];
prv.cLinks.forEach(({link}) => {
const customStyle = EDITOR.getCustomStyle(link);
let style: StyleGroup & {__default?: StyleGroup};

if (customStyle) {
style = JSUtils.extend(true, [], customStyle);
// Preserve previously applied custom styles when "default" styles are set.
style.__default = customStyle;
} else {
style = EDITOR.getStyle(link) as StyleGroup;
}

for (let s = 0; s < style.length; s++) {
style[s].opacity = 0.5;
}
EDITOR.setStyle(cl.link, style);
EDITOR.setStyle(link, style);
});

this.properties[EDITOR_NS].hovered = true;
Expand Down
11 changes: 5 additions & 6 deletions packages/editor/src/features/link/NavlinkTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* License-Filename: LICENSE
*/

import {GeoJSONBBox as BBox, GeoJSONCoordinate} from '@here/xyz-maps-core';
import {Feature, GeoJSONBBox as BBox, GeoJSONCoordinate, StyleGroup} from '@here/xyz-maps-core';
import {geotools, JSUtils} from '@here/xyz-maps-common';
import {getPointAtLength, getTotalLength, getPntAt, getSegmentIndex} from '../../geometry';
import {calcRelPosOfPoiAtLink} from '../../map/GeoMath';
Expand Down Expand Up @@ -124,14 +124,13 @@ function handleEvent(ev) {
line._e().listeners.trigger(ev, line);
}

function triggerDisplayRefresh(line: Navlink, editStates?: {}) {
function triggerDisplayRefresh(line: Navlink, editStates?: {}, enforceDefault?: boolean) {
if (editStates) {
for (let s in editStates) {
line.editState(<EditStates>s, editStates[s]);
}
}

line._e().setStyle(line);
line._e().setStyle(line, enforceDefault ? 'default': UNDEF);
}

function storeConnectedPoints(line: Navlink) {
Expand Down Expand Up @@ -758,7 +757,7 @@ var tools = {
}
},

defaults: function(line: Navlink, selected?: boolean) {
defaults: function(line: Navlink, selected?: LocationId, enforceDefault?: boolean) {
const prv = getPrivate(line);

if (selected && selected != prv._cPnt) {
Expand All @@ -770,7 +769,7 @@ var tools = {
triggerDisplayRefresh(line, {
'selected': false,
'hovered': false
});
}, enforceDefault);

return line;
},
Expand Down

0 comments on commit 3d054ec

Please sign in to comment.