|
| 1 | +import type { PluginOptions } from '@/core' |
| 2 | + |
| 3 | +/** |
| 4 | + * Plugin identifier. |
| 5 | + */ |
| 6 | +export const PluginId = 'filter' |
| 7 | + |
| 8 | +/** |
| 9 | + * Category-based filter configuration for a layer. |
| 10 | + */ |
| 11 | +export interface Category { |
| 12 | + /** |
| 13 | + * Known values for the target property to filter by. |
| 14 | + * Values not listed here cannot be filtered. |
| 15 | + * |
| 16 | + * @remarks |
| 17 | + * The values listed here can be localized. |
| 18 | + * ``` |
| 19 | + * filter: { |
| 20 | + * category: { |
| 21 | + * haus: { |
| 22 | + * shed: 'Schuppen', |
| 23 | + * mansion: 'Villa', |
| 24 | + * fortress: 'Festung', |
| 25 | + * }, |
| 26 | + * }, |
| 27 | + * }, |
| 28 | + * ``` |
| 29 | + * |
| 30 | + * @example ['shed', 'mansion', 'fortress'] |
| 31 | + */ |
| 32 | + knownValues: string[] |
| 33 | + |
| 34 | + /** |
| 35 | + * Key of the feature property to filter by. |
| 36 | + */ |
| 37 | + targetProperty: string |
| 38 | + |
| 39 | + /** |
| 40 | + * If `true`, a checkbox is provided to enable or disable all `knownValues` at once. |
| 41 | + * |
| 42 | + * @example true |
| 43 | + * @defaultValue false |
| 44 | + */ |
| 45 | + selectAll?: boolean |
| 46 | +} |
| 47 | + |
| 48 | +/** |
| 49 | + * Time-based filter configuration for a layer. |
| 50 | + */ |
| 51 | +export interface Time { |
| 52 | + /** |
| 53 | + * Key of the feature property to filter by. |
| 54 | + */ |
| 55 | + targetProperty: string |
| 56 | + |
| 57 | + /** |
| 58 | + * Defines if the time filter is freely selectable by the user. |
| 59 | + * If set to `'until'`, every time range until the current day (inclusive) can be selected. |
| 60 | + * If set to `'from'`, every time range from the current day (inclusive) can be selected. |
| 61 | + * If not set, this feature is disabled. |
| 62 | + * |
| 63 | + * @example 'until' |
| 64 | + */ |
| 65 | + freeSelection?: 'until' | 'from' |
| 66 | + |
| 67 | + /** |
| 68 | + * Configuration for preset time ranges in the past. |
| 69 | + * A configuration of `[5, 10]` adds the options `Last 5 days` and `Last 10 days`. |
| 70 | + * |
| 71 | + * @example [7, 30, 90] |
| 72 | + */ |
| 73 | + last?: number[] |
| 74 | + |
| 75 | + /** |
| 76 | + * Configuration for preset time ranges in the future. |
| 77 | + * A configuration of `[5, 10]` adds the options `Next 5 days` and `Next 10 days`. |
| 78 | + * |
| 79 | + * @example [7, 30, 90] |
| 80 | + */ |
| 81 | + next?: number[] |
| 82 | + |
| 83 | + /** |
| 84 | + * A pattern that specifies the date format used in the feature properties. |
| 85 | + * The pattern definition allows the following tokens: |
| 86 | + * - `YYYY`: 4-digit year |
| 87 | + * - `MM`: 2-digit month (01-12) |
| 88 | + * - `DD`: 2-digit day of month (01-31) |
| 89 | + * - `-`: ignored character |
| 90 | + * |
| 91 | + * @privateRemarks |
| 92 | + * All characters that are not tokens are handled as ignored characters. |
| 93 | + * This behavior may change in future versions without a breaking change! |
| 94 | + * |
| 95 | + * @example '--YYYYDD-MM' |
| 96 | + * @defaultValue 'YYYY-MM-DD' |
| 97 | + */ |
| 98 | + pattern?: string |
| 99 | +} |
| 100 | + |
| 101 | +/** |
| 102 | + * Filter configuration for a layer. |
| 103 | + */ |
| 104 | +export interface FilterConfiguration { |
| 105 | + /** |
| 106 | + * A definition of different categories to filter features based on their properties. |
| 107 | + */ |
| 108 | + categories?: Category[] |
| 109 | + |
| 110 | + /** |
| 111 | + * Filter features based on a time property. |
| 112 | + */ |
| 113 | + time?: Time |
| 114 | +} |
| 115 | + |
| 116 | +/** |
| 117 | + * Plugin options for filter plugin. |
| 118 | + */ |
| 119 | +export interface FilterPluginOptions extends PluginOptions { |
| 120 | + /** |
| 121 | + * Maps a layer ID to its filter configuration. |
| 122 | + */ |
| 123 | + layers: Record<string, FilterConfiguration> |
| 124 | +} |
0 commit comments