Trying to improve trkseg styles

This commit is contained in:
Eric van der Vlist 2023-03-16 22:16:16 +01:00
parent c9d231251f
commit 9b9bba1609
1 changed files with 36 additions and 15 deletions

View File

@ -124,16 +124,6 @@ const textFillSel = new Fill({
color: 'red', color: 'red',
}); });
const trksegStroke = new Stroke({
color: [11, 16, 71, 0.8],
width: 3,
});
const trksegStrokeSel = new Stroke({
color: 'red',
width: 3,
});
const rteStroke = new Stroke({ const rteStroke = new Stroke({
color: [18, 71, 11, 0.8], color: [18, 71, 11, 0.8],
width: 3, width: 3,
@ -222,12 +212,43 @@ const styles = {
zoom: getZoomInteger() >= 7 ? Math.floor(getZoomInteger()) : undefined, zoom: getZoomInteger() >= 7 ? Math.floor(getZoomInteger()) : undefined,
}; };
}, },
ownStyles: {
normal: [
new Style({
stroke: new Stroke({
color: [44, 64, 255, 0.8],
width: 2,
}),
}),
new Style({
stroke: new Stroke({
color: [44, 64, 255, 0.2],
width: 7,
}),
}),
],
selected: [
new Style({
stroke: new Stroke({
color: [44, 64, 255, 0.8],
width: 2,
}),
}),
new Style({
stroke: new Stroke({
color: [255, 0, 0, 0.4],
width: 7,
}),
}),
],
},
getStyle: memoize((params: any) => { getStyle: memoize((params: any) => {
// console.log({ caller: 'getStyle', params }); // console.log({ caller: 'getStyle', params });
const { isSelected, feature, zoom } = params; const { isSelected, feature, zoom } = params;
const styles = [ let currentStyles: any = isSelected
new Style({ stroke: isSelected ? trksegStrokeSel : trksegStroke }), ? styles.trkseg.ownStyles.selected
]; : styles.trkseg.ownStyles.normal;
if (feature) { if (feature) {
const map = getMap(); const map = getMap();
const geometry = feature.getGeometry(); const geometry = feature.getGeometry();
@ -247,7 +268,7 @@ const styles = {
const dx = end[0] - start[0]; const dx = end[0] - start[0];
const dy = end[1] - start[1]; const dy = end[1] - start[1];
const rotation = Math.atan2(dy, dx) - Math.PI / 2; const rotation = Math.atan2(dy, dx) - Math.PI / 2;
styles.push( currentStyles.push(
new Style({ new Style({
geometry: new Point(end), geometry: new Point(end),
image: new Icon({ image: new Icon({
@ -264,7 +285,7 @@ const styles = {
} }
}); });
} }
return styles; return currentStyles;
}, memoizeOptions), }, memoizeOptions),
}, },
'trkseg-finish': { 'trkseg-finish': {