Skip to content
Snippets Groups Projects

feat(vector-map): text placement for modifications

Merged Miłosz Grocholewski requested to merge feat/MIN-62-modifications-text-placement into development
2 files
+ 38
17
Compare changes
  • Side-by-side
  • Inline
Files
2
/* eslint-disable no-magic-numbers */
/* eslint-disable no-magic-numbers */
import { Style, Text } from 'ol/style';
import { Style } from 'ol/style';
import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection';
import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection';
import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke';
import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke';
import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill';
import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill';
@@ -18,6 +18,8 @@ import {
@@ -18,6 +18,8 @@ import {
} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants';
} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants';
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 getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords';
 
import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle';
export type MapElementProps = {
export type MapElementProps = {
shapes: Array<Shape>;
shapes: Array<Shape>;
@@ -175,24 +177,37 @@ export default class MapElement extends BaseMultiPolygon {
@@ -175,24 +177,37 @@ export default class MapElement extends BaseMultiPolygon {
fill: getFill({ color: rgbToHex(modification.fillColor) }),
fill: getFill({ color: rgbToHex(modification.fillColor) }),
zIndex: modification.z,
zIndex: modification.z,
});
});
const modificationText = modification.stateAbbreviation
? modification.stateAbbreviation
: modification.name;
if (modificationText) {
modificationStyle.setText(
new Text({
text: modificationText,
font: `${modification.fontSize}pt Arial`,
textAlign: 'center',
textBaseline: 'middle',
fill: getFill({ color: '#000' }),
overflow: true,
}),
);
this.polygonsTexts.push(modificationText);
}
this.styles.push(modificationStyle);
this.styles.push(modificationStyle);
});
});
 
const modificationText = modification.stateAbbreviation
 
? modification.stateAbbreviation
 
: modification.name;
 
if (modificationText) {
 
const modificationTextCoords = getTextCoords({
 
x: modification.nameX,
 
y: modification.nameY,
 
width: modification.nameWidth,
 
height: modification.nameHeight,
 
fontSize: modification.fontSize,
 
verticalAlign: modification.nameVerticalAlign,
 
horizontalAlign: modification.nameHorizontalAlign,
 
pointToProjection: this.pointToProjection,
 
});
 
const modificationTextPolygon = new Polygon([
 
[modificationTextCoords, modificationTextCoords],
 
]);
 
const modificationTextStyle = getTextStyle({
 
text: modificationText,
 
fontSize: modification.fontSize,
 
color: rgbToHex(BLACK_COLOR),
 
zIndex: modification.z,
 
horizontalAlign: modification.nameHorizontalAlign,
 
});
 
modificationTextStyle.setGeometry(modificationTextPolygon);
 
this.styles.push(modificationTextStyle);
 
this.polygonsTexts.push(modificationText);
 
this.polygons.push(modificationTextPolygon);
 
}
}
}
drawActiveBorder(homodimerShift: number, homodimerOffset: number): void {
drawActiveBorder(homodimerShift: number, homodimerOffset: number): void {
Loading