Skip to content

Commit

Permalink
fix: style
Browse files Browse the repository at this point in the history
  • Loading branch information
majkshkurti committed Jul 2, 2024
1 parent 585d8ec commit d30a31b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
30 changes: 22 additions & 8 deletions apps/web/components/map/panels/style/LayerStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,10 @@ const LayerStylePanel = ({ projectId }: { projectId: string }) => {
);

const createColorMapFromClassBreaks = useCallback(
(colors: string[], breakValues: LayerClassBreaks) => {
const breaks = [breakValues.min.toString()];
breakValues.breaks.forEach((b) => {
breaks.push(b.toString());
});
(colors: string[], breakValues: string[]) => {
const colorMap = [] as ColorMap;
colors.forEach((color, index) => {
const breakValue = breaks[index] || "0";
const breakValue = breakValues[index] || "0";
colorMap.push([[breakValue], color]);
});
return colorMap;
Expand All @@ -93,10 +89,28 @@ const LayerStylePanel = ({ projectId }: { projectId: string }) => {
const existingBreaks =
activeLayer.properties[`${updateType}_scale_breaks`];
if (classBreakType === classBreaks.Enum.custom_breaks && existingBreaks) {
const breakValues = [] as string[];
if (classBreakType === activeLayer.properties[`${updateType}_scale`]) {
const colorMap =
newStyle[`${updateType}_range`]?.color_map;
if (colorMap) {
colorMap.forEach((colorMapItem) => {
if (colorMapItem?.[0]?.[0] !== undefined)
breakValues.push(colorMapItem[0][0]);
});
}
} else {
if (existingBreaks) {
breakValues.push(existingBreaks.min.toString());
existingBreaks.breaks.forEach((value) => {
breakValues.push(value.toString());
});
}
}
newStyle[`${updateType}_range`]["color_map"] =
createColorMapFromClassBreaks(
activeLayer.properties[`${updateType}_range`]?.colors || [],
existingBreaks,
newStyle[`${updateType}_range`]?.colors || [],
breakValues,
);
return;
}
Expand Down
7 changes: 5 additions & 2 deletions apps/web/lib/transformers/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function getMapboxStyleColor(
(!fieldName ||
!colors ||
data.properties[`${type}_scale_breaks`]?.breaks.length !==
colors.length - 1)) ||
colors.length - 1)) ||
(colorScale === "custom_breaks" && (!colorMaps || !fieldName))
) {
return data.properties[type]
Expand Down Expand Up @@ -126,8 +126,11 @@ export function getMapboxStyleColor(
const config = ["step", ["get", fieldName], ...colorSteps];
return config;
}
const breakValues = data.properties[`${type}_scale_breaks`];

let _breakValues = data.properties[`${type}_scale_breaks`]?.breaks;
let _breakValues = breakValues?.breaks ? [...breakValues?.breaks] : [];
if (_breakValues && breakValues?.max !== undefined)
_breakValues.push(breakValues?.max);
let _colors = [...colors];
if (_breakValues) {
const combined = _breakValues.map((value, index) => [[value], colors[index]]);
Expand Down

0 comments on commit d30a31b

Please sign in to comment.