openlayers-style-editor 0.2.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/components/basedOnRules.d.ts +1 -0
- package/dist/index.cjs +105 -61
- package/dist/index.js +105 -61
- package/dist/openlayers-style-editor.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,6 +60,10 @@ A detailed explanation of each mode can be found [here](https://resources.arcgis
|
|
|
60
60
|
|
|
61
61
|
- **Based on Rules:** Allows the user to change the layer's color, opacity, and stroke based on rules defined by the user. Each rule is composed by a name, a filter, and a renderer. The filter is a logical expression that defines which features will be styled with the renderer of the rule.
|
|
62
62
|
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
This project is licensed under the MIT License.
|
|
66
|
+
|
|
63
67
|
## Installation
|
|
64
68
|
|
|
65
69
|
Depending on the installed package provider, this package can be installed with one of the following commands.
|
package/dist/index.cjs
CHANGED
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
return GraduatedModes;
|
|
106
106
|
}({});
|
|
107
107
|
function getCategorizedStyle(attribute, colors, outlineColor, outlineWidth, defaultColor) {
|
|
108
|
-
let outlineColorCopy = outlineColor ? outlineColor : void 0;
|
|
108
|
+
let outlineColorCopy = outlineColor ? [...outlineColor] : void 0;
|
|
109
109
|
if (outlineWidth == 0 && outlineColorCopy != void 0) outlineColorCopy[3] = 0;
|
|
110
110
|
else if (outlineWidth != void 0 && outlineWidth > 0 && outlineColorCopy) outlineColorCopy[3] = 1;
|
|
111
111
|
let aux = [];
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
function singleColorStyle(color, outlineColor, outlineWidth) {
|
|
144
|
-
let outlineColorCopy = outlineColor ? outlineColor : void 0;
|
|
144
|
+
let outlineColorCopy = outlineColor ? [...outlineColor] : void 0;
|
|
145
145
|
if (outlineWidth == 0 && outlineColorCopy != void 0) outlineColorCopy[3] = 0;
|
|
146
146
|
else if (outlineWidth != void 0 && outlineWidth > 0 && outlineColorCopy) outlineColorCopy[3] = 1;
|
|
147
147
|
return {
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
function getGraduatedStyle(attribute, ramp, outlineColor, outlineWidth) {
|
|
180
|
-
let outlineColorCopy = outlineColor ? outlineColor : void 0;
|
|
180
|
+
let outlineColorCopy = outlineColor ? [...outlineColor] : void 0;
|
|
181
181
|
if (outlineWidth == 0 && outlineColorCopy != void 0) outlineColorCopy[3] = 0;
|
|
182
182
|
else if (outlineWidth != void 0 && outlineWidth > 0 && outlineColorCopy) outlineColorCopy[3] = 1;
|
|
183
183
|
let aux = [];
|
|
@@ -188,7 +188,7 @@
|
|
|
188
188
|
aux.push(stop.value);
|
|
189
189
|
aux.push(stop.color);
|
|
190
190
|
});
|
|
191
|
-
|
|
191
|
+
return {
|
|
192
192
|
"stroke-color": [
|
|
193
193
|
"case",
|
|
194
194
|
[
|
|
@@ -211,8 +211,6 @@
|
|
|
211
211
|
],
|
|
212
212
|
"fill-color": aux
|
|
213
213
|
};
|
|
214
|
-
console.log(res);
|
|
215
|
-
return res;
|
|
216
214
|
}
|
|
217
215
|
function getRendererOpacity(renderer) {
|
|
218
216
|
if (renderer.type == RenderType.Unique) return renderer.rendererOL["fill-color"][3] * 100;
|
|
@@ -306,18 +304,27 @@
|
|
|
306
304
|
return (0, ol_color_js.fromString)("#" + (16777216 + Math.random() * 16777215).toString(16).substr(1, 6));
|
|
307
305
|
}
|
|
308
306
|
function getByRulesStyle(filters, idFieldName, elseFilter) {
|
|
309
|
-
|
|
307
|
+
console.log(filters);
|
|
308
|
+
if (filters.length === 0 || filters.filter((f) => f.ids.length > 0).length == 0) if (elseFilter) {
|
|
310
309
|
let fillColor = getStyleColorsAndValues(elseFilter.symbol.rendererOL, RenderType.Unique)[0].color;
|
|
311
310
|
let stroke = getRendererColorAndSizeStroke(elseFilter.symbol);
|
|
312
311
|
return {
|
|
313
312
|
"stroke-color": Object.values(stroke.color),
|
|
314
313
|
"stroke-width": stroke.size,
|
|
315
|
-
"fill-color": fillColor
|
|
314
|
+
"fill-color": fillColor,
|
|
315
|
+
"_rules": filters.map((f) => ({
|
|
316
|
+
expression: f.filter.friendlyExpression,
|
|
317
|
+
render: f.filter.symbol
|
|
318
|
+
}))
|
|
316
319
|
};
|
|
317
320
|
} else return {
|
|
318
321
|
"stroke-color": (0, ol_color_js.fromString)("#000000"),
|
|
319
322
|
"stroke-width": 1,
|
|
320
|
-
"fill-color": (0, ol_color_js.fromString)("#ffffff")
|
|
323
|
+
"fill-color": (0, ol_color_js.fromString)("#ffffff"),
|
|
324
|
+
"_rules": filters.map((f) => ({
|
|
325
|
+
expression: f.filter.friendlyExpression,
|
|
326
|
+
render: f.filter.symbol
|
|
327
|
+
}))
|
|
321
328
|
};
|
|
322
329
|
let fillColorArray = ["case"];
|
|
323
330
|
let strokeColorArray = ["case"];
|
|
@@ -350,11 +357,17 @@
|
|
|
350
357
|
strokeColorArray.push((0, ol_color_js.fromString)("#000000"));
|
|
351
358
|
strokeWidthArray.push(1);
|
|
352
359
|
}
|
|
353
|
-
|
|
360
|
+
const res = {
|
|
354
361
|
"stroke-color": strokeColorArray,
|
|
355
362
|
"stroke-width": strokeWidthArray,
|
|
356
|
-
"fill-color": fillColorArray
|
|
363
|
+
"fill-color": fillColorArray,
|
|
364
|
+
"_rules": filters.map((f) => ({
|
|
365
|
+
expression: f.filter.friendlyExpression,
|
|
366
|
+
render: f.filter.symbol
|
|
367
|
+
}))
|
|
357
368
|
};
|
|
369
|
+
console.log(res);
|
|
370
|
+
return res;
|
|
358
371
|
}
|
|
359
372
|
//#endregion
|
|
360
373
|
//#region src/components/uniqueSymbol.tsx
|
|
@@ -366,19 +379,34 @@
|
|
|
366
379
|
const strokeWidthLabel = t("categorized.stroke_width");
|
|
367
380
|
const concludeLabel = t("common.conclude");
|
|
368
381
|
const start = "#18d7ba";
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
+
const getStatesFromRenderer = (renderer) => {
|
|
383
|
+
const currentStyle = renderer.field ? null : renderer.rendererOL;
|
|
384
|
+
const color = currentStyle && currentStyle["fill-color"] ? currentStyle["fill-color"] : (0, ol_color_js.fromString)(start);
|
|
385
|
+
let auxBorder;
|
|
386
|
+
if (currentStyle) if (currentStyle["stroke-color"]) if (currentStyle["stroke-color"][0] == "case") auxBorder = currentStyle["stroke-color"][3];
|
|
387
|
+
else auxBorder = currentStyle["stroke-color"];
|
|
388
|
+
else auxBorder = (0, ol_color_js.fromString)("#000000");
|
|
389
|
+
else auxBorder = (0, ol_color_js.fromString)("#000000");
|
|
390
|
+
let auxBorderWidth;
|
|
391
|
+
if (currentStyle) if (currentStyle["stroke-width"] instanceof Array) auxBorderWidth = currentStyle["stroke-width"][3];
|
|
392
|
+
else auxBorderWidth = currentStyle["stroke-width"];
|
|
393
|
+
else auxBorderWidth = 0;
|
|
394
|
+
return {
|
|
395
|
+
color,
|
|
396
|
+
auxBorder,
|
|
397
|
+
auxBorderWidth
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
const initialStates = getStatesFromRenderer(layerCurrentRenderer);
|
|
401
|
+
const [color, setColor] = (0, react.useState)(initialStates.color);
|
|
402
|
+
const [borderColor, setBorderColor] = (0, react.useState)(initialStates.auxBorder);
|
|
403
|
+
const [borderThickness, setBorderThickness] = (0, react.useState)(initialStates.auxBorderWidth);
|
|
404
|
+
(0, react.useEffect)(() => {
|
|
405
|
+
const states = getStatesFromRenderer(layerCurrentRenderer);
|
|
406
|
+
setColor(states.color);
|
|
407
|
+
setBorderColor(states.auxBorder);
|
|
408
|
+
setBorderThickness(states.auxBorderWidth);
|
|
409
|
+
}, [layerCurrentRenderer]);
|
|
382
410
|
function createRenderUnique(color, outlineColor, outlineWidth) {
|
|
383
411
|
return singleColorStyle(color, outlineColor, outlineWidth);
|
|
384
412
|
}
|
|
@@ -1328,7 +1356,7 @@
|
|
|
1328
1356
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(primereact_dropdown_dropdown_esm_js.Dropdown, {
|
|
1329
1357
|
value: selectedAttr,
|
|
1330
1358
|
onChange: (e) => changeAttribute(e),
|
|
1331
|
-
options: attr,
|
|
1359
|
+
options: attr.filter((a) => a.values && a.values.length > 0 && a.values.length < 200),
|
|
1332
1360
|
optionLabel: "name",
|
|
1333
1361
|
itemTemplate: (option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
|
|
1334
1362
|
option.name,
|
|
@@ -1436,6 +1464,7 @@
|
|
|
1436
1464
|
value: table,
|
|
1437
1465
|
selectionMode: rowClick ? null : "checkbox",
|
|
1438
1466
|
tableStyle: { minWidth: "25rem" },
|
|
1467
|
+
dataKey: "value",
|
|
1439
1468
|
selection: table.filter((tr) => tr.visible),
|
|
1440
1469
|
onSelectionChange: (event) => {
|
|
1441
1470
|
const value = event.value;
|
|
@@ -1696,7 +1725,6 @@
|
|
|
1696
1725
|
}
|
|
1697
1726
|
case GraduatedModes.DefinedInterval: {
|
|
1698
1727
|
const interval = range / intervalSize;
|
|
1699
|
-
console.log("interval", interval, intervalSize);
|
|
1700
1728
|
for (let i = 0; i <= interval; i++) stops.push({
|
|
1701
1729
|
value: min + intervalSize * i,
|
|
1702
1730
|
color: (0, ol_color_js.fromString)("rgb(0,0,0)")
|
|
@@ -1865,6 +1893,10 @@
|
|
|
1865
1893
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("b", { children: [classesNumberLabel, ":"] })
|
|
1866
1894
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(primereact_inputnumber_inputnumber_esm_js.InputNumber, {
|
|
1867
1895
|
value: classNo,
|
|
1896
|
+
min: 0,
|
|
1897
|
+
max: 50,
|
|
1898
|
+
inputMode: "numeric",
|
|
1899
|
+
maxFractionDigits: 0,
|
|
1868
1900
|
locale,
|
|
1869
1901
|
onChange: async (e) => {
|
|
1870
1902
|
setClassNo(e.value);
|
|
@@ -1947,15 +1979,17 @@
|
|
|
1947
1979
|
placeholder: valueLabel,
|
|
1948
1980
|
allowEmpty: false,
|
|
1949
1981
|
locale,
|
|
1982
|
+
inputMode: "numeric",
|
|
1950
1983
|
min: stops[0].value,
|
|
1951
|
-
|
|
1984
|
+
maxFractionDigits: 3,
|
|
1985
|
+
max: stops[stops.length - 1].value,
|
|
1952
1986
|
disabled: index === 0 || selectedMode != GraduatedModes.Manual || index === stops.length - 1,
|
|
1953
1987
|
onChange: (e) => {
|
|
1954
1988
|
const aux = [...stops];
|
|
1955
1989
|
aux[index].value = e.value;
|
|
1956
1990
|
setStops(aux);
|
|
1957
1991
|
},
|
|
1958
|
-
value:
|
|
1992
|
+
value: stops[index].value
|
|
1959
1993
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MyColorPicker, {
|
|
1960
1994
|
color: value.color,
|
|
1961
1995
|
onChange: (e) => {
|
|
@@ -2311,6 +2345,7 @@
|
|
|
2311
2345
|
selectedAttribute?.type != AttributeTypeEnum.BOOLEAN && selectedFunction?.name != t("filters.is_null") && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(primereact_dropdown_dropdown_esm_js.Dropdown, {
|
|
2312
2346
|
value: selectedValue,
|
|
2313
2347
|
editable: true,
|
|
2348
|
+
maxLength: 150,
|
|
2314
2349
|
onChange: (e) => {
|
|
2315
2350
|
setSelectedValue(e.value);
|
|
2316
2351
|
update(void 0, e.value, void 0);
|
|
@@ -2743,6 +2778,7 @@
|
|
|
2743
2778
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(primereact_inputtext_inputtext_esm_js.InputText, {
|
|
2744
2779
|
id: "title",
|
|
2745
2780
|
value: queryWidget.title,
|
|
2781
|
+
maxLength: 100,
|
|
2746
2782
|
onChange: (e) => setTitle(e.target.value)
|
|
2747
2783
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
2748
2784
|
htmlFor: "title",
|
|
@@ -2860,40 +2896,41 @@
|
|
|
2860
2896
|
{
|
|
2861
2897
|
field: "filterJson",
|
|
2862
2898
|
header: expressionLabel,
|
|
2863
|
-
body: (data) =>
|
|
2864
|
-
if (!data.filterJson) return "";
|
|
2865
|
-
try {
|
|
2866
|
-
const parsed = JSON.parse(data.filterJson);
|
|
2867
|
-
const formatCondition = (cond) => {
|
|
2868
|
-
const operator = Object.keys(cond)[0];
|
|
2869
|
-
const value = cond[operator];
|
|
2870
|
-
if (operator === "!" && value.hasOwnProperty("in")) {
|
|
2871
|
-
const innerCondition = value["in"];
|
|
2872
|
-
return `${innerCondition[1].var} not in ${JSON.stringify(innerCondition[0])}`;
|
|
2873
|
-
}
|
|
2874
|
-
if (operator === "==" && Array.isArray(value) && value[0] && value[0].hasOwnProperty("substr")) {
|
|
2875
|
-
const substr = value[0].substr;
|
|
2876
|
-
const valueString = value[1];
|
|
2877
|
-
return `${substr[0].var} ${substr[1] < 0 ? "endsWith" : "startsWith"} "${valueString}"`;
|
|
2878
|
-
}
|
|
2879
|
-
if (operator === "==" && Array.isArray(value) && value[0] === null) return `${value[1].var} is null`;
|
|
2880
|
-
const max = Array.isArray(value) ? value[0] : null;
|
|
2881
|
-
if (max && max.hasOwnProperty("var")) return `${max.var} ${operator} ${JSON.stringify(value[1])}`;
|
|
2882
|
-
if (Array.isArray(value) && value[1] && value[1].hasOwnProperty("var")) return `${value[1].var} ${operator} ${JSON.stringify(max)}`;
|
|
2883
|
-
return JSON.stringify(cond);
|
|
2884
|
-
};
|
|
2885
|
-
const isAll = parsed.hasOwnProperty("and");
|
|
2886
|
-
const isAny = parsed.hasOwnProperty("or");
|
|
2887
|
-
if (isAll || isAny) {
|
|
2888
|
-
const operator = isAll ? " AND " : " OR ";
|
|
2889
|
-
return parsed[isAll ? "and" : "or"].map(formatCondition).join(operator);
|
|
2890
|
-
} else return formatCondition(parsed);
|
|
2891
|
-
} catch (e) {
|
|
2892
|
-
return data.filterJson;
|
|
2893
|
-
}
|
|
2894
|
-
}
|
|
2899
|
+
body: (data) => getFriendlyExpression(data)
|
|
2895
2900
|
}
|
|
2896
2901
|
];
|
|
2902
|
+
function getFriendlyExpression(data) {
|
|
2903
|
+
if (!data.filterJson) return "";
|
|
2904
|
+
try {
|
|
2905
|
+
const parsed = JSON.parse(data.filterJson);
|
|
2906
|
+
const formatCondition = (cond) => {
|
|
2907
|
+
const operator = Object.keys(cond)[0];
|
|
2908
|
+
const value = cond[operator];
|
|
2909
|
+
if (operator === "!" && value.hasOwnProperty("in")) {
|
|
2910
|
+
const innerCondition = value["in"];
|
|
2911
|
+
return `${innerCondition[1].var} not in ${JSON.stringify(innerCondition[0])}`;
|
|
2912
|
+
}
|
|
2913
|
+
if (operator === "==" && Array.isArray(value) && value[0] && value[0].hasOwnProperty("substr")) {
|
|
2914
|
+
const substr = value[0].substr;
|
|
2915
|
+
const valueString = value[1];
|
|
2916
|
+
return `${substr[0].var} ${substr[1] < 0 ? "endsWith" : "startsWith"} "${valueString}"`;
|
|
2917
|
+
}
|
|
2918
|
+
if (operator === "==" && Array.isArray(value) && value[0] === null) return `${value[1].var} is null`;
|
|
2919
|
+
const max = Array.isArray(value) ? value[0] : null;
|
|
2920
|
+
if (max && max.hasOwnProperty("var")) return `${max.var} ${operator} ${JSON.stringify(value[1])}`;
|
|
2921
|
+
if (Array.isArray(value) && value[1] && value[1].hasOwnProperty("var")) return `${value[1].var} ${operator} ${JSON.stringify(max)}`;
|
|
2922
|
+
return JSON.stringify(cond);
|
|
2923
|
+
};
|
|
2924
|
+
const isAll = parsed.hasOwnProperty("and");
|
|
2925
|
+
const isAny = parsed.hasOwnProperty("or");
|
|
2926
|
+
if (isAll || isAny) {
|
|
2927
|
+
const operator = isAll ? " AND " : " OR ";
|
|
2928
|
+
return parsed[isAll ? "and" : "or"].map(formatCondition).join(operator);
|
|
2929
|
+
} else return formatCondition(parsed);
|
|
2930
|
+
} catch (e) {
|
|
2931
|
+
return data.filterJson;
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2897
2934
|
function addFilter(filter) {
|
|
2898
2935
|
setRules([...rules, filter]);
|
|
2899
2936
|
}
|
|
@@ -3006,11 +3043,18 @@
|
|
|
3006
3043
|
ids: res
|
|
3007
3044
|
});
|
|
3008
3045
|
});
|
|
3046
|
+
const completedFilters = appliedFilters.map((r) => ({
|
|
3047
|
+
ids: [...r.ids],
|
|
3048
|
+
filter: {
|
|
3049
|
+
...r.filter,
|
|
3050
|
+
friendlyExpression: getFriendlyExpression(r.filter)
|
|
3051
|
+
}
|
|
3052
|
+
}));
|
|
3009
3053
|
applyRenderer({
|
|
3010
3054
|
type: RenderType.ByRules,
|
|
3011
3055
|
field: selectedAttribute.name,
|
|
3012
3056
|
filters: rules,
|
|
3013
|
-
rendererOL: getByRulesStyle(
|
|
3057
|
+
rendererOL: getByRulesStyle(completedFilters, selectedAttribute.name, rules.find((r) => r.isElse))
|
|
3014
3058
|
});
|
|
3015
3059
|
setVisible(false);
|
|
3016
3060
|
}
|
package/dist/index.js
CHANGED
|
@@ -73,7 +73,7 @@ var GraduatedModes = /* @__PURE__ */ function(GraduatedModes) {
|
|
|
73
73
|
return GraduatedModes;
|
|
74
74
|
}({});
|
|
75
75
|
function getCategorizedStyle(attribute, colors, outlineColor, outlineWidth, defaultColor) {
|
|
76
|
-
let outlineColorCopy = outlineColor ? outlineColor : void 0;
|
|
76
|
+
let outlineColorCopy = outlineColor ? [...outlineColor] : void 0;
|
|
77
77
|
if (outlineWidth == 0 && outlineColorCopy != void 0) outlineColorCopy[3] = 0;
|
|
78
78
|
else if (outlineWidth != void 0 && outlineWidth > 0 && outlineColorCopy) outlineColorCopy[3] = 1;
|
|
79
79
|
let aux = [];
|
|
@@ -109,7 +109,7 @@ function getCategorizedStyle(attribute, colors, outlineColor, outlineWidth, defa
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
function singleColorStyle(color, outlineColor, outlineWidth) {
|
|
112
|
-
let outlineColorCopy = outlineColor ? outlineColor : void 0;
|
|
112
|
+
let outlineColorCopy = outlineColor ? [...outlineColor] : void 0;
|
|
113
113
|
if (outlineWidth == 0 && outlineColorCopy != void 0) outlineColorCopy[3] = 0;
|
|
114
114
|
else if (outlineWidth != void 0 && outlineWidth > 0 && outlineColorCopy) outlineColorCopy[3] = 1;
|
|
115
115
|
return {
|
|
@@ -145,7 +145,7 @@ function singleColorStyleForLines(color) {
|
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
147
|
function getGraduatedStyle(attribute, ramp, outlineColor, outlineWidth) {
|
|
148
|
-
let outlineColorCopy = outlineColor ? outlineColor : void 0;
|
|
148
|
+
let outlineColorCopy = outlineColor ? [...outlineColor] : void 0;
|
|
149
149
|
if (outlineWidth == 0 && outlineColorCopy != void 0) outlineColorCopy[3] = 0;
|
|
150
150
|
else if (outlineWidth != void 0 && outlineWidth > 0 && outlineColorCopy) outlineColorCopy[3] = 1;
|
|
151
151
|
let aux = [];
|
|
@@ -156,7 +156,7 @@ function getGraduatedStyle(attribute, ramp, outlineColor, outlineWidth) {
|
|
|
156
156
|
aux.push(stop.value);
|
|
157
157
|
aux.push(stop.color);
|
|
158
158
|
});
|
|
159
|
-
|
|
159
|
+
return {
|
|
160
160
|
"stroke-color": [
|
|
161
161
|
"case",
|
|
162
162
|
[
|
|
@@ -179,8 +179,6 @@ function getGraduatedStyle(attribute, ramp, outlineColor, outlineWidth) {
|
|
|
179
179
|
],
|
|
180
180
|
"fill-color": aux
|
|
181
181
|
};
|
|
182
|
-
console.log(res);
|
|
183
|
-
return res;
|
|
184
182
|
}
|
|
185
183
|
function getRendererOpacity(renderer) {
|
|
186
184
|
if (renderer.type == RenderType.Unique) return renderer.rendererOL["fill-color"][3] * 100;
|
|
@@ -274,18 +272,27 @@ function generateRandomColor() {
|
|
|
274
272
|
return fromString("#" + (16777216 + Math.random() * 16777215).toString(16).substr(1, 6));
|
|
275
273
|
}
|
|
276
274
|
function getByRulesStyle(filters, idFieldName, elseFilter) {
|
|
277
|
-
|
|
275
|
+
console.log(filters);
|
|
276
|
+
if (filters.length === 0 || filters.filter((f) => f.ids.length > 0).length == 0) if (elseFilter) {
|
|
278
277
|
let fillColor = getStyleColorsAndValues(elseFilter.symbol.rendererOL, RenderType.Unique)[0].color;
|
|
279
278
|
let stroke = getRendererColorAndSizeStroke(elseFilter.symbol);
|
|
280
279
|
return {
|
|
281
280
|
"stroke-color": Object.values(stroke.color),
|
|
282
281
|
"stroke-width": stroke.size,
|
|
283
|
-
"fill-color": fillColor
|
|
282
|
+
"fill-color": fillColor,
|
|
283
|
+
"_rules": filters.map((f) => ({
|
|
284
|
+
expression: f.filter.friendlyExpression,
|
|
285
|
+
render: f.filter.symbol
|
|
286
|
+
}))
|
|
284
287
|
};
|
|
285
288
|
} else return {
|
|
286
289
|
"stroke-color": fromString("#000000"),
|
|
287
290
|
"stroke-width": 1,
|
|
288
|
-
"fill-color": fromString("#ffffff")
|
|
291
|
+
"fill-color": fromString("#ffffff"),
|
|
292
|
+
"_rules": filters.map((f) => ({
|
|
293
|
+
expression: f.filter.friendlyExpression,
|
|
294
|
+
render: f.filter.symbol
|
|
295
|
+
}))
|
|
289
296
|
};
|
|
290
297
|
let fillColorArray = ["case"];
|
|
291
298
|
let strokeColorArray = ["case"];
|
|
@@ -318,11 +325,17 @@ function getByRulesStyle(filters, idFieldName, elseFilter) {
|
|
|
318
325
|
strokeColorArray.push(fromString("#000000"));
|
|
319
326
|
strokeWidthArray.push(1);
|
|
320
327
|
}
|
|
321
|
-
|
|
328
|
+
const res = {
|
|
322
329
|
"stroke-color": strokeColorArray,
|
|
323
330
|
"stroke-width": strokeWidthArray,
|
|
324
|
-
"fill-color": fillColorArray
|
|
331
|
+
"fill-color": fillColorArray,
|
|
332
|
+
"_rules": filters.map((f) => ({
|
|
333
|
+
expression: f.filter.friendlyExpression,
|
|
334
|
+
render: f.filter.symbol
|
|
335
|
+
}))
|
|
325
336
|
};
|
|
337
|
+
console.log(res);
|
|
338
|
+
return res;
|
|
326
339
|
}
|
|
327
340
|
//#endregion
|
|
328
341
|
//#region src/components/uniqueSymbol.tsx
|
|
@@ -334,19 +347,34 @@ var UniqueSymbol = (props) => {
|
|
|
334
347
|
const strokeWidthLabel = t("categorized.stroke_width");
|
|
335
348
|
const concludeLabel = t("common.conclude");
|
|
336
349
|
const start = "#18d7ba";
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
+
const getStatesFromRenderer = (renderer) => {
|
|
351
|
+
const currentStyle = renderer.field ? null : renderer.rendererOL;
|
|
352
|
+
const color = currentStyle && currentStyle["fill-color"] ? currentStyle["fill-color"] : fromString(start);
|
|
353
|
+
let auxBorder;
|
|
354
|
+
if (currentStyle) if (currentStyle["stroke-color"]) if (currentStyle["stroke-color"][0] == "case") auxBorder = currentStyle["stroke-color"][3];
|
|
355
|
+
else auxBorder = currentStyle["stroke-color"];
|
|
356
|
+
else auxBorder = fromString("#000000");
|
|
357
|
+
else auxBorder = fromString("#000000");
|
|
358
|
+
let auxBorderWidth;
|
|
359
|
+
if (currentStyle) if (currentStyle["stroke-width"] instanceof Array) auxBorderWidth = currentStyle["stroke-width"][3];
|
|
360
|
+
else auxBorderWidth = currentStyle["stroke-width"];
|
|
361
|
+
else auxBorderWidth = 0;
|
|
362
|
+
return {
|
|
363
|
+
color,
|
|
364
|
+
auxBorder,
|
|
365
|
+
auxBorderWidth
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
const initialStates = getStatesFromRenderer(layerCurrentRenderer);
|
|
369
|
+
const [color, setColor] = useState(initialStates.color);
|
|
370
|
+
const [borderColor, setBorderColor] = useState(initialStates.auxBorder);
|
|
371
|
+
const [borderThickness, setBorderThickness] = useState(initialStates.auxBorderWidth);
|
|
372
|
+
useEffect(() => {
|
|
373
|
+
const states = getStatesFromRenderer(layerCurrentRenderer);
|
|
374
|
+
setColor(states.color);
|
|
375
|
+
setBorderColor(states.auxBorder);
|
|
376
|
+
setBorderThickness(states.auxBorderWidth);
|
|
377
|
+
}, [layerCurrentRenderer]);
|
|
350
378
|
function createRenderUnique(color, outlineColor, outlineWidth) {
|
|
351
379
|
return singleColorStyle(color, outlineColor, outlineWidth);
|
|
352
380
|
}
|
|
@@ -1296,7 +1324,7 @@ var Categorized = (props) => {
|
|
|
1296
1324
|
}), /* @__PURE__ */ jsx(Dropdown, {
|
|
1297
1325
|
value: selectedAttr,
|
|
1298
1326
|
onChange: (e) => changeAttribute(e),
|
|
1299
|
-
options: attr,
|
|
1327
|
+
options: attr.filter((a) => a.values && a.values.length > 0 && a.values.length < 200),
|
|
1300
1328
|
optionLabel: "name",
|
|
1301
1329
|
itemTemplate: (option) => /* @__PURE__ */ jsxs("span", { children: [
|
|
1302
1330
|
option.name,
|
|
@@ -1404,6 +1432,7 @@ var Categorized = (props) => {
|
|
|
1404
1432
|
value: table,
|
|
1405
1433
|
selectionMode: rowClick ? null : "checkbox",
|
|
1406
1434
|
tableStyle: { minWidth: "25rem" },
|
|
1435
|
+
dataKey: "value",
|
|
1407
1436
|
selection: table.filter((tr) => tr.visible),
|
|
1408
1437
|
onSelectionChange: (event) => {
|
|
1409
1438
|
const value = event.value;
|
|
@@ -1664,7 +1693,6 @@ var Graduated = (props) => {
|
|
|
1664
1693
|
}
|
|
1665
1694
|
case GraduatedModes.DefinedInterval: {
|
|
1666
1695
|
const interval = range / intervalSize;
|
|
1667
|
-
console.log("interval", interval, intervalSize);
|
|
1668
1696
|
for (let i = 0; i <= interval; i++) stops.push({
|
|
1669
1697
|
value: min + intervalSize * i,
|
|
1670
1698
|
color: fromString("rgb(0,0,0)")
|
|
@@ -1833,6 +1861,10 @@ var Graduated = (props) => {
|
|
|
1833
1861
|
children: /* @__PURE__ */ jsxs("b", { children: [classesNumberLabel, ":"] })
|
|
1834
1862
|
}), /* @__PURE__ */ jsx(InputNumber, {
|
|
1835
1863
|
value: classNo,
|
|
1864
|
+
min: 0,
|
|
1865
|
+
max: 50,
|
|
1866
|
+
inputMode: "numeric",
|
|
1867
|
+
maxFractionDigits: 0,
|
|
1836
1868
|
locale,
|
|
1837
1869
|
onChange: async (e) => {
|
|
1838
1870
|
setClassNo(e.value);
|
|
@@ -1915,15 +1947,17 @@ var Graduated = (props) => {
|
|
|
1915
1947
|
placeholder: valueLabel,
|
|
1916
1948
|
allowEmpty: false,
|
|
1917
1949
|
locale,
|
|
1950
|
+
inputMode: "numeric",
|
|
1918
1951
|
min: stops[0].value,
|
|
1919
|
-
|
|
1952
|
+
maxFractionDigits: 3,
|
|
1953
|
+
max: stops[stops.length - 1].value,
|
|
1920
1954
|
disabled: index === 0 || selectedMode != GraduatedModes.Manual || index === stops.length - 1,
|
|
1921
1955
|
onChange: (e) => {
|
|
1922
1956
|
const aux = [...stops];
|
|
1923
1957
|
aux[index].value = e.value;
|
|
1924
1958
|
setStops(aux);
|
|
1925
1959
|
},
|
|
1926
|
-
value:
|
|
1960
|
+
value: stops[index].value
|
|
1927
1961
|
}), /* @__PURE__ */ jsx(MyColorPicker, {
|
|
1928
1962
|
color: value.color,
|
|
1929
1963
|
onChange: (e) => {
|
|
@@ -2279,6 +2313,7 @@ var ConditionOnFilter = (props) => {
|
|
|
2279
2313
|
selectedAttribute?.type != AttributeTypeEnum.BOOLEAN && selectedFunction?.name != t("filters.is_null") && /* @__PURE__ */ jsx(Dropdown, {
|
|
2280
2314
|
value: selectedValue,
|
|
2281
2315
|
editable: true,
|
|
2316
|
+
maxLength: 150,
|
|
2282
2317
|
onChange: (e) => {
|
|
2283
2318
|
setSelectedValue(e.value);
|
|
2284
2319
|
update(void 0, e.value, void 0);
|
|
@@ -2711,6 +2746,7 @@ var FilterWidget = (props) => {
|
|
|
2711
2746
|
children: [/* @__PURE__ */ jsx(InputText, {
|
|
2712
2747
|
id: "title",
|
|
2713
2748
|
value: queryWidget.title,
|
|
2749
|
+
maxLength: 100,
|
|
2714
2750
|
onChange: (e) => setTitle(e.target.value)
|
|
2715
2751
|
}), /* @__PURE__ */ jsx("label", {
|
|
2716
2752
|
htmlFor: "title",
|
|
@@ -2828,40 +2864,41 @@ function BasedOnRules(props) {
|
|
|
2828
2864
|
{
|
|
2829
2865
|
field: "filterJson",
|
|
2830
2866
|
header: expressionLabel,
|
|
2831
|
-
body: (data) =>
|
|
2832
|
-
if (!data.filterJson) return "";
|
|
2833
|
-
try {
|
|
2834
|
-
const parsed = JSON.parse(data.filterJson);
|
|
2835
|
-
const formatCondition = (cond) => {
|
|
2836
|
-
const operator = Object.keys(cond)[0];
|
|
2837
|
-
const value = cond[operator];
|
|
2838
|
-
if (operator === "!" && value.hasOwnProperty("in")) {
|
|
2839
|
-
const innerCondition = value["in"];
|
|
2840
|
-
return `${innerCondition[1].var} not in ${JSON.stringify(innerCondition[0])}`;
|
|
2841
|
-
}
|
|
2842
|
-
if (operator === "==" && Array.isArray(value) && value[0] && value[0].hasOwnProperty("substr")) {
|
|
2843
|
-
const substr = value[0].substr;
|
|
2844
|
-
const valueString = value[1];
|
|
2845
|
-
return `${substr[0].var} ${substr[1] < 0 ? "endsWith" : "startsWith"} "${valueString}"`;
|
|
2846
|
-
}
|
|
2847
|
-
if (operator === "==" && Array.isArray(value) && value[0] === null) return `${value[1].var} is null`;
|
|
2848
|
-
const max = Array.isArray(value) ? value[0] : null;
|
|
2849
|
-
if (max && max.hasOwnProperty("var")) return `${max.var} ${operator} ${JSON.stringify(value[1])}`;
|
|
2850
|
-
if (Array.isArray(value) && value[1] && value[1].hasOwnProperty("var")) return `${value[1].var} ${operator} ${JSON.stringify(max)}`;
|
|
2851
|
-
return JSON.stringify(cond);
|
|
2852
|
-
};
|
|
2853
|
-
const isAll = parsed.hasOwnProperty("and");
|
|
2854
|
-
const isAny = parsed.hasOwnProperty("or");
|
|
2855
|
-
if (isAll || isAny) {
|
|
2856
|
-
const operator = isAll ? " AND " : " OR ";
|
|
2857
|
-
return parsed[isAll ? "and" : "or"].map(formatCondition).join(operator);
|
|
2858
|
-
} else return formatCondition(parsed);
|
|
2859
|
-
} catch (e) {
|
|
2860
|
-
return data.filterJson;
|
|
2861
|
-
}
|
|
2862
|
-
}
|
|
2867
|
+
body: (data) => getFriendlyExpression(data)
|
|
2863
2868
|
}
|
|
2864
2869
|
];
|
|
2870
|
+
function getFriendlyExpression(data) {
|
|
2871
|
+
if (!data.filterJson) return "";
|
|
2872
|
+
try {
|
|
2873
|
+
const parsed = JSON.parse(data.filterJson);
|
|
2874
|
+
const formatCondition = (cond) => {
|
|
2875
|
+
const operator = Object.keys(cond)[0];
|
|
2876
|
+
const value = cond[operator];
|
|
2877
|
+
if (operator === "!" && value.hasOwnProperty("in")) {
|
|
2878
|
+
const innerCondition = value["in"];
|
|
2879
|
+
return `${innerCondition[1].var} not in ${JSON.stringify(innerCondition[0])}`;
|
|
2880
|
+
}
|
|
2881
|
+
if (operator === "==" && Array.isArray(value) && value[0] && value[0].hasOwnProperty("substr")) {
|
|
2882
|
+
const substr = value[0].substr;
|
|
2883
|
+
const valueString = value[1];
|
|
2884
|
+
return `${substr[0].var} ${substr[1] < 0 ? "endsWith" : "startsWith"} "${valueString}"`;
|
|
2885
|
+
}
|
|
2886
|
+
if (operator === "==" && Array.isArray(value) && value[0] === null) return `${value[1].var} is null`;
|
|
2887
|
+
const max = Array.isArray(value) ? value[0] : null;
|
|
2888
|
+
if (max && max.hasOwnProperty("var")) return `${max.var} ${operator} ${JSON.stringify(value[1])}`;
|
|
2889
|
+
if (Array.isArray(value) && value[1] && value[1].hasOwnProperty("var")) return `${value[1].var} ${operator} ${JSON.stringify(max)}`;
|
|
2890
|
+
return JSON.stringify(cond);
|
|
2891
|
+
};
|
|
2892
|
+
const isAll = parsed.hasOwnProperty("and");
|
|
2893
|
+
const isAny = parsed.hasOwnProperty("or");
|
|
2894
|
+
if (isAll || isAny) {
|
|
2895
|
+
const operator = isAll ? " AND " : " OR ";
|
|
2896
|
+
return parsed[isAll ? "and" : "or"].map(formatCondition).join(operator);
|
|
2897
|
+
} else return formatCondition(parsed);
|
|
2898
|
+
} catch (e) {
|
|
2899
|
+
return data.filterJson;
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2865
2902
|
function addFilter(filter) {
|
|
2866
2903
|
setRules([...rules, filter]);
|
|
2867
2904
|
}
|
|
@@ -2974,11 +3011,18 @@ function BasedOnRules(props) {
|
|
|
2974
3011
|
ids: res
|
|
2975
3012
|
});
|
|
2976
3013
|
});
|
|
3014
|
+
const completedFilters = appliedFilters.map((r) => ({
|
|
3015
|
+
ids: [...r.ids],
|
|
3016
|
+
filter: {
|
|
3017
|
+
...r.filter,
|
|
3018
|
+
friendlyExpression: getFriendlyExpression(r.filter)
|
|
3019
|
+
}
|
|
3020
|
+
}));
|
|
2977
3021
|
applyRenderer({
|
|
2978
3022
|
type: RenderType.ByRules,
|
|
2979
3023
|
field: selectedAttribute.name,
|
|
2980
3024
|
filters: rules,
|
|
2981
|
-
rendererOL: getByRulesStyle(
|
|
3025
|
+
rendererOL: getByRulesStyle(completedFilters, selectedAttribute.name, rules.find((r) => r.isElse))
|
|
2982
3026
|
});
|
|
2983
3027
|
setVisible(false);
|
|
2984
3028
|
}
|