Skip to content

Commit

Permalink
Fix/4296 old vector style (#4301)
Browse files Browse the repository at this point in the history
* fix: fixed bug of restoring layer opacity when there is no paint property.

* fix: fixed bug of converting maplibre function to step expression.
  • Loading branch information
JinIgarashi authored Oct 21, 2024
1 parent 8c4b7a1 commit 9f9be6b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-chairs-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"geohub": patch
---

fix: fixed bug of converting maplibre function to step expression.
5 changes: 5 additions & 0 deletions .changeset/smooth-candles-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@undp-data/svelte-maplibre-storymap": patch
---

fix: fixed bug of restoring layer opacity when there is no paint property.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
const layer = style?.layers?.find((l) => l.id === layerId);
if (!layer) return 0;
if (layer.layout?.visibility === 'none') {
let invisible = layer.layout?.visibility === 'none';
if (invisible) {
return 0;
}
Expand All @@ -179,11 +180,17 @@
const props: string[] = layerTypes[layer.type];
if (props && props.length > 0) {
for (const prop of props) {
const v = layer.paint[prop];
opacity = v ?? 1;
if (layer.paint && prop in layer.paint) {
const v = layer.paint[prop];
opacity = v;
}
}
}
if (opacity === 0 && !invisible) {
opacity = 1;
}
return opacity;
};
Expand Down
13 changes: 10 additions & 3 deletions sites/geohub/src/components/pages/map/layers/LayerEdit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
const layer = style?.layers?.find((l) => l.id === $editingLayerStore?.id);
if (!layer) return 0;
if (layer.layout?.visibility === 'none') {
let invisible = layer.layout?.visibility === 'none';
if (invisible) {
return 0;
}
Expand All @@ -53,11 +54,17 @@
const props: string[] = layerTypes[layer.type];
if (props && props.length > 0) {
for (const prop of props) {
const v = layer.paint[prop];
opacity = v ?? 1;
if (layer.paint && prop in layer.paint) {
const v = layer.paint[prop];
opacity = v;
}
}
}
if (opacity === 0 && !invisible) {
opacity = 1;
}
return opacity;
};
Expand Down
13 changes: 10 additions & 3 deletions sites/geohub/src/components/pages/map/layers/LayerTemplate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@
const l = style?.layers?.find((l) => l.id === layer.id);
if (!l) return 0;
if (l.layout?.visibility === 'none') {
let invisible = l.layout?.visibility === 'none';
if (invisible) {
return 0;
}
Expand All @@ -216,11 +217,17 @@
const props: string[] = layerTypes[l.type];
if (props && props.length > 0) {
for (const prop of props) {
const v = l.paint[prop];
opacity = v ?? 1;
if (l.paint && prop in l.paint) {
const v = l.paint[prop];
opacity = v;
}
}
}
if (opacity === 0 && !invisible) {
opacity = 1;
}
return opacity;
};
Expand Down
14 changes: 12 additions & 2 deletions sites/geohub/src/lib/helper/convertFunctionToExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ export const convertFunctionToExpression = (value: unknown, defaultValue: unknow
const steps: unknown[] = ['step', ['get', property]];

if ('stops' in value && Array.isArray(value.stops)) {
let thresholds: number[] = [];
const colors: string[] = [];
for (let i = 0; i < value.stops.length; i++) {
const stop = value.stops[i];
const c: string = stop[1];
const v: number = stop[0];
thresholds.push(v);
colors.push(c);
}
// first value is minimum value in the dataset, it should be skiped for step expression.
thresholds = thresholds.splice(1);

colors.forEach((c, index) => {
const v: number = thresholds[index];
steps.push(c);
if (i !== value.stops.length - 1) {
if (index !== colors.length - 1) {
steps.push(v);
}
}
});
}
return steps;
} else if ('type' in value && value.type === 'categorical') {
Expand Down

0 comments on commit 9f9be6b

Please sign in to comment.