@versatiles/svelte 1.0.0 → 1.0.2
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/dist/components/BBoxMap/AutoComplete.svelte +116 -89
- package/dist/components/BBoxMap/BBoxMap.svelte +52 -42
- package/dist/components/BBoxMap/BBoxMap.svelte.d.ts +5 -3
- package/dist/components/BasicMap/BasicMap.svelte +59 -34
- package/dist/components/LocatorMap/LocatorMap.svelte +67 -60
- package/dist/components/MapEditor/MapEditor.svelte +35 -80
- package/dist/components/MapEditor/components/Editor.svelte +53 -0
- package/dist/components/MapEditor/{Editor.svelte.d.ts → components/Editor.svelte.d.ts} +1 -1
- package/dist/components/MapEditor/components/EditorFill.svelte +28 -0
- package/dist/components/MapEditor/components/EditorFill.svelte.d.ts +7 -0
- package/dist/components/MapEditor/components/EditorStroke.svelte +28 -0
- package/dist/components/MapEditor/components/EditorStroke.svelte.d.ts +7 -0
- package/dist/components/MapEditor/components/EditorSymbol.svelte +43 -0
- package/dist/components/MapEditor/components/EditorSymbol.svelte.d.ts +7 -0
- package/dist/components/MapEditor/components/Sidebar.svelte +179 -0
- package/dist/components/MapEditor/components/Sidebar.svelte.d.ts +8 -0
- package/dist/components/MapEditor/components/SymbolSelector.svelte +118 -0
- package/dist/components/MapEditor/components/SymbolSelector.svelte.d.ts +8 -0
- package/dist/components/MapEditor/lib/__mocks__/cursor.d.ts +5 -0
- package/dist/components/MapEditor/lib/__mocks__/cursor.js +6 -0
- package/dist/components/MapEditor/lib/__mocks__/geometry_manager.d.ts +22 -0
- package/dist/components/MapEditor/lib/__mocks__/geometry_manager.js +21 -0
- package/dist/components/MapEditor/lib/__mocks__/map.d.ts +36 -0
- package/dist/components/MapEditor/lib/__mocks__/map.js +26 -0
- package/dist/components/MapEditor/lib/cursor.d.ts +9 -0
- package/dist/components/MapEditor/lib/cursor.js +31 -0
- package/dist/components/MapEditor/lib/element/abstract.d.ts +21 -0
- package/dist/components/MapEditor/lib/element/abstract.js +39 -0
- package/dist/components/MapEditor/lib/element/abstract_path.d.ts +11 -0
- package/dist/components/MapEditor/lib/element/abstract_path.js +79 -0
- package/dist/components/MapEditor/lib/element/line.d.ts +16 -0
- package/dist/components/MapEditor/lib/element/line.js +53 -0
- package/dist/components/MapEditor/lib/element/marker.d.ts +18 -0
- package/dist/components/MapEditor/lib/element/marker.js +62 -0
- package/dist/components/MapEditor/lib/element/polygon.d.ts +17 -0
- package/dist/components/MapEditor/lib/element/polygon.js +63 -0
- package/dist/components/MapEditor/lib/element/types.d.ts +11 -0
- package/dist/components/MapEditor/lib/geometry_manager.d.ts +20 -10
- package/dist/components/MapEditor/lib/geometry_manager.js +158 -57
- package/dist/components/MapEditor/lib/map_layer/abstract.d.ts +30 -0
- package/dist/components/MapEditor/lib/map_layer/abstract.js +90 -0
- package/dist/components/MapEditor/lib/map_layer/fill.d.ts +24 -0
- package/dist/components/MapEditor/lib/map_layer/fill.js +104 -0
- package/dist/components/MapEditor/lib/map_layer/line.d.ts +20 -0
- package/dist/components/MapEditor/lib/map_layer/line.js +90 -0
- package/dist/components/MapEditor/lib/map_layer/symbol.d.ts +19 -0
- package/dist/components/MapEditor/lib/map_layer/symbol.js +123 -0
- package/dist/components/MapEditor/lib/{types.d.ts → map_layer/types.d.ts} +7 -15
- package/dist/components/MapEditor/lib/map_layer/types.js +1 -0
- package/dist/components/MapEditor/lib/state/reader.d.ts +17 -0
- package/dist/components/MapEditor/lib/state/reader.js +161 -0
- package/dist/components/MapEditor/lib/state/types.d.ts +20 -0
- package/dist/components/MapEditor/lib/state/types.js +1 -0
- package/dist/components/MapEditor/lib/state/writer.d.ts +17 -0
- package/dist/components/MapEditor/lib/state/writer.js +178 -0
- package/dist/components/MapEditor/lib/symbols.d.ts +16 -0
- package/dist/components/MapEditor/lib/symbols.js +173 -0
- package/dist/components/MapEditor/lib/utils.d.ts +8 -1
- package/dist/components/MapEditor/lib/utils.js +33 -2
- package/dist/utils/draw/bbox.d.ts +3 -1
- package/dist/utils/draw/bbox.js +56 -51
- package/package.json +16 -16
- package/dist/components/MapEditor/Editor.svelte +0 -25
- package/dist/components/MapEditor/EditorLine.svelte +0 -27
- package/dist/components/MapEditor/EditorLine.svelte.d.ts +0 -7
- package/dist/components/MapEditor/EditorMarker.svelte +0 -42
- package/dist/components/MapEditor/EditorMarker.svelte.d.ts +0 -7
- package/dist/components/MapEditor/editor.scss +0 -16
- package/dist/components/MapEditor/lib/element_abstract.d.ts +0 -20
- package/dist/components/MapEditor/lib/element_abstract.js +0 -58
- package/dist/components/MapEditor/lib/element_line.d.ts +0 -14
- package/dist/components/MapEditor/lib/element_line.js +0 -76
- package/dist/components/MapEditor/lib/element_marker.d.ts +0 -20
- package/dist/components/MapEditor/lib/element_marker.js +0 -191
- package/dist/components/MapEditor/lib/map_layer.d.ts +0 -14
- package/dist/components/MapEditor/lib/map_layer.js +0 -61
- package/dist/utils/sprite_library.d.ts +0 -19
- package/dist/utils/sprite_library.js +0 -30
- /package/dist/components/MapEditor/lib/{types.js → element/types.js} +0 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
import { derived, get, writable } from 'svelte/store';
|
2
|
+
import { MapLayer } from './abstract.js';
|
3
|
+
import { Color } from '@versatiles/style';
|
4
|
+
import { getSymbol, getSymbolIndexByName } from '../symbols.js';
|
5
|
+
import { removeDefaultFields } from '../utils.js';
|
6
|
+
const defaultStyle = {
|
7
|
+
color: '#ff0000',
|
8
|
+
rotate: 0,
|
9
|
+
size: 1,
|
10
|
+
halo: 1,
|
11
|
+
pattern: 38,
|
12
|
+
label: ''
|
13
|
+
};
|
14
|
+
export class MapLayerSymbol extends MapLayer {
|
15
|
+
color = writable(defaultStyle.color);
|
16
|
+
halo = writable(defaultStyle.halo);
|
17
|
+
rotate = writable(defaultStyle.rotate);
|
18
|
+
size = writable(defaultStyle.size);
|
19
|
+
symbolIndex = writable(defaultStyle.pattern);
|
20
|
+
label = writable(defaultStyle.label);
|
21
|
+
haloWidth = derived([this.halo, this.size], ([halo, size]) => halo * size);
|
22
|
+
symbolInfo = derived(this.symbolIndex, (index) => getSymbol(index));
|
23
|
+
constructor(manager, id, source) {
|
24
|
+
super(manager, id);
|
25
|
+
this.addLayer(source, 'symbol', {
|
26
|
+
'icon-image': get(this.symbolInfo).image,
|
27
|
+
'icon-offset': get(this.symbolInfo).offset,
|
28
|
+
'icon-overlap': 'always',
|
29
|
+
'icon-rotate': defaultStyle.rotate,
|
30
|
+
'icon-size': defaultStyle.size,
|
31
|
+
'text-field': defaultStyle.label,
|
32
|
+
'text-font': ['noto_sans_regular'],
|
33
|
+
'text-justify': 'left',
|
34
|
+
'text-optional': true,
|
35
|
+
'text-offset': [0.7, 0.7],
|
36
|
+
'text-variable-anchor': ['right', 'left', 'top', 'bottom']
|
37
|
+
}, {
|
38
|
+
'icon-color': defaultStyle.color,
|
39
|
+
'icon-halo-blur': 0,
|
40
|
+
'icon-halo-color': '#FFFFFF',
|
41
|
+
'icon-halo-width': defaultStyle.halo,
|
42
|
+
'icon-opacity': 1,
|
43
|
+
'text-halo-blur': 0,
|
44
|
+
'text-halo-color': '#FFFFFF',
|
45
|
+
'text-halo-width': defaultStyle.halo
|
46
|
+
});
|
47
|
+
this.color.subscribe((v) => this.updatePaint('icon-color', Color.parse(v)));
|
48
|
+
this.haloWidth.subscribe((v) => {
|
49
|
+
this.updatePaint('icon-halo-width', v);
|
50
|
+
this.updatePaint('text-halo-width', v);
|
51
|
+
});
|
52
|
+
this.label.subscribe((v) => this.updateLayout('text-field', v));
|
53
|
+
this.rotate.subscribe((v) => this.updateLayout('icon-rotate', v));
|
54
|
+
this.size.subscribe((v) => {
|
55
|
+
this.updateLayout('icon-size', v);
|
56
|
+
this.updateLayout('text-size', v * 16);
|
57
|
+
});
|
58
|
+
this.symbolInfo.subscribe((v) => {
|
59
|
+
if (v.image == null) {
|
60
|
+
this.updateLayout('icon-image', undefined);
|
61
|
+
this.updateLayout('text-variable-anchor', ['center']);
|
62
|
+
}
|
63
|
+
else {
|
64
|
+
this.updateLayout('icon-image', v.image);
|
65
|
+
this.updateLayout('text-variable-anchor', ['right', 'left', 'top', 'bottom']);
|
66
|
+
this.updateLayout('icon-offset', v.offset);
|
67
|
+
}
|
68
|
+
});
|
69
|
+
}
|
70
|
+
getState() {
|
71
|
+
return removeDefaultFields({
|
72
|
+
color: get(this.color),
|
73
|
+
rotate: get(this.rotate),
|
74
|
+
size: get(this.size),
|
75
|
+
halo: get(this.halo),
|
76
|
+
pattern: get(this.symbolIndex),
|
77
|
+
label: get(this.label)
|
78
|
+
}, defaultStyle);
|
79
|
+
}
|
80
|
+
setState(state) {
|
81
|
+
if (state.color)
|
82
|
+
this.color.set(state.color);
|
83
|
+
if (state.rotate)
|
84
|
+
this.rotate.set(state.rotate);
|
85
|
+
if (state.size)
|
86
|
+
this.size.set(state.size);
|
87
|
+
if (state.halo)
|
88
|
+
this.halo.set(state.halo);
|
89
|
+
if (state.pattern)
|
90
|
+
this.symbolIndex.set(state.pattern);
|
91
|
+
if (state.label)
|
92
|
+
this.label.set(state.label);
|
93
|
+
}
|
94
|
+
getGeoJSONProperties() {
|
95
|
+
return {
|
96
|
+
'symbol-color': get(this.color),
|
97
|
+
'symbol-halo-width': get(this.halo),
|
98
|
+
'symbol-rotate': get(this.rotate),
|
99
|
+
'symbol-size': get(this.size),
|
100
|
+
'symbol-pattern': get(this.symbolInfo).name,
|
101
|
+
'symbol-label': get(this.label)
|
102
|
+
};
|
103
|
+
}
|
104
|
+
setGeoJSONProperties(properties) {
|
105
|
+
if (properties == null)
|
106
|
+
return;
|
107
|
+
if (properties['symbol-color'])
|
108
|
+
this.color.set(properties['symbol-color']);
|
109
|
+
if (properties['symbol-halo-width'])
|
110
|
+
this.halo.set(properties['symbol-halo-width']);
|
111
|
+
if (properties['symbol-rotate'])
|
112
|
+
this.rotate.set(properties['symbol-rotate']);
|
113
|
+
if (properties['symbol-size'])
|
114
|
+
this.size.set(properties['symbol-size']);
|
115
|
+
if (properties['symbol-label'])
|
116
|
+
this.label.set(properties['symbol-label']);
|
117
|
+
if (properties['symbol-pattern']) {
|
118
|
+
const index = getSymbolIndexByName(properties['symbol-pattern']);
|
119
|
+
if (index != null)
|
120
|
+
this.symbolIndex.set(index);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import type { Color } from '@versatiles/style';
|
2
|
-
import type { ExpressionSpecification, FormattedSpecification, PaddingSpecification, ResolvedImageSpecification, VariableAnchorOffsetCollectionSpecification } from 'maplibre-gl';
|
3
2
|
export interface LayerFill {
|
4
3
|
layout: {
|
5
4
|
'fill-sort-key'?: number;
|
@@ -12,7 +11,7 @@ export interface LayerFill {
|
|
12
11
|
'fill-outline-color'?: string | Color;
|
13
12
|
'fill-translate'?: [number, number];
|
14
13
|
'fill-translate-anchor'?: 'map' | 'viewport';
|
15
|
-
'fill-pattern'?: ResolvedImageSpecification;
|
14
|
+
'fill-pattern'?: maplibregl.ResolvedImageSpecification;
|
16
15
|
};
|
17
16
|
}
|
18
17
|
export interface LayerLine {
|
@@ -34,8 +33,8 @@ export interface LayerLine {
|
|
34
33
|
'line-offset'?: number;
|
35
34
|
'line-blur'?: number;
|
36
35
|
'line-dasharray'?: Array<number>;
|
37
|
-
'line-pattern'?: ResolvedImageSpecification;
|
38
|
-
'line-gradient'?: ExpressionSpecification;
|
36
|
+
'line-pattern'?: maplibregl.ResolvedImageSpecification;
|
37
|
+
'line-gradient'?: maplibregl.ExpressionSpecification;
|
39
38
|
};
|
40
39
|
}
|
41
40
|
export interface LayerSymbol {
|
@@ -53,16 +52,16 @@ export interface LayerSymbol {
|
|
53
52
|
'icon-size'?: number;
|
54
53
|
'icon-text-fit'?: 'none' | 'width' | 'height' | 'both';
|
55
54
|
'icon-text-fit-padding'?: [number, number, number, number];
|
56
|
-
'icon-image'?: ResolvedImageSpecification;
|
55
|
+
'icon-image'?: maplibregl.ResolvedImageSpecification;
|
57
56
|
'icon-rotate'?: number;
|
58
|
-
'icon-padding'?: PaddingSpecification;
|
57
|
+
'icon-padding'?: maplibregl.PaddingSpecification;
|
59
58
|
'icon-keep-upright'?: boolean;
|
60
59
|
'icon-offset'?: [number, number];
|
61
60
|
'icon-anchor'?: 'center' | 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
62
61
|
'icon-pitch-alignment'?: 'map' | 'viewport' | 'auto';
|
63
62
|
'text-pitch-alignment'?: 'map' | 'viewport' | 'auto';
|
64
63
|
'text-rotation-alignment'?: 'map' | 'viewport' | 'viewport-glyph' | 'auto';
|
65
|
-
'text-field'?: FormattedSpecification;
|
64
|
+
'text-field'?: maplibregl.FormattedSpecification;
|
66
65
|
'text-font'?: Array<string>;
|
67
66
|
'text-size'?: number;
|
68
67
|
'text-max-width'?: number;
|
@@ -71,7 +70,7 @@ export interface LayerSymbol {
|
|
71
70
|
'text-justify'?: 'auto' | 'left' | 'center' | 'right';
|
72
71
|
'text-radial-offset'?: number;
|
73
72
|
'text-variable-anchor'?: Array<'center' | 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'>;
|
74
|
-
'text-variable-anchor-offset'?: VariableAnchorOffsetCollectionSpecification;
|
73
|
+
'text-variable-anchor-offset'?: maplibregl.VariableAnchorOffsetCollectionSpecification;
|
75
74
|
'text-anchor'?: 'center' | 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
76
75
|
'text-max-angle'?: number;
|
77
76
|
'text-writing-mode'?: Array<'horizontal' | 'vertical'>;
|
@@ -103,10 +102,3 @@ export interface LayerSymbol {
|
|
103
102
|
'text-translate-anchor'?: 'map' | 'viewport';
|
104
103
|
};
|
105
104
|
}
|
106
|
-
export type ElementPoint = [number, number];
|
107
|
-
export type ElementLine = ElementPoint[];
|
108
|
-
export interface SelectionNode {
|
109
|
-
coordinates: ElementPoint;
|
110
|
-
index: number;
|
111
|
-
transparent?: boolean;
|
112
|
-
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { StateObject } from './types.js';
|
2
|
+
export declare class StateReader {
|
3
|
+
private buffer;
|
4
|
+
private offset;
|
5
|
+
constructor(buffer: Uint8Array | number[]);
|
6
|
+
readByte(): number;
|
7
|
+
readUnsignedInteger(): number;
|
8
|
+
readSignedInteger(): number;
|
9
|
+
readString(): string;
|
10
|
+
readBoolean(): boolean;
|
11
|
+
static fromBase64compressed(base64: string): Promise<StateReader>;
|
12
|
+
static fromBase64(base64: string): Promise<StateReader>;
|
13
|
+
readObject(): StateObject;
|
14
|
+
readDifferential(count: number): number[];
|
15
|
+
readColor(): string;
|
16
|
+
readType(): string;
|
17
|
+
}
|
@@ -0,0 +1,161 @@
|
|
1
|
+
import { Color } from '@versatiles/style';
|
2
|
+
import { base64ToUint8Array, decompress } from '../utils.js';
|
3
|
+
export class StateReader {
|
4
|
+
buffer;
|
5
|
+
offset = 0;
|
6
|
+
constructor(buffer) {
|
7
|
+
if (buffer instanceof Uint8Array) {
|
8
|
+
this.buffer = buffer;
|
9
|
+
}
|
10
|
+
else if (Array.isArray(buffer)) {
|
11
|
+
this.buffer = new Uint8Array(buffer);
|
12
|
+
}
|
13
|
+
else {
|
14
|
+
throw new TypeError('Invalid buffer type');
|
15
|
+
}
|
16
|
+
}
|
17
|
+
readByte() {
|
18
|
+
if (this.offset >= this.buffer.length) {
|
19
|
+
throw new RangeError('Attempt to read past end of buffer');
|
20
|
+
}
|
21
|
+
return this.buffer[this.offset++];
|
22
|
+
}
|
23
|
+
readUnsignedInteger() {
|
24
|
+
let result = 0, shift = 0, byte;
|
25
|
+
do {
|
26
|
+
if (this.offset >= this.buffer.length) {
|
27
|
+
throw new RangeError('Unexpected end of buffer while reading integer');
|
28
|
+
}
|
29
|
+
byte = this.readByte();
|
30
|
+
result |= (byte & 0x7f) << shift;
|
31
|
+
shift += 7;
|
32
|
+
} while (byte & 0x80);
|
33
|
+
return result;
|
34
|
+
}
|
35
|
+
readSignedInteger() {
|
36
|
+
const result = this.readUnsignedInteger();
|
37
|
+
if (result & 1) {
|
38
|
+
return -((result + 1) / 2);
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
return result / 2;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
readString() {
|
45
|
+
const length = this.readUnsignedInteger();
|
46
|
+
let str = '';
|
47
|
+
for (let i = 0; i < length; i++) {
|
48
|
+
str += String.fromCharCode(this.readUnsignedInteger());
|
49
|
+
}
|
50
|
+
return str;
|
51
|
+
}
|
52
|
+
readBoolean() {
|
53
|
+
return this.readByte() !== 0;
|
54
|
+
}
|
55
|
+
static async fromBase64compressed(base64) {
|
56
|
+
return new StateReader(await decompress(base64ToUint8Array(base64)));
|
57
|
+
}
|
58
|
+
static async fromBase64(base64) {
|
59
|
+
return new StateReader(base64ToUint8Array(base64));
|
60
|
+
}
|
61
|
+
readObject() {
|
62
|
+
const state = {};
|
63
|
+
while (true) {
|
64
|
+
const key = this.readByte();
|
65
|
+
if (key === 0)
|
66
|
+
break;
|
67
|
+
switch (key) {
|
68
|
+
case 10:
|
69
|
+
state.map = this.readObject();
|
70
|
+
break;
|
71
|
+
case 11:
|
72
|
+
state.style = this.readObject();
|
73
|
+
break;
|
74
|
+
case 12:
|
75
|
+
state.strokeStyle = this.readObject();
|
76
|
+
break;
|
77
|
+
case 20:
|
78
|
+
{
|
79
|
+
const length = this.readUnsignedInteger();
|
80
|
+
state.elements = Array.from({ length }, () => this.readObject());
|
81
|
+
}
|
82
|
+
break;
|
83
|
+
case 30:
|
84
|
+
state.point = [this.readSignedInteger() / 1e5, this.readSignedInteger() / 1e5];
|
85
|
+
break;
|
86
|
+
case 31:
|
87
|
+
{
|
88
|
+
const count = this.readUnsignedInteger();
|
89
|
+
const x = this.readDifferential(count);
|
90
|
+
const y = this.readDifferential(count);
|
91
|
+
state.points = Array.from({ length: count }, (_, i) => [x[i] / 1e5, y[i] / 1e5]);
|
92
|
+
}
|
93
|
+
break;
|
94
|
+
case 40:
|
95
|
+
state.color = this.readColor();
|
96
|
+
break;
|
97
|
+
case 50:
|
98
|
+
state.type = this.readType();
|
99
|
+
break;
|
100
|
+
case 60:
|
101
|
+
state.label = this.readString();
|
102
|
+
break;
|
103
|
+
case 70:
|
104
|
+
state.halo = this.readUnsignedInteger() / 10;
|
105
|
+
break;
|
106
|
+
case 71:
|
107
|
+
state.opacity = this.readUnsignedInteger() / 100;
|
108
|
+
break;
|
109
|
+
case 72:
|
110
|
+
state.pattern = this.readUnsignedInteger();
|
111
|
+
break;
|
112
|
+
case 73:
|
113
|
+
state.rotate = this.readUnsignedInteger();
|
114
|
+
break;
|
115
|
+
case 74:
|
116
|
+
state.size = this.readUnsignedInteger() / 10;
|
117
|
+
break;
|
118
|
+
case 75:
|
119
|
+
state.width = this.readUnsignedInteger() / 10;
|
120
|
+
break;
|
121
|
+
case 76:
|
122
|
+
state.zoom = this.readUnsignedInteger() / 20;
|
123
|
+
break;
|
124
|
+
case 90:
|
125
|
+
state.visible = this.readBoolean();
|
126
|
+
break;
|
127
|
+
default:
|
128
|
+
throw new Error(`Invalid state key: ${key}`);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
return state;
|
132
|
+
}
|
133
|
+
readDifferential(count) {
|
134
|
+
const values = [];
|
135
|
+
if (count === 0)
|
136
|
+
return values;
|
137
|
+
let value = this.readSignedInteger();
|
138
|
+
values.push(value);
|
139
|
+
for (let i = 1; i < count; i++) {
|
140
|
+
value += +this.readSignedInteger();
|
141
|
+
values.push(value);
|
142
|
+
}
|
143
|
+
return values;
|
144
|
+
}
|
145
|
+
readColor() {
|
146
|
+
return new Color.RGB(this.readByte(), this.readByte(), this.readByte()).asHex();
|
147
|
+
}
|
148
|
+
readType() {
|
149
|
+
const type = this.readByte();
|
150
|
+
switch (type) {
|
151
|
+
case 0:
|
152
|
+
return 'marker';
|
153
|
+
case 1:
|
154
|
+
return 'line';
|
155
|
+
case 2:
|
156
|
+
return 'polygon';
|
157
|
+
default:
|
158
|
+
throw new Error(`Invalid type: ${type}`);
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export interface StateObject {
|
2
|
+
[key: string]: StateObject | StateObject[] | [number, number] | [number, number][] | string | number | boolean | undefined;
|
3
|
+
map?: StateObject;
|
4
|
+
style?: StateObject;
|
5
|
+
strokeStyle?: StateObject;
|
6
|
+
elements?: StateObject[];
|
7
|
+
point?: [number, number];
|
8
|
+
points?: [number, number][];
|
9
|
+
color?: string;
|
10
|
+
type?: string;
|
11
|
+
label?: string;
|
12
|
+
halo?: number;
|
13
|
+
opacity?: number;
|
14
|
+
pattern?: number;
|
15
|
+
rotate?: number;
|
16
|
+
size?: number;
|
17
|
+
width?: number;
|
18
|
+
zoom?: number;
|
19
|
+
visible?: boolean;
|
20
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { StateObject } from './types.js';
|
2
|
+
export declare class StateWriter {
|
3
|
+
buffer: Uint8Array<ArrayBuffer>;
|
4
|
+
offset: number;
|
5
|
+
constructor();
|
6
|
+
writeByte(num: number): void;
|
7
|
+
writeUnsignedInteger(i: number): void;
|
8
|
+
writeSignedInteger(i: number): void;
|
9
|
+
writeString(str: string): void;
|
10
|
+
writeBoolean(b: boolean): void;
|
11
|
+
getBase64(): string;
|
12
|
+
getBase64compressed(): Promise<string>;
|
13
|
+
getBuffer(): Uint8Array;
|
14
|
+
writeObject(state: StateObject): void;
|
15
|
+
writeColor(color: unknown): void;
|
16
|
+
writeDifferential(values: number[]): void;
|
17
|
+
}
|
@@ -0,0 +1,178 @@
|
|
1
|
+
import { Color } from '@versatiles/style';
|
2
|
+
import { compress, uint8ArrayToBase64 } from '../utils.js';
|
3
|
+
const chunkSize = 65536;
|
4
|
+
export class StateWriter {
|
5
|
+
buffer = new Uint8Array(chunkSize);
|
6
|
+
offset = 0;
|
7
|
+
constructor() { }
|
8
|
+
writeByte(num) {
|
9
|
+
if (this.offset >= this.buffer.length) {
|
10
|
+
const newBuffer = new Uint8Array(this.buffer.length + chunkSize);
|
11
|
+
newBuffer.set(this.buffer);
|
12
|
+
this.buffer = newBuffer;
|
13
|
+
}
|
14
|
+
this.buffer[this.offset++] = num;
|
15
|
+
}
|
16
|
+
writeUnsignedInteger(i) {
|
17
|
+
if (!Number.isSafeInteger(i)) {
|
18
|
+
throw new RangeError(`Number out of safe integer range: ${i}`);
|
19
|
+
}
|
20
|
+
while (i > 0x7f) {
|
21
|
+
this.writeByte((i & 0x7f) | 0x80);
|
22
|
+
i >>>= 7;
|
23
|
+
}
|
24
|
+
this.writeByte(i);
|
25
|
+
}
|
26
|
+
writeSignedInteger(i) {
|
27
|
+
if (!Number.isSafeInteger(i)) {
|
28
|
+
throw new RangeError(`Number out of safe integer range: ${i}`);
|
29
|
+
}
|
30
|
+
this.writeUnsignedInteger(i < 0 ? -i * 2 - 1 : i * 2);
|
31
|
+
}
|
32
|
+
writeString(str) {
|
33
|
+
const length = str.length;
|
34
|
+
this.writeUnsignedInteger(length);
|
35
|
+
for (let i = 0; i < length; i++)
|
36
|
+
this.writeUnsignedInteger(str.charCodeAt(i));
|
37
|
+
}
|
38
|
+
writeBoolean(b) {
|
39
|
+
this.writeByte(b ? 1 : 0);
|
40
|
+
}
|
41
|
+
getBase64() {
|
42
|
+
return uint8ArrayToBase64(this.getBuffer());
|
43
|
+
}
|
44
|
+
async getBase64compressed() {
|
45
|
+
return uint8ArrayToBase64(await compress(this.getBuffer()));
|
46
|
+
}
|
47
|
+
getBuffer() {
|
48
|
+
return this.buffer.slice(0, this.offset);
|
49
|
+
}
|
50
|
+
writeObject(state) {
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
52
|
+
const me = this;
|
53
|
+
Object.entries(state).forEach(([key, value]) => {
|
54
|
+
if (value == null)
|
55
|
+
return;
|
56
|
+
switch (key) {
|
57
|
+
case 'map':
|
58
|
+
writeObject(10, value);
|
59
|
+
break;
|
60
|
+
case 'style':
|
61
|
+
writeObject(11, value);
|
62
|
+
break;
|
63
|
+
case 'strokeStyle':
|
64
|
+
writeObject(12, value);
|
65
|
+
break;
|
66
|
+
case 'elements':
|
67
|
+
if (!Array.isArray(value))
|
68
|
+
throw new Error(`Invalid elements: ${value}`);
|
69
|
+
this.writeByte(20);
|
70
|
+
this.writeUnsignedInteger(value.length);
|
71
|
+
value.forEach((element) => this.writeObject(element));
|
72
|
+
break;
|
73
|
+
case 'point':
|
74
|
+
if (!Array.isArray(value) || value.length !== 2)
|
75
|
+
throw new Error(`Invalid point: ${value}`);
|
76
|
+
this.writeByte(30);
|
77
|
+
me.writeSignedInteger(Math.round(value[0] * 1e5));
|
78
|
+
me.writeSignedInteger(Math.round(value[1] * 1e5));
|
79
|
+
break;
|
80
|
+
case 'points':
|
81
|
+
if (!Array.isArray(value))
|
82
|
+
throw new Error(`Invalid points: ${value}`);
|
83
|
+
this.writeByte(31);
|
84
|
+
this.writeUnsignedInteger(value.length);
|
85
|
+
this.writeDifferential(value.map((p) => Math.round(p[0] * 1e5)));
|
86
|
+
this.writeDifferential(value.map((p) => Math.round(p[1] * 1e5)));
|
87
|
+
break;
|
88
|
+
case 'color':
|
89
|
+
this.writeByte(40);
|
90
|
+
this.writeColor(value);
|
91
|
+
break;
|
92
|
+
case 'type':
|
93
|
+
this.writeByte(50);
|
94
|
+
switch (value) {
|
95
|
+
case 'marker':
|
96
|
+
this.writeByte(0);
|
97
|
+
break;
|
98
|
+
case 'line':
|
99
|
+
this.writeByte(1);
|
100
|
+
break;
|
101
|
+
case 'polygon':
|
102
|
+
this.writeByte(2);
|
103
|
+
break;
|
104
|
+
default:
|
105
|
+
throw new Error(`Invalid type: ${value}`);
|
106
|
+
}
|
107
|
+
break;
|
108
|
+
case 'label':
|
109
|
+
if (typeof value !== 'string')
|
110
|
+
throw new Error(`Invalid string: ${value}`);
|
111
|
+
this.writeByte(60);
|
112
|
+
this.writeString(value);
|
113
|
+
break;
|
114
|
+
case 'halo':
|
115
|
+
writeInteger(70, value, 10);
|
116
|
+
break;
|
117
|
+
case 'opacity':
|
118
|
+
writeInteger(71, value, 100);
|
119
|
+
break;
|
120
|
+
case 'pattern':
|
121
|
+
writeInteger(72, value);
|
122
|
+
break;
|
123
|
+
case 'rotate':
|
124
|
+
writeInteger(73, value);
|
125
|
+
break;
|
126
|
+
case 'size':
|
127
|
+
writeInteger(74, value, 10);
|
128
|
+
break;
|
129
|
+
case 'width':
|
130
|
+
writeInteger(75, value, 10);
|
131
|
+
break;
|
132
|
+
case 'zoom':
|
133
|
+
writeInteger(76, value, 20);
|
134
|
+
break;
|
135
|
+
case 'visible':
|
136
|
+
if (typeof value !== 'boolean')
|
137
|
+
throw new Error(`Invalid boolean: ${value}`);
|
138
|
+
this.writeByte(90);
|
139
|
+
this.writeBoolean(value);
|
140
|
+
break;
|
141
|
+
default:
|
142
|
+
throw new Error(`Invalid state key: ${key}`);
|
143
|
+
}
|
144
|
+
});
|
145
|
+
this.writeByte(0);
|
146
|
+
function writeObject(id, obj) {
|
147
|
+
if (typeof obj !== 'object' || obj == null)
|
148
|
+
throw new Error(`Invalid object: ${obj}`);
|
149
|
+
me.writeByte(id);
|
150
|
+
me.writeObject(obj);
|
151
|
+
}
|
152
|
+
function writeInteger(id, obj, factor = 1) {
|
153
|
+
if (typeof obj !== 'number')
|
154
|
+
throw new Error(`Invalid number: ${obj}`);
|
155
|
+
const value = Math.round(obj);
|
156
|
+
if (value < 0)
|
157
|
+
throw new Error(`Negative Number: ${obj}`);
|
158
|
+
me.writeByte(id);
|
159
|
+
me.writeUnsignedInteger(value * factor);
|
160
|
+
}
|
161
|
+
}
|
162
|
+
writeColor(color) {
|
163
|
+
if (typeof color !== 'string')
|
164
|
+
throw new Error(`Invalid color: ${color}`);
|
165
|
+
const c = Color.parse(color).asRGB().round().asArray();
|
166
|
+
this.writeByte(c[0]);
|
167
|
+
this.writeByte(c[1]);
|
168
|
+
this.writeByte(c[2]);
|
169
|
+
}
|
170
|
+
writeDifferential(values) {
|
171
|
+
if (values.length === 0)
|
172
|
+
return;
|
173
|
+
this.writeSignedInteger(values[0]);
|
174
|
+
for (let i = 1; i < values.length; i++) {
|
175
|
+
this.writeSignedInteger(values[i] - values[i - 1]);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
export interface SymbolInfo {
|
2
|
+
index: number;
|
3
|
+
name: string;
|
4
|
+
image?: string;
|
5
|
+
offset?: [number, number];
|
6
|
+
icon?: string;
|
7
|
+
}
|
8
|
+
export declare function getSymbol(index: number): SymbolInfo;
|
9
|
+
export declare function getSymbolIndexByName(name: string): number | undefined;
|
10
|
+
export declare class SymbolLibrary {
|
11
|
+
private map;
|
12
|
+
constructor(map: maplibregl.Map);
|
13
|
+
getSymbol(index: number): SymbolInfo;
|
14
|
+
drawSymbol(canvas: HTMLCanvasElement, index: number, halo?: boolean): void;
|
15
|
+
asList(): SymbolInfo[];
|
16
|
+
}
|