Skip to content
Snippets Groups Projects
Commit 7c77b546 authored by Miłosz Grocholewski's avatar Miłosz Grocholewski
Browse files

Merge branch 'feat/MIN-46-arrow-position' into 'development'

fix(vector-map): correct arrow position on arrow layer

Closes MIN-46

See merge request !278
parents e8a3f71d b8b0db70
No related branches found
No related tags found
1 merge request!278fix(vector-map): correct arrow position on arrow layer
Pipeline #96843 passed
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection';
import { MapInstance } from '@/types/map'; import { MapInstance } from '@/types/map';
import { import {
ColorObject,
HorizontalAlign, HorizontalAlign,
VerticalAlign, VerticalAlign,
} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types';
...@@ -13,6 +12,7 @@ import { ...@@ -13,6 +12,7 @@ import {
import Polygon from 'ol/geom/Polygon'; import Polygon from 'ol/geom/Polygon';
import BaseMultiPolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon'; import BaseMultiPolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon';
import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle';
import { Color } from '@/types/models';
export type CompartmentPathwayProps = { export type CompartmentPathwayProps = {
x: number; x: number;
...@@ -20,9 +20,9 @@ export type CompartmentPathwayProps = { ...@@ -20,9 +20,9 @@ export type CompartmentPathwayProps = {
width: number; width: number;
height: number; height: number;
zIndex: number; zIndex: number;
fillColor?: ColorObject; fillColor?: Color;
borderColor?: ColorObject; borderColor?: Color;
fontColor?: ColorObject; fontColor?: Color;
outerWidth?: number; outerWidth?: number;
text?: string; text?: string;
fontSize?: number; fontSize?: number;
......
...@@ -210,6 +210,25 @@ export default class Layer { ...@@ -210,6 +210,25 @@ export default class Layer {
return [pointToProjection({ x: segment.x2, y: segment.y2 })]; return [pointToProjection({ x: segment.x2, y: segment.y2 })];
}) })
.flat(); .flat();
const firstSegment = line.segments[0];
const startArrowRotation = getRotation(
[firstSegment.x1, firstSegment.y1],
[firstSegment.x2, firstSegment.y2],
);
const shortenedX1 = firstSegment.x1 + line.startArrow.length * Math.cos(startArrowRotation);
const shortenedY1 = firstSegment.y1 - line.startArrow.length * Math.sin(startArrowRotation);
points[0] = pointToProjection({ x: shortenedX1, y: shortenedY1 });
const lastSegment = line.segments[line.segments.length - 1];
const endArrowRotation = getRotation(
[lastSegment.x1, lastSegment.y1],
[lastSegment.x2, lastSegment.y2],
);
const shortenedX2 = lastSegment.x2 - line.endArrow.length * Math.cos(endArrowRotation);
const shortenedY2 = lastSegment.y2 - line.endArrow.length * Math.sin(endArrowRotation);
points[points.length - 1] = pointToProjection({ x: shortenedX2, y: shortenedY2 });
const lineString = new LineString(points); const lineString = new LineString(points);
let lineDash; let lineDash;
...@@ -229,25 +248,47 @@ export default class Layer { ...@@ -229,25 +248,47 @@ export default class Layer {
}); });
lineFeature.setStyle(lineStyle); lineFeature.setStyle(lineStyle);
linesFeatures.push(lineFeature); linesFeatures.push(lineFeature);
arrowsFeatures.push(...this.getLineArrowsFeatures(line, pointToProjection));
arrowsFeatures.push(
...this.getLineArrowsFeatures({
line,
pointToProjection,
startArrowX: firstSegment.x1,
startArrowY: firstSegment.y1,
startArrowRotation,
endArrowX: shortenedX2,
endArrowY: shortenedY2,
endArrowRotation,
}),
);
}); });
return { linesFeatures, arrowsFeatures }; return { linesFeatures, arrowsFeatures };
}; };
private getLineArrowsFeatures = ( private getLineArrowsFeatures = ({
line: LayerLine, line,
pointToProjection: UsePointToProjectionResult, pointToProjection,
): Array<Feature<MultiPolygon>> => { startArrowX,
startArrowY,
startArrowRotation,
endArrowX,
endArrowY,
endArrowRotation,
}: {
line: LayerLine;
pointToProjection: UsePointToProjectionResult;
startArrowX: number;
startArrowY: number;
startArrowRotation: number;
endArrowX: number;
endArrowY: number;
endArrowRotation: number;
}): Array<Feature<MultiPolygon>> => {
const arrowsFeatures: Array<Feature<MultiPolygon>> = []; const arrowsFeatures: Array<Feature<MultiPolygon>> = [];
const firstSegment = line.segments[0];
const startArrowRotation = getRotation(
[firstSegment.x1, firstSegment.y1],
[firstSegment.x2, firstSegment.y2],
);
const startArrowFeature = this.getLineArrowFeature( const startArrowFeature = this.getLineArrowFeature(
line.startArrow, line.startArrow,
firstSegment.x1, startArrowX,
firstSegment.y1, startArrowY,
line.z, line.z,
startArrowRotation, startArrowRotation,
line.width, line.width,
...@@ -257,15 +298,10 @@ export default class Layer { ...@@ -257,15 +298,10 @@ export default class Layer {
arrowsFeatures.push(startArrowFeature); arrowsFeatures.push(startArrowFeature);
} }
const lastSegment = line.segments[line.segments.length - 1];
const endArrowRotation = getRotation(
[lastSegment.x1, lastSegment.y1],
[lastSegment.x2, lastSegment.y2],
);
const endArrowFeature = this.getLineArrowFeature( const endArrowFeature = this.getLineArrowFeature(
line.endArrow, line.endArrow,
lastSegment.x2, endArrowX,
lastSegment.y2, endArrowY,
line.z, line.z,
endArrowRotation, endArrowRotation,
line.width, line.width,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment