@sakuzu/maplibre-gl-draw-ui 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/CHANGELOG.md +78 -0
- package/LICENSE +661 -0
- package/README.md +267 -0
- package/THIRD_PARTY_NOTICES.md +350 -0
- package/dist/controls.d.ts +36 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +15336 -0
- package/dist/index.js.map +1 -0
- package/dist/inspector/attributes.d.ts +46 -0
- package/dist/inspector/measure.d.ts +25 -0
- package/dist/inspector/operations.d.ts +44 -0
- package/dist/inspector/sections.d.ts +20 -0
- package/dist/inspector/style.d.ts +57 -0
- package/dist/inspector/types.d.ts +121 -0
- package/dist/inspector/view.d.ts +84 -0
- package/dist/layers/legend.d.ts +36 -0
- package/dist/layers/move.d.ts +30 -0
- package/dist/layers/tree.d.ts +87 -0
- package/dist/locales/en.d.ts +3 -0
- package/dist/locales/ja.d.ts +3 -0
- package/dist/maplibre-gl-draw-ui.js +13988 -0
- package/dist/maplibre-gl-draw-ui.js.map +1 -0
- package/dist/messages.d.ts +211 -0
- package/dist/padding.d.ts +33 -0
- package/dist/shortcuts.d.ts +7 -0
- package/dist/store.d.ts +21 -0
- package/dist/style.css +3 -0
- package/dist/theme.d.ts +23 -0
- package/dist/tools.d.ts +56 -0
- package/dist/types.d.ts +237 -0
- package/package.json +88 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Feature, type FeaturePatch } from '@sakuzu/maplibre-gl-draw';
|
|
2
|
+
/** The attribute that holds the name of a feature */
|
|
3
|
+
export declare const NAME_KEY = "name";
|
|
4
|
+
/** The attribute that holds the description of a feature */
|
|
5
|
+
export declare const DESCRIPTION_KEY = "description";
|
|
6
|
+
/** An attribute as the list shows it */
|
|
7
|
+
export interface AttributeRow {
|
|
8
|
+
key: string;
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
11
|
+
/** Whether a key of `properties` is kept out of the list of attributes */
|
|
12
|
+
export declare function isReservedKey(key: string): boolean;
|
|
13
|
+
/** A value of `properties` as a string */
|
|
14
|
+
export declare function showValue(value: unknown): string;
|
|
15
|
+
/** The name of a feature, or an empty string */
|
|
16
|
+
export declare function featureName(feature: Pick<Feature, 'properties'>): string;
|
|
17
|
+
/** The description of a feature, or an empty string */
|
|
18
|
+
export declare function featureDescription(feature: Pick<Feature, 'properties'>): string;
|
|
19
|
+
/** The attributes of a feature, in the order of `properties` */
|
|
20
|
+
export declare function attributeRows(feature: Pick<Feature, 'properties'>): AttributeRow[];
|
|
21
|
+
/** The patch that names a feature; an empty name removes the attribute */
|
|
22
|
+
export declare function namePatch(name: string): FeaturePatch;
|
|
23
|
+
/** The patch that describes a feature; an empty description removes the attribute */
|
|
24
|
+
export declare function descriptionPatch(text: string): FeaturePatch;
|
|
25
|
+
/**
|
|
26
|
+
* The patch of a change of the attribute at `index` of {@link attributeRows}: a new value, a
|
|
27
|
+
* new name (the old key removed and the new one set), or both. When only the name changes, the
|
|
28
|
+
* value keeps its type.
|
|
29
|
+
*
|
|
30
|
+
* @returns The patch, or null when nothing changes, there is no attribute at `index`, or the
|
|
31
|
+
* new name is empty, is the name of another attribute, or is kept (`name`, `description`, a
|
|
32
|
+
* key of the library)
|
|
33
|
+
*/
|
|
34
|
+
export declare function attributePatch(feature: Pick<Feature, 'properties'>, index: number, next: AttributeRow): FeaturePatch | null;
|
|
35
|
+
/**
|
|
36
|
+
* The patch that adds an attribute
|
|
37
|
+
*
|
|
38
|
+
* @returns The patch, or null when the name is empty, is taken, or is kept
|
|
39
|
+
*/
|
|
40
|
+
export declare function attributeAdd(feature: Pick<Feature, 'properties'>, item: AttributeRow): FeaturePatch | null;
|
|
41
|
+
/**
|
|
42
|
+
* The patch that removes the attribute at `index` of {@link attributeRows}
|
|
43
|
+
*
|
|
44
|
+
* @returns The patch, or null when there is no attribute at `index`
|
|
45
|
+
*/
|
|
46
|
+
export declare function attributeRemove(feature: Pick<Feature, 'properties'>, index: number): FeaturePatch | null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Feature } from '@sakuzu/maplibre-gl-draw';
|
|
2
|
+
import type { Units } from './types.js';
|
|
3
|
+
/** What a row of the measurements is */
|
|
4
|
+
export type MeasureKey = 'longitude' | 'latitude' | 'length' | 'area' | 'perimeter' | 'radius' | 'points';
|
|
5
|
+
/** A row of the measurements: what it is and the value, written out */
|
|
6
|
+
export interface MeasureRow {
|
|
7
|
+
key: MeasureKey;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
/** A length in meters, written in the units */
|
|
11
|
+
export declare function formatLength(meters: number, units: Units, locale?: string): string;
|
|
12
|
+
/** An area in square meters, written in the units */
|
|
13
|
+
export declare function formatArea(squareMeters: number, units: Units, locale?: string): string;
|
|
14
|
+
/** A longitude or a latitude in degrees, with six decimals */
|
|
15
|
+
export declare function formatDegrees(degrees: number, locale?: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* The measurements of a feature: the coordinates of a point, the length of a line, the area and
|
|
18
|
+
* the perimeter of an area (and the radius of a circle), the number of points of a MultiPoint.
|
|
19
|
+
* An image and a custom type have none.
|
|
20
|
+
*
|
|
21
|
+
* @param feature - The feature
|
|
22
|
+
* @param units - Metric or imperial
|
|
23
|
+
* @param locale - The language tag the numbers are written in
|
|
24
|
+
*/
|
|
25
|
+
export declare function measure(feature: Feature, units: Units, locale?: string): MeasureRow[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Feature } from '@sakuzu/maplibre-gl-draw';
|
|
2
|
+
import type { InspectorDraw, Units } from './types.js';
|
|
3
|
+
/** An operation on the features selected */
|
|
4
|
+
export type OperationId = 'union' | 'intersection' | 'difference' | 'split' | 'buffer';
|
|
5
|
+
/** The operations, in the order they are offered */
|
|
6
|
+
export declare const OPERATION_IDS: readonly OperationId[];
|
|
7
|
+
/** Whether a feature is an area that union, intersection, difference and split take */
|
|
8
|
+
export declare function isArea(feature: Pick<Feature, 'type' | 'properties'>): boolean;
|
|
9
|
+
/** Whether a feature is a line that a split cuts along */
|
|
10
|
+
export declare function isCuttingLine(feature: Pick<Feature, 'type'>): boolean;
|
|
11
|
+
/** Whether a feature is one that buffer takes */
|
|
12
|
+
export declare function isBufferable(feature: Pick<Feature, 'type' | 'properties'>): boolean;
|
|
13
|
+
/** The area and the line of a split, or null when the features are not one of each */
|
|
14
|
+
export declare function splitPair<T extends Pick<Feature, 'type' | 'properties'>>(features: readonly T[]): {
|
|
15
|
+
area: T;
|
|
16
|
+
line: T;
|
|
17
|
+
} | null;
|
|
18
|
+
/** The operations that apply to features, in order */
|
|
19
|
+
export declare function applicableOperations(features: readonly Pick<Feature, 'type' | 'properties'>[]): OperationId[];
|
|
20
|
+
/** The units of the distance of a buffer */
|
|
21
|
+
export type DistanceUnit = 'm' | 'km' | 'ft' | 'mi';
|
|
22
|
+
/** The units of the distance offered for a system of units, the first being the default */
|
|
23
|
+
export declare function distanceUnits(units: Units): DistanceUnit[];
|
|
24
|
+
/** A distance in meters */
|
|
25
|
+
export declare function toMeters(value: number, unit: DistanceUnit): number;
|
|
26
|
+
/**
|
|
27
|
+
* Runs union, intersection, difference or split on features, and selects what it made
|
|
28
|
+
*
|
|
29
|
+
* @param features - The features, in the order of the selection (difference subtracts the
|
|
30
|
+
* others from the first)
|
|
31
|
+
* @returns The IDs of the features made (empty when the line did not cut the area), or null when
|
|
32
|
+
* core refused the operation (read-only, a lock) or its result is empty
|
|
33
|
+
* @throws `DrawError` of core when the features do not suit the operation
|
|
34
|
+
*/
|
|
35
|
+
export declare function runOperation(draw: InspectorDraw, op: Exclude<OperationId, 'buffer'>, features: readonly Feature[]): string[] | null;
|
|
36
|
+
/**
|
|
37
|
+
* Makes the buffers of features and selects them
|
|
38
|
+
*
|
|
39
|
+
* @param distanceMeters - The distance of the outline from the features, in meters
|
|
40
|
+
* @param segments - The segments of a full circle; core's default when left out
|
|
41
|
+
* @returns The IDs of the features made, or null when core refused the operation
|
|
42
|
+
* @throws `DrawError` of core when a feature cannot be buffered or the distance is not finite
|
|
43
|
+
*/
|
|
44
|
+
export declare function runBuffer(draw: InspectorDraw, features: readonly Feature[], distanceMeters: number, segments?: number): string[] | null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Feature } from '@sakuzu/maplibre-gl-draw';
|
|
2
|
+
import type { Box } from '../store.js';
|
|
3
|
+
import type { InspectorOptions, InspectorSectionSpec, InspectorSectionsHandle, InspectorSettings, Units } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The options of the inspector with their defaults
|
|
6
|
+
*
|
|
7
|
+
* @param units - The units when the options name none (those of `createDrawUI`)
|
|
8
|
+
* @throws Error when a tab is not `style` or `attributes`
|
|
9
|
+
*/
|
|
10
|
+
export declare function inspectorSettings(options?: InspectorOptions, units?: Units): InspectorSettings;
|
|
11
|
+
/**
|
|
12
|
+
* Checks a section of the application
|
|
13
|
+
*
|
|
14
|
+
* @throws Error when the ID or the title is missing, or `appliesTo` is not a function
|
|
15
|
+
*/
|
|
16
|
+
export declare function checkSection(spec: InspectorSectionSpec): void;
|
|
17
|
+
/** The sections that apply to features; a section whose appliesTo throws does not */
|
|
18
|
+
export declare function applicableSections(sections: readonly InspectorSectionSpec[], features: readonly Feature[]): InspectorSectionSpec[];
|
|
19
|
+
/** The sections of an inspector, to add to and to remove from */
|
|
20
|
+
export declare function sectionsHandle(sections: Box<InspectorSectionSpec[]>): InspectorSectionsHandle;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Feature, FeatureStyle, FeatureStyleResolved, FeatureType } from '@sakuzu/maplibre-gl-draw';
|
|
2
|
+
import type { Messages } from '../messages.js';
|
|
3
|
+
import type { InspectorDraw, InspectorField } from './types.js';
|
|
4
|
+
/** A key of the style that the inspector edits */
|
|
5
|
+
export type StyleKey = keyof FeatureStyleResolved;
|
|
6
|
+
/** The kind of style a type reads */
|
|
7
|
+
export type StyleKind = 'point' | 'line' | 'area' | 'image';
|
|
8
|
+
/** The values of the line style, as core's LineStyle has them */
|
|
9
|
+
export declare const LINE_STYLES: readonly ["solid", "dashed", "dotted"];
|
|
10
|
+
/** The shapes of a point marker, as core's PointShape has them */
|
|
11
|
+
export declare const POINT_SHAPES: readonly ["circle", "square", "triangle", "star"];
|
|
12
|
+
/** The keys of each kind, in the order of the fields */
|
|
13
|
+
export declare const STYLE_KEYS: Readonly<Record<StyleKind, readonly StyleKey[]>>;
|
|
14
|
+
/** The kind of style of a type, or null for a custom type */
|
|
15
|
+
export declare function styleKind(type: FeatureType): StyleKind | null;
|
|
16
|
+
/** The keys a type reads, in order; none for a custom type */
|
|
17
|
+
export declare function styleKeys(type: FeatureType): readonly StyleKey[];
|
|
18
|
+
/** Whether a key is an opacity, shown as a percentage */
|
|
19
|
+
export declare function isPercentKey(key: string): boolean;
|
|
20
|
+
/** A value of the style as the field shows it: an opacity as a whole percentage */
|
|
21
|
+
export declare function displayValue(key: StyleKey, value: unknown): unknown;
|
|
22
|
+
/**
|
|
23
|
+
* The keys the features share, in the order of the first one's: the keys of every type of the
|
|
24
|
+
* selection. Empty when one of them is of a custom type, or when there is no feature
|
|
25
|
+
*/
|
|
26
|
+
export declare function sharedStyleKeys(features: readonly Pick<Feature, 'type'>[]): StyleKey[];
|
|
27
|
+
/**
|
|
28
|
+
* The fields of the style of features: the keys they share, each with the value they are drawn
|
|
29
|
+
* with, or `mixed` when their values differ.
|
|
30
|
+
*
|
|
31
|
+
* @param features - The features selected
|
|
32
|
+
* @param applied - The look of a feature as core resolves it (`draw.features.getAppliedStyle`);
|
|
33
|
+
* a feature it gives nothing for shows the keys of its own style
|
|
34
|
+
* @param messages - The words
|
|
35
|
+
* @param disabled - Whether the fields cannot be changed (read-only, a lock)
|
|
36
|
+
*/
|
|
37
|
+
export declare function styleFields(features: readonly Feature[], applied: (id: string) => FeatureStyleResolved | undefined, messages: Messages, disabled?: boolean): InspectorField[];
|
|
38
|
+
/**
|
|
39
|
+
* The style that a change of a field writes: an opacity from a percentage to a fraction (clamped
|
|
40
|
+
* to 0..1), a number as it is, a color or a choice as a string. An empty value (a number
|
|
41
|
+
* input emptied) removes the key, so the feature takes the layer rule or the default again.
|
|
42
|
+
*/
|
|
43
|
+
export declare function stylePatch(key: string, value: unknown): FeatureStyle;
|
|
44
|
+
/**
|
|
45
|
+
* The keys of the inspector's fields that the features set in their own style, over the layer
|
|
46
|
+
* rule and the defaults. Keys the features share no field for (keys of an extension) are left
|
|
47
|
+
* out, so a reset does not touch them
|
|
48
|
+
*/
|
|
49
|
+
export declare function ownStyleKeys(features: readonly Pick<Feature, 'type' | 'style'>[]): StyleKey[];
|
|
50
|
+
/** The style that removes keys, so the features take the layer rule or the defaults again */
|
|
51
|
+
export declare function resetPatch(keys: readonly string[]): FeatureStyle;
|
|
52
|
+
/**
|
|
53
|
+
* Writes a style into features, in one transaction
|
|
54
|
+
*
|
|
55
|
+
* @returns The features after the change, or null when core refused it (read-only, a lock)
|
|
56
|
+
*/
|
|
57
|
+
export declare function applyStyle(draw: Pick<InspectorDraw, 'transact' | 'features'>, ids: readonly string[], style: FeatureStyle): Feature[] | null;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { Draw, Feature } from '@sakuzu/maplibre-gl-draw';
|
|
2
|
+
/** A tab of the inspector of a feature */
|
|
3
|
+
export type InspectorTab = 'style' | 'attributes';
|
|
4
|
+
/** The units of the measurements and of the distance of a buffer */
|
|
5
|
+
export type Units = 'metric' | 'imperial';
|
|
6
|
+
/** What the inspector shows */
|
|
7
|
+
export interface InspectorOptions {
|
|
8
|
+
/** The tabs of a feature, in order; both when left out */
|
|
9
|
+
tabs?: InspectorTab[];
|
|
10
|
+
/**
|
|
11
|
+
* Whether the measurements of a feature show under its name, before the tabs; true when left
|
|
12
|
+
* out
|
|
13
|
+
*/
|
|
14
|
+
measurements?: boolean;
|
|
15
|
+
/** Whether the operations (union, intersection, difference, split, buffer) show; true when left out */
|
|
16
|
+
operations?: boolean;
|
|
17
|
+
/** The units of the measurements; `metric` when left out */
|
|
18
|
+
units?: Units;
|
|
19
|
+
}
|
|
20
|
+
/** The kind of the control of a field of a section */
|
|
21
|
+
export type InspectorFieldKind = 'text' | 'number' | 'select' | 'color' | 'toggle' | 'slider' | 'segmented';
|
|
22
|
+
/**
|
|
23
|
+
* A field of a section of the inspector: a name and the control that changes one value. The
|
|
24
|
+
* values are the application's; a unit is text after the value
|
|
25
|
+
*/
|
|
26
|
+
export interface InspectorField {
|
|
27
|
+
/** The key the change is reported with */
|
|
28
|
+
key: string;
|
|
29
|
+
/** The control */
|
|
30
|
+
kind: InspectorFieldKind;
|
|
31
|
+
/** The name before the control */
|
|
32
|
+
label: string;
|
|
33
|
+
/** The current value */
|
|
34
|
+
value?: unknown;
|
|
35
|
+
/** The features selected do not share one value; no value shows */
|
|
36
|
+
mixed?: boolean;
|
|
37
|
+
/** The choices of `select` and `segmented` */
|
|
38
|
+
options?: {
|
|
39
|
+
value: string;
|
|
40
|
+
label: string;
|
|
41
|
+
}[];
|
|
42
|
+
/** The range of `number` and `slider` */
|
|
43
|
+
min?: number;
|
|
44
|
+
max?: number;
|
|
45
|
+
step?: number;
|
|
46
|
+
/** Text after the value, such as `px` or `%` */
|
|
47
|
+
unit?: string;
|
|
48
|
+
/** A word shown while a text or a number is empty */
|
|
49
|
+
placeholder?: string;
|
|
50
|
+
/** The control cannot be changed */
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
/** A caption under the control */
|
|
53
|
+
hint?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A section an application adds to the inspector of features. It shows, on the Style tab of one
|
|
57
|
+
* feature and among the fields of several, when `appliesTo` accepts the features selected.
|
|
58
|
+
*
|
|
59
|
+
* The section either lists fields, whose changes go to `onchange`, or draws itself with `render`
|
|
60
|
+
* (or both: the fields first, then what `render` draws).
|
|
61
|
+
*/
|
|
62
|
+
export interface InspectorSectionSpec {
|
|
63
|
+
/** The name of the section, unique in the inspector */
|
|
64
|
+
id: string;
|
|
65
|
+
/** The title of the section */
|
|
66
|
+
title: string;
|
|
67
|
+
/** Whether the section shows for these features */
|
|
68
|
+
appliesTo: (features: readonly Feature[]) => boolean;
|
|
69
|
+
/** The fields of the section for these features */
|
|
70
|
+
fields?: (features: readonly Feature[]) => InspectorField[];
|
|
71
|
+
/** Called with the key and the value of a field that was changed, and the features */
|
|
72
|
+
onchange?: (key: string, value: unknown, features: readonly Feature[]) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Draws the section into an element, for what fields cannot show. It is called again with a
|
|
75
|
+
* new element when the features change; the function it returns, if any, is called before that
|
|
76
|
+
* and when the section goes away
|
|
77
|
+
*/
|
|
78
|
+
render?: (element: HTMLElement, features: readonly Feature[]) => undefined | (() => void);
|
|
79
|
+
}
|
|
80
|
+
/** The sections of the inspector that an application added */
|
|
81
|
+
export interface InspectorSectionsHandle {
|
|
82
|
+
/**
|
|
83
|
+
* Adds a section after the sections added before it
|
|
84
|
+
*
|
|
85
|
+
* @returns The function that removes it again
|
|
86
|
+
* @throws Error when the section is not valid or its ID is taken
|
|
87
|
+
*/
|
|
88
|
+
add(spec: InspectorSectionSpec): () => void;
|
|
89
|
+
/**
|
|
90
|
+
* Removes a section
|
|
91
|
+
*
|
|
92
|
+
* @returns Whether there was a section with this ID
|
|
93
|
+
*/
|
|
94
|
+
remove(id: string): boolean;
|
|
95
|
+
/** The sections, in order */
|
|
96
|
+
list(): InspectorSectionSpec[];
|
|
97
|
+
}
|
|
98
|
+
/** An inspector on the page */
|
|
99
|
+
export interface InspectorHandle {
|
|
100
|
+
/** The element of the inspector */
|
|
101
|
+
readonly element: HTMLElement;
|
|
102
|
+
/** The sections an application added */
|
|
103
|
+
readonly sections: InspectorSectionsHandle;
|
|
104
|
+
/** Removes the inspector. A second call does nothing */
|
|
105
|
+
destroy(): void;
|
|
106
|
+
}
|
|
107
|
+
/** The options of the inspector with their defaults applied */
|
|
108
|
+
export interface InspectorSettings {
|
|
109
|
+
tabs: InspectorTab[];
|
|
110
|
+
measurements: boolean;
|
|
111
|
+
operations: boolean;
|
|
112
|
+
units: Units;
|
|
113
|
+
}
|
|
114
|
+
/** The members of a draw instance that the inspector uses */
|
|
115
|
+
export type InspectorDraw = Pick<Draw, 'on' | 'off' | 'transact' | 'isReadOnly'> & {
|
|
116
|
+
readonly features: Pick<Draw['features'], 'get' | 'getMany' | 'getAppliedStyle' | 'update' | 'updateMany' | 'isEditable' | 'union' | 'difference' | 'intersection' | 'split' | 'buffer'>;
|
|
117
|
+
readonly selection: Pick<Draw['selection'], 'get' | 'set' | 'clear' | 'delete' | 'group' | 'ungroup'>;
|
|
118
|
+
readonly hidden: Pick<Draw['hidden'], 'has' | 'add' | 'remove'>;
|
|
119
|
+
readonly layers: Pick<Draw['layers'], 'get' | 'update' | 'count'>;
|
|
120
|
+
readonly groups: Pick<Draw['groups'], 'get' | 'update'>;
|
|
121
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Feature, FeatureStyleResolved, FeatureType, Group, Layer } from '@sakuzu/maplibre-gl-draw';
|
|
2
|
+
import type { Messages } from '../messages.js';
|
|
3
|
+
import { type MeasureRow } from './measure.js';
|
|
4
|
+
import type { InspectorDraw, InspectorSettings, InspectorTab } from './types.js';
|
|
5
|
+
/** The events after which the inspector reads the draw instance again */
|
|
6
|
+
export declare const INSPECTOR_EVENTS: readonly ["selection.changed", "document.changed", "hidden.changed", "readOnly.changed"];
|
|
7
|
+
/** One feature, with what its inspector needs */
|
|
8
|
+
export interface FeatureView {
|
|
9
|
+
kind: 'feature';
|
|
10
|
+
feature: Feature;
|
|
11
|
+
/** The look it is drawn with */
|
|
12
|
+
applied: FeatureStyleResolved | undefined;
|
|
13
|
+
/** Its layer */
|
|
14
|
+
layer: Layer | undefined;
|
|
15
|
+
/** Whether it can be edited now (not read-only, no lock on it, its group or its layer) */
|
|
16
|
+
editable: boolean;
|
|
17
|
+
/** Whether the document is read-only */
|
|
18
|
+
readOnly: boolean;
|
|
19
|
+
/** Whether this client hides it */
|
|
20
|
+
hidden: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** What the inspector shows */
|
|
23
|
+
export type InspectorView = {
|
|
24
|
+
kind: 'empty';
|
|
25
|
+
} | FeatureView | {
|
|
26
|
+
kind: 'features';
|
|
27
|
+
features: Feature[];
|
|
28
|
+
applied: (FeatureStyleResolved | undefined)[];
|
|
29
|
+
editable: boolean;
|
|
30
|
+
readOnly: boolean;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'layer';
|
|
33
|
+
layer: Layer;
|
|
34
|
+
onlyLayer: boolean;
|
|
35
|
+
readOnly: boolean;
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'group';
|
|
38
|
+
group: Group;
|
|
39
|
+
layer: Layer | undefined;
|
|
40
|
+
readOnly: boolean;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'items';
|
|
43
|
+
type: 'layer' | 'group';
|
|
44
|
+
count: number;
|
|
45
|
+
readOnly: boolean;
|
|
46
|
+
};
|
|
47
|
+
/** Reads what the inspector shows */
|
|
48
|
+
export declare function readView(draw: InspectorDraw): InspectorView;
|
|
49
|
+
/** What the inspector of one feature shows under its head and in its tabs */
|
|
50
|
+
export interface FeatureLayout {
|
|
51
|
+
/** The measurements under the head, before the tabs; none when the options leave them out */
|
|
52
|
+
measurements: MeasureRow[];
|
|
53
|
+
/**
|
|
54
|
+
* The description under the head, before the tabs: its text, and whether it can be changed
|
|
55
|
+
* (an empty one then shows the action that adds it). Null when it is empty and cannot be
|
|
56
|
+
* changed
|
|
57
|
+
*/
|
|
58
|
+
description: {
|
|
59
|
+
text: string;
|
|
60
|
+
editable: boolean;
|
|
61
|
+
} | null;
|
|
62
|
+
/** The tabs, in the order of the options; the Style tab only when it has something to show */
|
|
63
|
+
tabs: InspectorTab[];
|
|
64
|
+
/** Whether the Style tab has the fields of the style */
|
|
65
|
+
style: boolean;
|
|
66
|
+
/** Whether the Style tab has the buffer, at its end */
|
|
67
|
+
buffer: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Lays out the inspector of one feature
|
|
71
|
+
*
|
|
72
|
+
* @param view - The feature, as readView gives it
|
|
73
|
+
* @param settings - The options of the inspector
|
|
74
|
+
* @param sections - The number of the sections of the application that apply to the feature
|
|
75
|
+
* @param locale - The language tag the numbers of the measurements are written in
|
|
76
|
+
*/
|
|
77
|
+
export declare function featureLayout(view: Pick<FeatureView, 'feature' | 'editable'>, settings: InspectorSettings, sections: number, locale?: string): FeatureLayout;
|
|
78
|
+
/** The name of a type: the words of the built-in types, and a custom type as it is named */
|
|
79
|
+
export declare function typeLabel(type: FeatureType, m: Messages): string;
|
|
80
|
+
/** The number of features of each type, in the order the types first appear */
|
|
81
|
+
export declare function kindCounts(features: readonly Pick<Feature, 'type'>[], m: Messages): {
|
|
82
|
+
label: string;
|
|
83
|
+
count: number;
|
|
84
|
+
}[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Messages as CoreMessages, type Feature, type Layer, type LegendEntry } from '@sakuzu/maplibre-gl-draw';
|
|
2
|
+
import type { Messages } from '../messages.js';
|
|
3
|
+
/** The shape of the swatches of a layer, after the kind of what its features draw */
|
|
4
|
+
export type LegendShape = 'box' | 'dot' | 'line' | 'area';
|
|
5
|
+
/** The legend of one layer */
|
|
6
|
+
export interface LegendBlock {
|
|
7
|
+
/** The ID of the layer */
|
|
8
|
+
layerId: string;
|
|
9
|
+
/** The name of the layer */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The rows, in the order to show them */
|
|
12
|
+
entries: LegendEntry[];
|
|
13
|
+
/** The shape of the swatches */
|
|
14
|
+
shape: LegendShape;
|
|
15
|
+
}
|
|
16
|
+
/** What the legend reads from the draw instance */
|
|
17
|
+
export interface LegendSource {
|
|
18
|
+
readonly layers: {
|
|
19
|
+
get(id: string): Layer | undefined;
|
|
20
|
+
getOrder(): readonly string[];
|
|
21
|
+
};
|
|
22
|
+
readonly features: {
|
|
23
|
+
list(filter?: {
|
|
24
|
+
layerId?: string;
|
|
25
|
+
}): Feature[];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** The words of the labels of a legend, for `deriveLegend` */
|
|
29
|
+
export declare function legendMessages(m: Messages): Partial<CoreMessages>;
|
|
30
|
+
/**
|
|
31
|
+
* The shape of the swatches for the features of a layer: a dot for points, a line for lines, an
|
|
32
|
+
* area for areas, and a box when they are mixed or there are none
|
|
33
|
+
*/
|
|
34
|
+
export declare function legendShape(features: readonly Feature[]): LegendShape;
|
|
35
|
+
/** The legend of every layer with a style rule, from the front */
|
|
36
|
+
export declare function legendBlocks(source: LegendSource, m: Messages): LegendBlock[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TreeMove } from '@sakuzu/kata/svelte';
|
|
2
|
+
import type { MoveTarget } from '@sakuzu/maplibre-gl-draw';
|
|
3
|
+
import { type LayerTreeNode } from './tree.js';
|
|
4
|
+
/** The call of core a drop makes */
|
|
5
|
+
export type MovePlan = {
|
|
6
|
+
kind: 'layers';
|
|
7
|
+
order: string[];
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'group';
|
|
10
|
+
id: string;
|
|
11
|
+
to: MoveTarget;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'feature';
|
|
14
|
+
id: string;
|
|
15
|
+
to: MoveTarget;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The position in a list of core, from the back, of an item that goes just in front of `behind`
|
|
19
|
+
* (a node of the tree, or undefined when the item goes to the back)
|
|
20
|
+
*/
|
|
21
|
+
export declare function coreIndex(coreList: readonly string[], id: string, behind: string | undefined): number;
|
|
22
|
+
/**
|
|
23
|
+
* The call of core for a drop in the tree
|
|
24
|
+
*
|
|
25
|
+
* @param move - What the tree reported: the node, its new parent (null for the root) and its
|
|
26
|
+
* index among the parent's children after the move, from the front
|
|
27
|
+
* @param nodes - The nodes the tree showed when the node was dropped
|
|
28
|
+
* @returns The call, or null when the drop is not one the tree allows
|
|
29
|
+
*/
|
|
30
|
+
export declare function planMove(move: TreeMove, nodes: readonly LayerTreeNode[]): MovePlan | null;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { IconComponent, IconSource, TreeNode } from '@sakuzu/kata/svelte';
|
|
2
|
+
import { type Group as DrawGroup, type Feature, type FeatureStyleResolved, type Layer, type Selection, type SelectionType } from '@sakuzu/maplibre-gl-draw';
|
|
3
|
+
import type { Messages } from '../messages.js';
|
|
4
|
+
/** The kinds of the nodes, which are the types of the selection of core */
|
|
5
|
+
export type NodeKind = SelectionType;
|
|
6
|
+
/** A node of the tree, with the entity of core it was built from */
|
|
7
|
+
export type LayerTreeNode = TreeNode & {
|
|
8
|
+
kind: NodeKind;
|
|
9
|
+
data: Layer | DrawGroup | Feature;
|
|
10
|
+
};
|
|
11
|
+
/** What building the nodes reads from the draw instance */
|
|
12
|
+
export interface TreeSource {
|
|
13
|
+
readonly layers: {
|
|
14
|
+
get(id: string): Layer | undefined;
|
|
15
|
+
getOrder(): readonly string[];
|
|
16
|
+
};
|
|
17
|
+
readonly groups: {
|
|
18
|
+
get(id: string): DrawGroup | undefined;
|
|
19
|
+
};
|
|
20
|
+
readonly features: {
|
|
21
|
+
get(id: string): Feature | undefined;
|
|
22
|
+
getAppliedStyle(id: string): FeatureStyleResolved | undefined;
|
|
23
|
+
};
|
|
24
|
+
/** What this client hides; a node it hides shows as hidden */
|
|
25
|
+
readonly hidden?: {
|
|
26
|
+
has(id: string): boolean;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** What the tree shows */
|
|
30
|
+
export interface TreeOptions {
|
|
31
|
+
/** Whether the features show under the layers and the groups */
|
|
32
|
+
features: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The icon of a layer and of a group */
|
|
35
|
+
export declare const LAYER_ICON: IconComponent;
|
|
36
|
+
export declare const GROUP_ICON: IconComponent;
|
|
37
|
+
/** The icon of a feature type */
|
|
38
|
+
export declare function typeIcon(type: string): IconSource;
|
|
39
|
+
/** The words for each built-in feature type, from the set of the interface */
|
|
40
|
+
export declare function typeLabel(type: string, m: Messages): string;
|
|
41
|
+
/**
|
|
42
|
+
* The name of a feature: `properties.name` (the name the interface shows and edits, by the
|
|
43
|
+
* convention of the interface; core has no name of its own for a feature), or the word of its
|
|
44
|
+
* type when it has none
|
|
45
|
+
*/
|
|
46
|
+
export declare function featureName(feature: Feature, m: Messages): string;
|
|
47
|
+
/**
|
|
48
|
+
* The color of the mark of a feature: the color it is drawn with, of the part a style rule colors
|
|
49
|
+
* (the marker of a point, the line of a line, the fill of an area). An image has none
|
|
50
|
+
*/
|
|
51
|
+
export declare function featureColor(feature: Feature, style: FeatureStyleResolved | undefined): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* The nodes of the tree: the layers from the front, each with its groups and features from the
|
|
54
|
+
* front, and the features of each group from the front.
|
|
55
|
+
*
|
|
56
|
+
* An ID of the stacking order that is not a layer (a dataset placed among the layers) is left
|
|
57
|
+
* out, and so is an item of a layer that is neither a group nor a feature. A feature shows once,
|
|
58
|
+
* under its group when it is in one.
|
|
59
|
+
*/
|
|
60
|
+
export declare function buildNodes(source: TreeSource, m: Messages, options?: TreeOptions): LayerTreeNode[];
|
|
61
|
+
/** Every node of the tree by its ID, with the ID of its parent */
|
|
62
|
+
export declare function indexNodes(nodes: readonly LayerTreeNode[]): Map<string, {
|
|
63
|
+
node: LayerTreeNode;
|
|
64
|
+
parentId: string | null;
|
|
65
|
+
}>;
|
|
66
|
+
/** The rows the tree shows as selected: what draw has selected, of any of the three types */
|
|
67
|
+
export declare function selectedIds(selection: Selection): string[];
|
|
68
|
+
/**
|
|
69
|
+
* What a press in the tree selects in draw, which holds one type at a time: the IDs of the new
|
|
70
|
+
* selection that are of the kind of the node pressed last. With no node pressed (a key, a range
|
|
71
|
+
* without a pointer), the kind of the last ID.
|
|
72
|
+
*
|
|
73
|
+
* @returns The type and the IDs, or null to clear the selection
|
|
74
|
+
*/
|
|
75
|
+
export declare function selectionOf(ids: readonly string[], kindOf: (id: string) => NodeKind | undefined, pressed?: NodeKind): {
|
|
76
|
+
type: NodeKind;
|
|
77
|
+
ids: string[];
|
|
78
|
+
} | null;
|
|
79
|
+
/**
|
|
80
|
+
* Whether a node may be dropped into a parent (null for the root): a layer only at the root, a
|
|
81
|
+
* group only into a layer, a feature into a layer or a group
|
|
82
|
+
*/
|
|
83
|
+
export declare function canDropInto(node: TreeNode, parent: TreeNode | null): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Whether the selected features can make a new group: two or more, all in one layer
|
|
86
|
+
*/
|
|
87
|
+
export declare function canGroup(selection: Selection, getFeature: (id: string) => Feature | undefined): boolean;
|