@eox/itemfilter 1.3.0 → 1.4.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.
Files changed (76) hide show
  1. package/README.md +4 -0
  2. package/dist/eox-itemfilter.js +1156 -1276
  3. package/dist/eox-itemfilter.umd.cjs +110 -112
  4. package/package.json +8 -13
  5. package/src/components/chips.js +131 -0
  6. package/src/components/expand-container.js +94 -0
  7. package/src/components/filters/range.js +114 -0
  8. package/src/components/filters/selector.js +245 -0
  9. package/src/components/filters/spatial.js +192 -0
  10. package/src/components/filters/text.js +114 -0
  11. package/src/components/itemfilter-container.js +289 -0
  12. package/src/components/results.js +156 -0
  13. package/src/enums/config.js +104 -0
  14. package/src/enums/index.js +1 -0
  15. package/src/helpers/chip-items.js +19 -0
  16. package/src/helpers/filter-client.js +179 -0
  17. package/src/helpers/filter-external.js +18 -0
  18. package/src/helpers/get-value.js +12 -0
  19. package/src/helpers/highlighting.js +79 -0
  20. package/src/helpers/index.js +11 -0
  21. package/src/helpers/is-filters-dirty.js +13 -0
  22. package/src/helpers/map-layers.js +42 -0
  23. package/src/helpers/reset-filter.js +60 -0
  24. package/src/helpers/spatial.js +35 -0
  25. package/src/helpers/tab-index.js +13 -0
  26. package/src/helpers/toggle-accordion.js +39 -0
  27. package/src/main.js +466 -0
  28. package/src/methods/chips/handler.js +129 -0
  29. package/src/methods/chips/index.js +5 -0
  30. package/src/methods/container/handler.js +70 -0
  31. package/src/methods/container/index.js +10 -0
  32. package/src/methods/container/init-popver.js +34 -0
  33. package/src/methods/container/reset-filter.js +14 -0
  34. package/src/methods/container/reset-search.js +16 -0
  35. package/src/methods/container/search-filter.js +27 -0
  36. package/src/methods/filters/index.js +20 -0
  37. package/src/methods/filters/range.js +78 -0
  38. package/src/methods/filters/selector.js +209 -0
  39. package/src/methods/filters/spatial.js +114 -0
  40. package/src/methods/filters/text.js +32 -0
  41. package/src/methods/itemfilter/create-filter.js +83 -0
  42. package/src/methods/itemfilter/create-reset.js +39 -0
  43. package/src/methods/itemfilter/filter-apply.js +140 -0
  44. package/src/methods/itemfilter/index.js +6 -0
  45. package/src/methods/itemfilter/reset-filter.js +13 -0
  46. package/src/methods/itemfilter/search.js +23 -0
  47. package/src/methods/itemfilter/sort-results.js +14 -0
  48. package/src/methods/results/aggregate-results.js +43 -0
  49. package/src/methods/results/create.js +111 -0
  50. package/src/methods/results/index.js +2 -0
  51. package/src/style.eox.js +457 -0
  52. package/src/style.js +26 -0
  53. package/test/_mockMap.js +0 -20
  54. package/test/cases/filters/filter-keys.js +0 -22
  55. package/test/cases/filters/index.js +0 -3
  56. package/test/cases/general/accordion.js +0 -60
  57. package/test/cases/general/disable-highlight.js +0 -21
  58. package/test/cases/general/external-filter.js +0 -35
  59. package/test/cases/general/highlight-result.js +0 -16
  60. package/test/cases/general/index.js +0 -13
  61. package/test/cases/general/multiple-filters.js +0 -21
  62. package/test/cases/general/nested-property.js +0 -25
  63. package/test/cases/general/search-bar.js +0 -12
  64. package/test/cases/general/search-result.js +0 -14
  65. package/test/cases/general/spatial-filter.js +0 -22
  66. package/test/cases/general/subtitle.js +0 -15
  67. package/test/cases/general/validation.js +0 -22
  68. package/test/cases/state/custom-order.js +0 -24
  69. package/test/cases/state/index.js +0 -6
  70. package/test/cases/state/render-checkbox.js +0 -17
  71. package/test/cases/state/result-pre-checked.js +0 -20
  72. package/test/cases/state/results-with-pre-set-filters.js +0 -30
  73. package/test/filters.cy.js +0 -54
  74. package/test/general.cy.js +0 -110
  75. package/test/state.cy.js +0 -74
  76. package/test/testItems.json +0 -440
@@ -0,0 +1,156 @@
1
+ import { LitElement, html, nothing } from "lit";
2
+ import { when } from "lit/directives/when.js";
3
+ import { map } from "lit/directives/map.js";
4
+ import {
5
+ aggregateResultsMethod,
6
+ createItemDetailsMethod,
7
+ createItemListMethod,
8
+ } from "../methods/results/index.js";
9
+ import { toggleAccordion } from "../helpers";
10
+
11
+ /**
12
+ * EOxItemFilterResults is a custom web component that displays the results of item filtering.
13
+ * It uses the LitElement base class and integrates with external methods for aggregating results
14
+ * and creating item details and lists.
15
+ *
16
+ * @module EOxItemFilterResults
17
+ * @extends LitElement
18
+ * @property {Object} config - The configuration object for the results display.
19
+ * @property {Object} results - The state object containing the filter results.
20
+ * @property {Object} filters - The state object containing the applied filters.
21
+ * @property {Array} resultAggregation - The array of properties used for result aggregation.
22
+ * @property {Object} selectedResult - Property with pre-selected result
23
+ */
24
+ export class EOxItemFilterResults extends LitElement {
25
+ // Define properties with defaults and types
26
+ static get properties() {
27
+ return {
28
+ config: { attribute: false, type: Object },
29
+ results: { state: true, type: Object },
30
+ filters: { state: true, type: Object },
31
+ resultAggregation: { attribute: false, type: Array },
32
+ selectedResult: { state: true, type: Object },
33
+ };
34
+ }
35
+
36
+ constructor() {
37
+ super();
38
+
39
+ /**
40
+ * @type Object
41
+ */
42
+ this.config = null;
43
+
44
+ /**
45
+ * @type Object
46
+ */
47
+ this.filters = {};
48
+
49
+ /**
50
+ * @type Array
51
+ */
52
+ this.resultAggregation = [];
53
+
54
+ /**
55
+ * @type Object
56
+ */
57
+ this.selectedResult = null;
58
+ }
59
+
60
+ /**
61
+ * Creates a list of items based on the aggregation property.
62
+ *
63
+ * @param {string} aggregationProperty - The property used for aggregation.
64
+ * @returns {import("lit")} - The template result for the item list.
65
+ * @private
66
+ */
67
+ #createItemList(aggregationProperty) {
68
+ return createItemListMethod(aggregationProperty, this);
69
+ }
70
+
71
+ /**
72
+ * Creates item details based on the aggregation property.
73
+ *
74
+ * @param {string} aggregationProperty - The property used for aggregation.
75
+ * @returns {import("lit")} - The template result for the item details.
76
+ * @private
77
+ */
78
+ #createItemDetails(aggregationProperty) {
79
+ return createItemDetailsMethod(aggregationProperty, this);
80
+ }
81
+
82
+ /**
83
+ * Aggregates results based on the specified property.
84
+ *
85
+ * @param {Array} items - The array of items to be aggregated.
86
+ * @param {string} property - The property used for aggregation.
87
+ * @returns {Array} - The aggregated results.
88
+ */
89
+ aggregateResults(items, property) {
90
+ return aggregateResultsMethod(items, property, this);
91
+ }
92
+
93
+ /**
94
+ * Overrides the default createRenderRoot method to render in the light DOM.
95
+ *
96
+ * @returns {this} - The current instance to render in the light DOM.
97
+ */
98
+ createRenderRoot() {
99
+ return this;
100
+ }
101
+
102
+ /**
103
+ * Handles the toggle event for accordion.
104
+ *
105
+ * @param {Event} event - The toggle event.
106
+ */
107
+ handleAccordion(event) {
108
+ toggleAccordion(event, this.config, this);
109
+ }
110
+
111
+ /**
112
+ * Renders the HTML template for the component.
113
+ */
114
+ render() {
115
+ return html`
116
+ <section id="section-results">
117
+ <div>
118
+ <h6 class="main-heading">Results</h6>
119
+ </div>
120
+ <div id="container-results" class="scroll">
121
+ ${when(
122
+ this.results.length < 1,
123
+ () => html`<small class="no-results">No matching items</small>`,
124
+ () => nothing,
125
+ )}
126
+ <ul id="results" part="results">
127
+ ${when(
128
+ this.config.aggregateResults,
129
+ () =>
130
+ map(
131
+ this.resultAggregation.filter(
132
+ (aggregationProperty) =>
133
+ this.aggregateResults(this.results, aggregationProperty)
134
+ .length,
135
+ ),
136
+ (aggregationProperty) =>
137
+ html`${when(
138
+ this.aggregateResults(this.results, aggregationProperty)
139
+ .length === 1 && this.config.autoSpreadSingle,
140
+ () =>
141
+ html`<div style="margin-left: -8px">
142
+ ${this.#createItemList(aggregationProperty)}
143
+ </div>`,
144
+ () => this.#createItemDetails(aggregationProperty),
145
+ )}`,
146
+ ),
147
+ () => this.#createItemList(),
148
+ )}
149
+ </ul>
150
+ </div>
151
+ </section>
152
+ `;
153
+ }
154
+ }
155
+
156
+ customElements.define("eox-itemfilter-results", EOxItemFilterResults);
@@ -0,0 +1,104 @@
1
+ export const ELEMENT_CONFIG = Object.freeze({
2
+ /**
3
+ * Aggregate results by a property key
4
+ */
5
+ aggregateResults: undefined,
6
+
7
+ /**
8
+ * Automatically spread single item summaries
9
+ * removing the summary header
10
+ */
11
+ autoSpreadSingle: false,
12
+
13
+ /**
14
+ * Highlighting of search result character matches
15
+ */
16
+ enableHighlighting: false,
17
+
18
+ /**
19
+ * Use an external search endpoint instead of fuse search.
20
+ * Passed properties: input string, filters object
21
+ *
22
+ * (input, filters) => {}
23
+ */
24
+ externalFilter: () => {},
25
+
26
+ /**
27
+ * The filter properties.
28
+ */
29
+ filterProperties: [],
30
+
31
+ /**
32
+ * Native fuse.js config override
33
+ */
34
+ fuseConfig: {},
35
+
36
+ /**
37
+ * Inline mode, for rendering the itemfilter in a very condensed space.
38
+ * Expects showResults to be false
39
+ */
40
+ inlineMode: false,
41
+
42
+ /**
43
+ * Show all result items if nothing is input by the user
44
+ * @default true
45
+ */
46
+ matchAllWhenEmpty: true,
47
+
48
+ /**
49
+ * Display results list
50
+ */
51
+ showResults: true,
52
+
53
+ /**
54
+ * Unique id property of items
55
+ */
56
+ idProperty: "id",
57
+
58
+ /**
59
+ * The property of the result items used for display
60
+ */
61
+ titleProperty: "title",
62
+
63
+ /**
64
+ * The property of the result items used for a subtitle
65
+ */
66
+ subTitleProperty: undefined,
67
+
68
+ /**
69
+ * Allow opening multiple filter accordions in parallel
70
+ * @default true
71
+ */
72
+ expandMultipleFilters: true,
73
+
74
+ /**
75
+ * Initialize result accordions expanded
76
+ * @default true
77
+ */
78
+ expandResults: true,
79
+
80
+ /**
81
+ * Allow opening multiple result accordions in parallel
82
+ * @default true
83
+ */
84
+ expandMultipleResults: true,
85
+ });
86
+
87
+ export const ELEMENT_PROPERTIES = [
88
+ "aggregateResults",
89
+ "autoSpreadSingle",
90
+ "enableHighlighting",
91
+ "externalFilter",
92
+ "filterProperties",
93
+ "fuseConfig",
94
+ "inlineMode",
95
+ "matchAllWhenEmpty",
96
+ "showResults",
97
+ "titleProperty",
98
+ "subTitleProperty",
99
+ "idProperty",
100
+ "expandMultipleFilters",
101
+ "expandResults",
102
+ "expandMultipleResults",
103
+ "items",
104
+ ];
@@ -0,0 +1 @@
1
+ export { ELEMENT_CONFIG, ELEMENT_PROPERTIES } from "./config";
@@ -0,0 +1,19 @@
1
+ import { html } from "lit";
2
+
3
+ /**
4
+ * Generates an array of chip items from the given filters.
5
+ *
6
+ * @param {Object} filters - An object containing filter data.
7
+ * @returns {Array<Object>} An array of chip item objects.
8
+ */
9
+ function getChipItems(filters) {
10
+ return Object.keys(filters)
11
+ .map((filter) => ({
12
+ title: html`${filters[filter].title}:
13
+ <strong>${filters[filter].stringifiedState}</strong>`,
14
+ key: filter,
15
+ }))
16
+ .filter((item) => filters[item.key].dirty);
17
+ }
18
+
19
+ export default getChipItems;
@@ -0,0 +1,179 @@
1
+ import Fuse from "fuse.js";
2
+ import dayjs from "dayjs";
3
+ import { intersects, within, highlight, getValue } from "./";
4
+
5
+ let _fuse;
6
+
7
+ /**
8
+ * Indexes the given items using Fuse.js with the provided configuration.
9
+ *
10
+ * @param {Array<Object>} items - The items to be indexed.
11
+ * @param {Object} fuseConfig - Configuration object for Fuse.js.
12
+ */
13
+ export const indexItems = (items, fuseConfig) => {
14
+ _fuse = new Fuse(items, {
15
+ threshold: 0.4,
16
+ distance: 50,
17
+ includeMatches: true,
18
+ useExtendedSearch: true,
19
+ ...fuseConfig,
20
+ });
21
+ };
22
+
23
+ /**
24
+ * Filters the given items based on the provided filters and configuration.
25
+ *
26
+ * @param {Array<Object>} items - The items to be filtered.
27
+ * @param {Object} filters - The filters to be applied.
28
+ * @param {Object} config - Configuration for filtering behavior.
29
+ * @returns {Promise<Array<Object>>} The filtered items.
30
+ */
31
+ export const filter = async (items, filters, config) => {
32
+ // Parse text, select, and multiselect filters
33
+ const parsedFilters = Object.entries(filters)
34
+ .filter(
35
+ ([, filter]) =>
36
+ filter.type === "text" ||
37
+ filter.type === "select" ||
38
+ filter.type === "multiselect",
39
+ )
40
+ .reduce((store, [key, filter]) => {
41
+ const operator = "$or"; // Logical OR operator for filtering
42
+ const holding = [];
43
+
44
+ // Function to create a filter property
45
+ const createProperty = (pKey, pVal) => {
46
+ const property = {};
47
+ if (filter.type === "text") {
48
+ property[pKey] = `${pVal}`;
49
+ } else {
50
+ property[key] = `="${pKey}"`;
51
+ }
52
+ holding.push(property); // Add the property to the holding array
53
+ };
54
+
55
+ // Add filter properties to holding array
56
+ Object.entries(filter.state)
57
+ .filter(([, v]) => v)
58
+ .forEach(([k, v]) => createProperty(k, v));
59
+
60
+ // If there are any properties, add them to the store
61
+ if (holding.length > 0) {
62
+ store.push({
63
+ [operator]: holding,
64
+ });
65
+ }
66
+ return store;
67
+ }, []);
68
+ let results;
69
+
70
+ // Check if no parsed filters and matchAllWhenEmpty is not false
71
+ if (!(parsedFilters.length > 0) && config.matchAllWhenEmpty !== false) {
72
+ results = items;
73
+ } else {
74
+ const parameters = {
75
+ $and: [...parsedFilters], // Combine filters using logical AND
76
+ };
77
+ const response = _fuse.search(parameters);
78
+ results = config.enableHighlighting
79
+ ? highlight(response, "highlight", config.titleProperty)
80
+ : response.map((i) => i.item);
81
+ }
82
+
83
+ // Handle range filters
84
+ const rangeFilters = Object.entries(filters)
85
+ .filter(([, value]) => value.type === "range")
86
+ .reduce((acc, [key, value]) => {
87
+ acc[key] = {
88
+ min: value.state.min,
89
+ max: value.state.max,
90
+ format: value.format,
91
+ };
92
+ return acc; // Return the accumulated range filters
93
+ }, {});
94
+
95
+ if (Object.keys(rangeFilters).length > 0) {
96
+ const filteredResults = [];
97
+ for (let i = 0; i < results.length; i++) {
98
+ const pass = {}; // Object to hold filter pass status for each key
99
+ for (const [key, value] of Object.entries(rangeFilters)) {
100
+ // Function to parse value based on format
101
+ const parseValue = (input) => {
102
+ return value.format === "date" ? dayjs(input).unix() : input;
103
+ };
104
+ const rangeValue = getValue(key, results[i]);
105
+ if (rangeValue) {
106
+ if (Array.isArray(rangeValue)) {
107
+ const mode = "overlap"; // Mode for handling array values
108
+ if (mode === "overlap") {
109
+ pass[key] =
110
+ rangeFilters[key].min <= parseValue(rangeValue[1]) &&
111
+ parseValue(rangeValue[0]) <= rangeFilters[key].max;
112
+ } else if (mode === "contain") {
113
+ pass[key] =
114
+ parseValue(rangeValue[0]) >= rangeFilters[key].min &&
115
+ parseValue(rangeValue[1]) <= rangeFilters[key].max;
116
+ }
117
+ } else if (
118
+ parseValue(rangeValue) >= rangeFilters[key].min &&
119
+ parseValue(rangeValue) <= rangeFilters[key].max
120
+ ) {
121
+ pass[key] = true;
122
+ } else {
123
+ pass[key] = false;
124
+ }
125
+ } else {
126
+ pass[key] = true;
127
+ }
128
+ }
129
+ if (Object.values(pass).every((v) => !!v)) {
130
+ filteredResults.push(results[i]);
131
+ }
132
+ }
133
+ results = [...filteredResults]; // Update results with filtered range results
134
+ }
135
+
136
+ // Handle spatial filters
137
+ const spatialFilters = Object.entries(filters)
138
+ .filter(([, value]) => value.type === "spatial")
139
+ .reduce((acc, [key, value]) => {
140
+ acc[key] = {
141
+ geometry: value.state.geometry,
142
+ mode: value.state.mode,
143
+ };
144
+ return acc; // Return accumulated spatial filters
145
+ }, {});
146
+
147
+ if (
148
+ Object.values(spatialFilters)
149
+ .map((f) => f.geometry)
150
+ .filter((f) => !!f).length > 0
151
+ ) {
152
+ const filteredResults = [];
153
+ for (let i = 0; i < results.length; i++) {
154
+ const pass = {};
155
+ for (const key of Object.keys(spatialFilters)) {
156
+ const spatialValue = getValue(key, results[i]);
157
+ const mode = spatialFilters[key].mode || "within";
158
+ if (spatialValue) {
159
+ const test =
160
+ mode === "within"
161
+ ? within(spatialValue, spatialFilters[key].geometry)
162
+ : intersects(spatialValue, spatialFilters[key].geometry);
163
+ if (test) {
164
+ pass[key] = true;
165
+ } else {
166
+ pass[key] = false;
167
+ }
168
+ } else {
169
+ pass[key] = false;
170
+ }
171
+ }
172
+ if (Object.values(pass).every((v) => !!v)) {
173
+ filteredResults.push(results[i]); // Add to results if all conditions pass
174
+ }
175
+ }
176
+ results = [...filteredResults]; // Update results with filtered spatial results
177
+ }
178
+ return results;
179
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Fetches and filters items based on the provided filters and configuration using an external API.
3
+ *
4
+ * @param {Array<Object>} items - The items to be filtered.
5
+ * @param {Object} filters - The filters to be applied.
6
+ * @param {Object} config - Configuration for filtering behavior.
7
+ * @returns {Promise<Array<Object>>} The filtered items from the external API.
8
+ */
9
+ async function filterExternal(items, filters, config) {
10
+ // Generate the URL for the external API based on the provided items and filters
11
+ const response = await fetch(`${config.externalFilter(items, filters)}`);
12
+ const jsonData = await response.json();
13
+
14
+ // Return the array from the parsed JSON data
15
+ return jsonData;
16
+ }
17
+
18
+ export default filterExternal;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Get value based on nested key or individual key
3
+ *
4
+ * @param {string} key - Key to identify the value
5
+ * @param {Object} items - Items contain list of key & it's value
6
+ * @returns {any}
7
+ */
8
+ export default function getValue(key, items) {
9
+ return key?.includes(".")
10
+ ? key.split(".").reduce((acc, key) => acc && acc[key], items)
11
+ : items[key];
12
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Highlights matched text in the Fuse.js search results.
3
+ *
4
+ * @param {Array<Object>} fuseSearchResult - The search results from Fuse.js.
5
+ * @param {string} [highlightClassName="highlight"] - The CSS class name to be used for highlighting.
6
+ * @param {string} [matchKey="title"] - The key of the object where matches should be highlighted.
7
+ * @returns {Array<Object>} The search results with highlighted matches.
8
+ */
9
+ function highlight(
10
+ fuseSearchResult,
11
+ highlightClassName = "highlight",
12
+ matchKey = "title",
13
+ ) {
14
+ /**
15
+ * Sets a value at a specified path within an object.
16
+ *
17
+ * @param {Object} obj - The object to modify.
18
+ * @param {string} path - The dot-separated path specifying the location within the object.
19
+ * @param {*} value - The value to set at the specified path.
20
+ */
21
+ const set = (obj, path, value) => {
22
+ const pathValue = path.split(".");
23
+ let i;
24
+
25
+ for (i = 0; i < pathValue.length - 1; i++) {
26
+ obj = obj[pathValue[i]];
27
+ }
28
+
29
+ obj[pathValue[i]] = value;
30
+ };
31
+
32
+ /**
33
+ * Generates HTML string with highlighted regions.
34
+ *
35
+ * @param {string} inputText - The text to be highlighted.
36
+ * @param {Array<Array<number>>} [regions=[]] - The regions to highlight, specified as an array of [start, end] indices.
37
+ * @returns {string} The HTML string with highlighted regions.
38
+ */
39
+ const generateHighlightedText = (inputText, regions = []) => {
40
+ let content = "";
41
+ let nextUnhighlightedRegionStartingIndex = 0;
42
+
43
+ regions.forEach((region) => {
44
+ const lastRegionNextIndex = region[1] + 1;
45
+
46
+ content += [
47
+ inputText.substring(nextUnhighlightedRegionStartingIndex, region[0]),
48
+ `<mark class="${highlightClassName}">`,
49
+ inputText.substring(region[0], lastRegionNextIndex),
50
+ "</mark>",
51
+ ].join("");
52
+
53
+ nextUnhighlightedRegionStartingIndex = lastRegionNextIndex;
54
+ });
55
+
56
+ content += inputText.substring(nextUnhighlightedRegionStartingIndex);
57
+
58
+ return content;
59
+ };
60
+
61
+ return fuseSearchResult
62
+ .filter(({ matches }) => matches && matches.length) // Filter results with matches
63
+ .map(({ item, matches }) => {
64
+ const highlightedItem = { ...item }; // Create a copy of the item
65
+
66
+ matches.forEach((match) => {
67
+ if (match.key !== matchKey) return; // Skip if the match key does not match
68
+ set(
69
+ highlightedItem,
70
+ match.key,
71
+ generateHighlightedText(match.value, match.indices), // Highlight the matched text
72
+ );
73
+ });
74
+
75
+ return highlightedItem;
76
+ });
77
+ }
78
+
79
+ export default highlight;
@@ -0,0 +1,11 @@
1
+ export { intersects, within } from "./spatial";
2
+ export { default as highlight } from "./highlighting";
3
+ export { indexItems, filter } from "./filter-client";
4
+ export { default as getMapLayers } from "./map-layers";
5
+ export { default as resetFilter } from "./reset-filter";
6
+ export { default as getTabIndex } from "./tab-index";
7
+ export { default as getChipItems } from "./chip-items";
8
+ export { default as isFiltersDirty } from "./is-filters-dirty";
9
+ export { default as filterExternal } from "./filter-external";
10
+ export { default as toggleAccordion } from "./toggle-accordion";
11
+ export { default as getValue } from "./get-value";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Checks if any of the filters are dirty.
3
+ *
4
+ * @param {Object} filters - An object containing filter data.
5
+ * @returns {boolean} True if any filter is dirty, otherwise false.
6
+ */
7
+ export default function isFiltersDirty(filters) {
8
+ return (
9
+ Object.values(filters)
10
+ .map((f) => f.dirty)
11
+ .filter((f) => f).length > 0 // Filter to keep only truthy values and check if the length is greater than 0
12
+ );
13
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Generates an array of map layer configurations.
3
+ *
4
+ * @param {Object} [geometry] - Optional geometry data to include in the Vector source.
5
+ * @param {string} [url] - Optional URL for the GeoJSON data source.
6
+ * @returns {Array<Object>} An array of map layer configurations.
7
+ */
8
+ export default function getMapLayers(geometry, url) {
9
+ return [
10
+ {
11
+ type: "Vector",
12
+ properties: {
13
+ id: "draw",
14
+ },
15
+ source: {
16
+ type: "Vector",
17
+ ...(geometry && { format: "GeoJSON" }),
18
+ ...(geometry && { url }),
19
+ },
20
+ zIndex: 1,
21
+ interactions: [
22
+ {
23
+ type: "draw",
24
+ options: {
25
+ id: "drawInteraction",
26
+ type: "Box",
27
+ modify: true,
28
+ },
29
+ },
30
+ ],
31
+ },
32
+ {
33
+ type: "Tile",
34
+ source: {
35
+ type: "XYZ",
36
+ url: "https://tiles.maps.eox.at/wmts/1.0.0/osm_3857/default/g/{z}/{y}/{x}.jpg",
37
+ attribution:
38
+ "{ OSM: Data &copy; OpenStreetMap contributors and others, Rendering &copy; EOX }",
39
+ },
40
+ },
41
+ ];
42
+ }