Skip to content

Commit 379ec1b

Browse files
warm-coolguydopenguin
authored andcommitted
refactor: tiny steps in about the right direction
1 parent 670e11b commit 379ec1b

2 files changed

Lines changed: 8 additions & 32 deletions

File tree

src/plugins/draw/utils/createMeasureStyle.ts

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ function calculatePartialDistances(
2929
geometry instanceof Polygon
3030
? geometry.getCoordinates()[0]
3131
: geometry.getCoordinates()
32+
33+
if (!coordinates) {
34+
return styles
35+
}
36+
3237
for (let i = 1; i < coordinates.length; i++) {
3338
const lineString = new LineString([coordinates[i - 1], coordinates[i]])
3439
const lengthInMetres = getLength(lineString, {
@@ -132,24 +137,14 @@ const measureStyle: (
132137
return new Style(styleOptions)
133138
}
134139

135-
// TODO: this overrides the whole style, but should merely add measurements; most of this file can be thrown away, as it should merely add measurement styling now; also wow, that's a lot of type errors!
140+
// TODO: this was createDrawStyle; it is createMeasureStyle now. much of the code is useless and can be removed. Proposal: Instead of overriding all styles, only inject text styles onto the existing/configured style.
136141
export function createMeasureStyle(
137-
drawMode: string,
138142
strokeColor: string,
139-
measureMode: MeasureMode,
143+
measureMode: Exclude<MeasureMode, 'none'>,
140144
projection: Projection,
141145
drawStyle?: DrawPluginOptionsLayerStyle
142146
): Style | StyleFunction {
143147
const defaultFillColor = 'rgba(255, 255, 255, 0.5)'
144-
if (drawMode === 'Point') {
145-
return createPointStyle(
146-
strokeColor,
147-
drawStyle?.circle?.fillColor
148-
? drawStyle.circle.fillColor
149-
: defaultFillColor,
150-
drawStyle?.circle?.radius
151-
)
152-
}
153148
const fillColor = drawStyle?.fill?.color
154149
? drawStyle.fill.color
155150
: defaultFillColor
@@ -169,23 +164,5 @@ export function createMeasureStyle(
169164
color: fillColor,
170165
}),
171166
}
172-
return measureMode === 'none'
173-
? new Style(styleOptions)
174-
: measureStyle(styleOptions, measureMode, projection, drawStyle?.measure)
175-
}
176-
177-
function createPointStyle(
178-
strokeColor: string,
179-
fillColor: Color | ColorLike,
180-
radius = 5
181-
) {
182-
return new Style({
183-
image: new CircleStyle({
184-
radius,
185-
fill: new Fill({
186-
color: fillColor,
187-
}),
188-
stroke: new Stroke({ color: strokeColor }),
189-
}),
190-
})
167+
return measureStyle(styleOptions, measureMode, projection, drawStyle?.measure)
191168
}

src/plugins/draw/utils/interactionManager/createDrawInteractions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export function createDrawInteraction(
6666

6767
const style = makeMeasurement
6868
? createMeasureStyle(
69-
drawMode,
7069
'#000000',
7170
measureMode,
7271
map.getView().getProjection(),

0 commit comments

Comments
 (0)