Skip to content

Commit 9df5176

Browse files
committed
refactor: split style memoization-function by displayFeatureCount
1 parent 09ab963 commit 9df5176

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/core/utils/markers.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,19 @@ const memoCountStyle = (getMarker: GetMarkerFunction): GetMarkerFunction => {
129129
}
130130
}
131131

132-
const getStyleFunction: GetMarkerFunction = (style, multi) =>
132+
/**
133+
* The map became a little laggy due to constant re-generation of styles.
134+
* This memoization function optimises this issue by reusing styles.
135+
* */
136+
const memoizeStyle = (getMarker: GetMarkerFunction): GetMarkerFunction => {
137+
const memoizedCountStyle = memoCountStyle(getMarker)
138+
const memoizedStyle = memoStyle(getMarker)
139+
return (style, count, displayFeatureCount) =>
140+
displayFeatureCount
141+
? memoizedCountStyle(style, count, displayFeatureCount)
142+
: memoizedStyle(style, count, displayFeatureCount)
143+
}
144+
133145
new Style({
134146
image: new Icon({
135147
src: (multi ? makeMultiMarker : makeMarker)(style),

0 commit comments

Comments
 (0)