Skip to content

Commit

Permalink
ammend cluster assignment and style clone
Browse files Browse the repository at this point in the history
  • Loading branch information
dbauszus-glx committed Mar 5, 2024
1 parent f633d2f commit 9e3ae75
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
31 changes: 18 additions & 13 deletions lib/layer/featureStyle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions lib/layer/styleParser.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const iconKeys = new Set([
'anchor',
'scale',
'clusterScale',
'zoomInScale',
'zoomOutScale',
'highlightScale',
'url',
'svg',
'type',
Expand All @@ -16,7 +12,11 @@ const styleKeys = new Set([
'strokeColor',
'strokeWidth',
'strokeOpacity',
'fillOpacity']).union(iconKeys)
'fillOpacity',
'clusterScale',
'zoomInScale',
'zoomOutScale',
'highlightScale']).union(iconKeys)

export default layer => {

Expand Down

0 comments on commit 9e3ae75

Please sign in to comment.