Skip to content

Commit

Permalink
closes #46
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasHalwax committed Jun 5, 2024
1 parent 47b8c4b commit 3ce0c7c
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/renderer/ol/interaction/measure/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ const linestringStyle = feature => {
const styles = []
const geometry = feature.getGeometry()

let numberOfSegments = 0

geometry.forEachSegment((start, end) => {
const segment = new LineString([start, end])
numberOfSegments++
styles.push(new Style({
geometry: segment,
text: new TextStyle({
Expand Down Expand Up @@ -124,7 +127,8 @@ const linestringStyle = feature => {
const lastSegment = new LineString(getLastSegmentCoordinates(geometry))
const alpha = radiansAngle(lastSegment)

/* set style and label for last point */
/* set style and label for last point but only if we have more than one segment */

styles.push(
new Style({
geometry: new Point(geometry.getLastCoordinate()),
Expand All @@ -134,26 +138,29 @@ const linestringStyle = feature => {
color: 'red'
})
}),
text: new TextStyle({
text: length(geometry),
font: FONT,
fill: new Fill({
color: 'black'
}),
stroke: new Stroke({
color: 'white',
width: 5
}),
offsetX: 25 * Math.cos(alpha),
offsetY: -25 * Math.sin(alpha),
placement: 'point',
textAlign: Math.abs(alpha) < Math.PI / 2 ? 'left' : 'right',
overflow: true,
textBaseline: 'ideographic'
})
text: (numberOfSegments === 1)
? ''
: new TextStyle({
text: length(geometry),
font: FONT,
fill: new Fill({
color: 'black'
}),
stroke: new Stroke({
color: 'white',
width: 5
}),
offsetX: 25 * Math.cos(alpha),
offsetY: -25 * Math.sin(alpha),
placement: 'point',
textAlign: Math.abs(alpha) < Math.PI / 2 ? 'left' : 'right',
overflow: true,
textBaseline: 'ideographic'
})
})
)


return styles
}

Expand Down

0 comments on commit 3ce0c7c

Please sign in to comment.