diff --git a/lib/layer/featureStyle.mjs b/lib/layer/featureStyle.mjs index 6fc98afad..eb6cf964f 100644 --- a/lib/layer/featureStyle.mjs +++ b/lib/layer/featureStyle.mjs @@ -25,17 +25,21 @@ export default layer => { return null } - // Assign default style as feature.style. - feature.style = structuredClone(layer.style.default) - // Assign geometryType from geometry. feature.geometryType ??= feature.getGeometry().getType(); - // Apply theme style to style object. - mapp.layer.themes[layer.style.theme?.type]?.(layer.style.theme, feature) + if (Object.hasOwn(mapp.layer.themes, layer.style.theme?.type)) { + + // Apply theme style to style object. + mapp.layer.themes[layer.style.theme?.type]?.(layer.style.theme, feature) + } else { + + // Assign default style as feature.style. + feature.style = structuredClone(layer.style.default) + } - // Style point features. - pointStyle(feature) + // Style cluster point features. + clusterStyle(feature) // Assign highlight style if required. highlightStyle(feature) @@ -90,17 +94,18 @@ export default layer => { } } - function pointStyle(feature) { + function clusterStyle(feature) { if (feature.geometryType !== 'Point') return; - // Only assign cluster style to features with a count property. - if (layer.style.cluster && feature.properties?.count > 1) { + if (!feature.properties?.count) return; - // The cluster style must not be modified in place. - const clusterIcon = structuredClone(layer.style.cluster) + // Assign cluster style to features with a count property. + if (layer.style.cluster) { - feature.style.icon = {...clusterIcon, ...feature.style.icon} + feature.style = { + icon: structuredClone(layer.style.cluster) + } } // Cluster icons will NOT scale different to single locations if the clusterScale is not set in the cluster style. diff --git a/lib/layer/styleParser.mjs b/lib/layer/styleParser.mjs index 8ff79db18..76e862f92 100644 --- a/lib/layer/styleParser.mjs +++ b/lib/layer/styleParser.mjs @@ -1,10 +1,6 @@ const iconKeys = new Set([ 'anchor', 'scale', - 'clusterScale', - 'zoomInScale', - 'zoomOutScale', - 'highlightScale', 'url', 'svg', 'type', @@ -16,7 +12,11 @@ const styleKeys = new Set([ 'strokeColor', 'strokeWidth', 'strokeOpacity', - 'fillOpacity']).union(iconKeys) + 'fillOpacity', + 'clusterScale', + 'zoomInScale', + 'zoomOutScale', + 'highlightScale']).union(iconKeys) export default layer => {