@versatiles/svelte 2.0.0 → 2.1.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 (83) hide show
  1. package/dist/components/BBoxMap/BBoxMap.svelte +23 -12
  2. package/dist/components/BBoxMap/lib/bbox.d.ts +1 -1
  3. package/dist/components/BBoxMap/lib/bbox.js +19 -17
  4. package/dist/components/BasicMap/BasicMap.svelte +22 -9
  5. package/dist/components/BasicMap/BasicMap.svelte.d.ts +2 -1
  6. package/dist/components/MapEditor/MapEditor.svelte +51 -20
  7. package/dist/components/MapEditor/components/Dialog.svelte +92 -0
  8. package/dist/components/MapEditor/components/Dialog.svelte.d.ts +17 -0
  9. package/dist/components/MapEditor/components/DialogFile.svelte +112 -0
  10. package/dist/components/MapEditor/components/DialogFile.svelte.d.ts +6 -0
  11. package/dist/components/MapEditor/components/DialogShare.svelte +216 -0
  12. package/dist/components/MapEditor/components/DialogShare.svelte.d.ts +10 -0
  13. package/dist/components/MapEditor/components/Editor.svelte +16 -14
  14. package/dist/components/MapEditor/components/EditorFill.svelte +35 -3
  15. package/dist/components/MapEditor/components/EditorStroke.svelte +35 -3
  16. package/dist/components/MapEditor/components/EditorSymbol.svelte +85 -8
  17. package/dist/components/MapEditor/components/InputRow.svelte +2 -3
  18. package/dist/components/MapEditor/components/PanelFile.svelte +73 -0
  19. package/dist/components/MapEditor/components/PanelFile.svelte.d.ts +7 -0
  20. package/dist/components/MapEditor/components/PanelSymbolSelector.svelte +82 -0
  21. package/dist/components/MapEditor/components/PanelSymbolSelector.svelte.d.ts +8 -0
  22. package/dist/components/MapEditor/components/Sidebar.svelte +59 -103
  23. package/dist/components/MapEditor/components/Sidebar.svelte.d.ts +3 -3
  24. package/dist/components/MapEditor/components/SidebarPanel.svelte +26 -9
  25. package/dist/components/MapEditor/lib/element/abstract.d.ts +8 -4
  26. package/dist/components/MapEditor/lib/element/abstract.js +11 -2
  27. package/dist/components/MapEditor/lib/element/abstract_path.d.ts +3 -2
  28. package/dist/components/MapEditor/lib/element/abstract_path.js +6 -3
  29. package/dist/components/MapEditor/lib/element/circle.d.ts +25 -0
  30. package/dist/components/MapEditor/lib/element/circle.js +118 -0
  31. package/dist/components/MapEditor/lib/element/line.d.ts +2 -2
  32. package/dist/components/MapEditor/lib/element/line.js +1 -1
  33. package/dist/components/MapEditor/lib/element/marker.d.ts +4 -3
  34. package/dist/components/MapEditor/lib/element/marker.js +2 -2
  35. package/dist/components/MapEditor/lib/element/polygon.d.ts +2 -2
  36. package/dist/components/MapEditor/lib/element/polygon.js +2 -2
  37. package/dist/components/MapEditor/lib/element/types.d.ts +2 -3
  38. package/dist/components/MapEditor/lib/geometry_manager.d.ts +12 -29
  39. package/dist/components/MapEditor/lib/geometry_manager.js +44 -162
  40. package/dist/components/MapEditor/lib/geometry_manager_interactive.d.ts +33 -0
  41. package/dist/components/MapEditor/lib/geometry_manager_interactive.js +102 -0
  42. package/dist/components/MapEditor/lib/map_layer/abstract.d.ts +2 -2
  43. package/dist/components/MapEditor/lib/map_layer/abstract.js +25 -25
  44. package/dist/components/MapEditor/lib/map_layer/fill.js +5 -16
  45. package/dist/components/MapEditor/lib/map_layer/line.js +5 -17
  46. package/dist/components/MapEditor/lib/map_layer/symbol.js +1 -1
  47. package/dist/components/MapEditor/lib/selection.d.ts +11 -0
  48. package/dist/components/MapEditor/lib/selection.js +70 -0
  49. package/dist/components/MapEditor/lib/state/constants.js +5 -6
  50. package/dist/components/MapEditor/lib/state/history.d.ts +14 -0
  51. package/dist/components/MapEditor/lib/state/history.js +53 -0
  52. package/dist/components/MapEditor/lib/state/manager.d.ts +8 -10
  53. package/dist/components/MapEditor/lib/state/manager.js +24 -48
  54. package/dist/components/MapEditor/lib/state/reader.d.ts +6 -4
  55. package/dist/components/MapEditor/lib/state/reader.js +70 -18
  56. package/dist/components/MapEditor/lib/state/types.d.ts +19 -2
  57. package/dist/components/MapEditor/lib/state/utils.d.ts +2 -0
  58. package/dist/components/MapEditor/lib/state/utils.js +12 -0
  59. package/dist/components/MapEditor/lib/state/writer.d.ts +6 -4
  60. package/dist/components/MapEditor/lib/state/writer.js +59 -19
  61. package/dist/components/MapEditor/lib/symbols.d.ts +1 -1
  62. package/dist/components/MapEditor/lib/symbols.js +47 -28
  63. package/dist/components/MapEditor/lib/utils/event_handler.d.ts +10 -0
  64. package/dist/components/MapEditor/lib/utils/event_handler.js +39 -0
  65. package/dist/components/MapEditor/lib/utils/geometry.d.ts +12 -0
  66. package/dist/components/MapEditor/lib/utils/geometry.js +87 -0
  67. package/dist/components/MapEditor/lib/utils/types.d.ts +2 -0
  68. package/dist/components/MapEditor/lib/utils/types.js +1 -0
  69. package/dist/components/MapEditor/style/button.scss +115 -0
  70. package/dist/components/MapEditor/style/index.scss +3 -0
  71. package/dist/components/MapEditor/style/layout.scss +20 -0
  72. package/dist/components/MapEditor/style/other.scss +10 -0
  73. package/dist/utils/location.d.ts +1 -0
  74. package/dist/utils/location.js +181 -0
  75. package/dist/utils/map_style.d.ts +2 -2
  76. package/dist/utils/map_style.js +2 -2
  77. package/package.json +29 -29
  78. package/dist/components/MapEditor/components/SymbolSelector.svelte +0 -110
  79. package/dist/components/MapEditor/components/SymbolSelector.svelte.d.ts +0 -8
  80. package/dist/components/MapEditor/lib/utils.d.ts +0 -6
  81. package/dist/components/MapEditor/lib/utils.js +0 -23
  82. /package/dist/components/MapEditor/lib/{geocoder.d.ts → utils/geocoder.d.ts} +0 -0
  83. /package/dist/components/MapEditor/lib/{geocoder.js → utils/geocoder.js} +0 -0
@@ -0,0 +1,70 @@
1
+ import { get, writable } from 'svelte/store';
2
+ export class SelectionHandler {
3
+ selectedElement = writable(undefined);
4
+ selectionNodes;
5
+ manager;
6
+ constructor(manager) {
7
+ this.manager = manager;
8
+ const map = this.manager.map;
9
+ map.on('mousedown', 'selection_nodes', (e) => {
10
+ const element = get(this.selectedElement);
11
+ if (element == null)
12
+ return;
13
+ const feature = map.queryRenderedFeatures(e.point, { layers: ['selection_nodes'] })[0];
14
+ const selectedNode = element.getSelectionNodeUpdater(feature.properties);
15
+ if (selectedNode == null)
16
+ return;
17
+ // @ts-expect-error ensure that the event is ignored by other layers
18
+ e.ignore = true;
19
+ e.preventDefault();
20
+ if (e.originalEvent.shiftKey) {
21
+ selectedNode.delete();
22
+ this.updateSelectionNodes();
23
+ }
24
+ else {
25
+ const onMove = (e) => {
26
+ e.preventDefault();
27
+ selectedNode.update(e.lngLat.lng, e.lngLat.lat);
28
+ this.updateSelectionNodes();
29
+ };
30
+ map.on('mousemove', onMove);
31
+ map.once('mouseup', () => {
32
+ map.off('mousemove', onMove);
33
+ this.manager.state.log();
34
+ });
35
+ }
36
+ });
37
+ map.on('mouseenter', 'selection_nodes', () => {
38
+ this.manager.cursor.togglePrecise('selection_nodes');
39
+ });
40
+ map.on('mouseleave', 'selection_nodes', () => {
41
+ this.manager.cursor.togglePrecise('selection_nodes', false);
42
+ });
43
+ map.on('click', (e) => {
44
+ if (!e.originalEvent.shiftKey)
45
+ this.selectElement();
46
+ e.preventDefault();
47
+ });
48
+ }
49
+ selectElement(element) {
50
+ if (element == get(this.selectedElement))
51
+ return;
52
+ const elements = get(this.manager.elements);
53
+ elements.forEach((e) => e.select(e == element));
54
+ this.selectedElement.set(element);
55
+ this.updateSelectionNodes();
56
+ }
57
+ updateSelectionNodes() {
58
+ const nodes = get(this.selectedElement)?.getSelectionNodes() ?? [];
59
+ if (!this.selectionNodes)
60
+ this.selectionNodes = this.manager.map.getSource('selection_nodes');
61
+ this.selectionNodes?.setData({
62
+ type: 'FeatureCollection',
63
+ features: nodes.map((n) => ({
64
+ type: 'Feature',
65
+ properties: { index: n.index, opacity: n.transparent ? 0.3 : 1 },
66
+ geometry: { type: 'Point', coordinates: n.coordinates }
67
+ }))
68
+ });
69
+ }
70
+ }
@@ -11,12 +11,11 @@ for (let i = 0; i < BASE64_CHARS.length; i++) {
11
11
  ];
12
12
  }
13
13
  export const CHAR_VALUE2CODE = [
14
- 32, 101, 116, 97, 110, 105, 111, 115, 114, 108, 100, 104, 99, 117, 109, 112, 102, 103, 46, 121,
15
- 98, 119, 44, 118, 48, 107, 49, 83, 84, 67, 50, 56, 53, 65, 57, 120, 51, 73, 45, 54, 52, 55, 77,
16
- 66, 34, 39, 80, 69, 78, 70, 82, 68, 85, 113, 76, 71, 74, 72, 79, 87, 106, 122, 47, 60, 62, 75, 41,
17
- 40, 86, 89, 58, 81, 90, 88, 59, 63, 94, 38, 43, 91, 93, 36, 33, 42, 61, 126, 95, 123, 64, 0, 1, 2,
18
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
19
- 29, 30, 31, 35, 37, 92, 96, 124, 125, 127
14
+ 32, 101, 116, 97, 110, 105, 111, 115, 114, 108, 100, 104, 99, 117, 109, 112, 102, 103, 46, 121, 98, 119, 44, 118, 48,
15
+ 107, 49, 83, 84, 67, 50, 56, 53, 65, 57, 120, 51, 73, 45, 54, 52, 55, 77, 66, 34, 39, 80, 69, 78, 70, 82, 68, 85, 113,
16
+ 76, 71, 74, 72, 79, 87, 106, 122, 47, 60, 62, 75, 41, 40, 86, 89, 58, 81, 90, 88, 59, 63, 94, 38, 43, 91, 93, 36, 33,
17
+ 42, 61, 126, 95, 123, 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
18
+ 25, 26, 27, 28, 29, 30, 31, 35, 37, 92, 96, 124, 125, 127
20
19
  ];
21
20
  export const CHAR_CODE2VALUE = [];
22
21
  CHAR_VALUE2CODE.forEach((c, v) => (CHAR_CODE2VALUE[c] = v));
@@ -0,0 +1,14 @@
1
+ import type { StateRoot } from './types.js';
2
+ export declare class StateHistory {
3
+ private history;
4
+ private index;
5
+ undoEnabled: import("svelte/store").Writable<boolean>;
6
+ redoEnabled: import("svelte/store").Writable<boolean>;
7
+ constructor(state: StateRoot);
8
+ reset(state: StateRoot): void;
9
+ push(state: StateRoot): void;
10
+ private get;
11
+ undo(): StateRoot;
12
+ redo(): StateRoot;
13
+ private updateButtons;
14
+ }
@@ -0,0 +1,53 @@
1
+ import { writable } from 'svelte/store';
2
+ const MAXLENGTH = 100;
3
+ export class StateHistory {
4
+ // History of state hashes
5
+ // The first element is the most recent state
6
+ history = [];
7
+ // The index of the current state in the history
8
+ // 0 means the most recent state
9
+ // 1 means the second most recent state
10
+ index = 0;
11
+ undoEnabled = writable(false);
12
+ redoEnabled = writable(false);
13
+ constructor(state) {
14
+ this.reset(state);
15
+ }
16
+ reset(state) {
17
+ this.history = [];
18
+ this.index = 0;
19
+ this.push(state);
20
+ }
21
+ push(state) {
22
+ state.map = undefined; // Remove map state from history
23
+ if (this.index > 0) {
24
+ this.history.splice(0, this.index);
25
+ this.index = 0;
26
+ }
27
+ this.history.unshift(JSON.stringify(state));
28
+ // Remove old history
29
+ if (this.history.length > MAXLENGTH) {
30
+ this.history.length = MAXLENGTH;
31
+ }
32
+ this.updateButtons();
33
+ }
34
+ get() {
35
+ return JSON.parse(this.history[this.index]);
36
+ }
37
+ undo() {
38
+ if (this.index < this.history.length - 1)
39
+ this.index++;
40
+ this.updateButtons();
41
+ return this.get();
42
+ }
43
+ redo() {
44
+ if (this.index > 0)
45
+ this.index--;
46
+ this.updateButtons();
47
+ return this.get();
48
+ }
49
+ updateButtons() {
50
+ this.undoEnabled.set(this.index < this.history.length - 1);
51
+ this.redoEnabled.set(this.index > 0);
52
+ }
53
+ }
@@ -1,16 +1,14 @@
1
- import type { GeometryManager } from '../geometry_manager.js';
1
+ import type { GeometryManagerInteractive } from '../geometry_manager_interactive.js';
2
+ import type { StateMetadata } from './types.js';
3
+ import { StateHistory } from './history.js';
2
4
  export declare class StateManager {
3
- geometryManager: GeometryManager;
4
- constructor(geometryManager: GeometryManager);
5
- getHash(): string;
5
+ geometryManager: GeometryManagerInteractive;
6
+ private disableLogging;
7
+ readonly history: StateHistory;
8
+ constructor(geometryManager: GeometryManagerInteractive);
9
+ getHash(additionalMeta?: StateMetadata): string;
6
10
  setHash(hash: string): void;
7
- private history;
8
- private historyIndex;
9
- undoEnabled: import("svelte/store").Writable<boolean>;
10
- redoEnabled: import("svelte/store").Writable<boolean>;
11
- private resetHistory;
12
11
  log(): void;
13
12
  undo(): void;
14
13
  redo(): void;
15
- private updateButtons;
16
14
  }
@@ -1,16 +1,27 @@
1
- import { writable } from 'svelte/store';
2
1
  import { StateReader } from './reader.js';
3
2
  import { StateWriter } from './writer.js';
4
- const MAXLENGTH = 100;
3
+ import { StateHistory } from './history.js';
5
4
  export class StateManager {
6
5
  geometryManager;
6
+ disableLogging = false;
7
+ history;
7
8
  constructor(geometryManager) {
8
9
  this.geometryManager = geometryManager;
9
- this.resetHistory();
10
+ this.history = new StateHistory(geometryManager.getState());
10
11
  }
11
- getHash() {
12
+ getHash(additionalMeta) {
12
13
  const writer = new StateWriter();
13
- writer.writeRoot(this.geometryManager.getState());
14
+ const state = this.geometryManager.getState();
15
+ if (additionalMeta) {
16
+ state.meta ??= {};
17
+ const keys = Object.keys(additionalMeta);
18
+ for (const key of keys) {
19
+ if (additionalMeta[key] == null)
20
+ continue;
21
+ state.meta[key] = additionalMeta[key];
22
+ }
23
+ }
24
+ writer.writeRoot(state);
14
25
  return writer.asBase64();
15
26
  }
16
27
  setHash(hash) {
@@ -18,59 +29,24 @@ export class StateManager {
18
29
  return;
19
30
  try {
20
31
  const state = StateReader.fromBase64(hash).readRoot();
32
+ this.disableLogging = true;
21
33
  this.geometryManager.setState(state);
22
- this.resetHistory();
34
+ this.disableLogging = false;
35
+ this.history.reset(state);
23
36
  }
24
37
  catch (error) {
25
38
  console.error(error);
26
39
  }
27
40
  }
28
- // History of state hashes
29
- // The first element is the most recent state
30
- history = [];
31
- // The index of the current state in the history
32
- // 0 means the most recent state
33
- // 1 means the second most recent state
34
- historyIndex = 0;
35
- undoEnabled = writable(false);
36
- redoEnabled = writable(false);
37
- resetHistory() {
38
- this.history = [this.geometryManager.getState()];
39
- this.historyIndex = 0;
40
- this.updateButtons();
41
- }
42
41
  log() {
43
- const state = this.geometryManager.getState();
44
- state.map = undefined; // Remove map state from history
45
- if (this.historyIndex > 0) {
46
- this.history.splice(0, this.historyIndex);
47
- this.historyIndex = 0;
48
- }
49
- this.history.unshift(state);
50
- // Remove old history
51
- if (this.history.length > MAXLENGTH) {
52
- this.history.length = MAXLENGTH;
53
- }
54
- this.updateButtons();
42
+ if (this.disableLogging)
43
+ return;
44
+ this.history.push(this.geometryManager.getState());
55
45
  }
56
46
  undo() {
57
- if (this.historyIndex < this.history.length - 1) {
58
- this.historyIndex++;
59
- const state = this.history[this.historyIndex];
60
- this.geometryManager.setState(state);
61
- this.updateButtons();
62
- }
47
+ this.geometryManager.setState(this.history.undo());
63
48
  }
64
49
  redo() {
65
- if (this.historyIndex > 0) {
66
- this.historyIndex--;
67
- const state = this.history[this.historyIndex];
68
- this.geometryManager.setState(state);
69
- this.updateButtons();
70
- }
71
- }
72
- updateButtons() {
73
- this.undoEnabled.set(this.historyIndex < this.history.length - 1);
74
- this.redoEnabled.set(this.historyIndex > 0);
50
+ this.geometryManager.setState(this.history.redo());
75
51
  }
76
52
  }
@@ -1,4 +1,4 @@
1
- import type { StateElementLine, StateElementMarker, StateElementPolygon, StateRoot, StateStyle } from './types.js';
1
+ import type { StateElementCircle, StateElementLine, StateElementMarker, StateElementPolygon, StateMetadata, StateRoot, StateStyle } from './types.js';
2
2
  export declare class StateReader {
3
3
  bits: boolean[];
4
4
  offset: number;
@@ -11,13 +11,15 @@ export declare class StateReader {
11
11
  read6pack(): number;
12
12
  readVarint(signed?: true): number;
13
13
  readArray<T>(cb: () => T): T[];
14
- readPoint(level?: number): [number, number];
15
- readPoints(level?: number): [number, number][];
14
+ readPoint(resolutionInMeters?: number): [number, number];
15
+ readPoints(resolutionInMeters?: number): [number, number][];
16
16
  readRoot(): StateRoot;
17
- readMap(): NonNullable<StateRoot['map']>;
17
+ readMap(): StateRoot['map'];
18
+ readMetadata(): StateMetadata | undefined;
18
19
  readElementMarker(): StateElementMarker;
19
20
  readElementLine(): StateElementLine;
20
21
  readElementPolygon(): StateElementPolygon;
22
+ readElementCircle(): StateElementCircle;
21
23
  readStyle(): StateStyle;
22
24
  readColor(): string;
23
25
  readString(): string;
@@ -83,29 +83,28 @@ export class StateReader {
83
83
  throw new Error(`Error reading array`, { cause });
84
84
  }
85
85
  }
86
- readPoint(level = 14) {
86
+ readPoint(resolutionInMeters = 1) {
87
+ if (!resolutionInMeters || resolutionInMeters < 1)
88
+ resolutionInMeters = 1;
87
89
  try {
88
- const scale = Math.pow(2, level + 2);
89
- return [
90
- this.readInteger(level + 11, true) / scale,
91
- this.readInteger(level + 10, true) / scale
92
- ];
90
+ const scale = Math.round(1e5 / resolutionInMeters);
91
+ return [this.readVarint(true) / scale, this.readVarint(true) / scale];
93
92
  }
94
93
  catch (cause) {
95
94
  throw new Error(`Error reading point`, { cause });
96
95
  }
97
96
  }
98
- readPoints(level = 14) {
97
+ readPoints(resolutionInMeters = 1) {
99
98
  try {
100
99
  const length = this.readVarint();
101
- const scale = Math.pow(2, -level - 2);
100
+ const scale = Math.round(1e5 / resolutionInMeters);
102
101
  let x = 0;
103
102
  let y = 0;
104
103
  const points = [];
105
104
  for (let i = 0; i < length; i++) {
106
105
  x += this.readVarint(true);
107
106
  y += this.readVarint(true);
108
- points[i] = [x * scale, y * scale];
107
+ points[i] = [x / scale, y / scale];
109
108
  }
110
109
  return points;
111
110
  }
@@ -121,13 +120,13 @@ export class StateReader {
121
120
  throw new Error(`Unsupported version: ${version}`);
122
121
  }
123
122
  // Read the map element
124
- if (this.readBit()) {
125
- root.map = this.readMap();
126
- }
123
+ root.map = this.readMap();
124
+ if (!root.map)
125
+ delete root.map;
127
126
  // Read the metadata
128
- if (this.readBit()) {
129
- throw new Error(`Metadata not supported yet`);
130
- }
127
+ root.meta = this.readMetadata();
128
+ if (!root.meta)
129
+ delete root.meta;
131
130
  // Read the elements
132
131
  while (true) {
133
132
  let key;
@@ -149,6 +148,9 @@ export class StateReader {
149
148
  case 3:
150
149
  root.elements.push(this.readElementPolygon());
151
150
  break;
151
+ case 4:
152
+ root.elements.push(this.readElementCircle());
153
+ break;
152
154
  default:
153
155
  console.warn(`Unknown state key: ${key}`);
154
156
  }
@@ -160,19 +162,48 @@ export class StateReader {
160
162
  }
161
163
  readMap() {
162
164
  try {
163
- const zoom = this.readInteger(10) / 32;
164
- const center = this.readPoint(Math.ceil(zoom));
165
- return { zoom, center };
165
+ if (!this.readBit())
166
+ return undefined;
167
+ const radius = Math.pow(2, this.readInteger(10) / 40);
168
+ // effective resolution of coordinates is 1000 times the visible radius
169
+ const center = this.readPoint(radius / 1e3);
170
+ if (this.readBit())
171
+ throw new Error('Addtional map meta data is not supported yet');
172
+ return { radius, center };
166
173
  }
167
174
  catch (cause) {
168
175
  throw new Error(`Error reading map`, { cause });
169
176
  }
170
177
  }
178
+ readMetadata() {
179
+ try {
180
+ if (!this.readBit())
181
+ return undefined;
182
+ const metadata = {};
183
+ while (true) {
184
+ const key = this.readInteger(6);
185
+ switch (key) {
186
+ case 0:
187
+ return metadata;
188
+ //case 1:
189
+ // metadata.heading = this.readString();
190
+ // break;
191
+ default:
192
+ throw new Error(`Invalid state key: ${key}`);
193
+ }
194
+ }
195
+ }
196
+ catch (cause) {
197
+ throw new Error(`Error reading metadata`, { cause });
198
+ }
199
+ }
171
200
  readElementMarker() {
172
201
  try {
173
202
  const element = { type: 'marker', point: this.readPoint() };
174
203
  if (this.readBit())
175
204
  element.style = this.readStyle();
205
+ if (this.readBit())
206
+ throw new Error(`Tooltip not supported yet`);
176
207
  return element;
177
208
  }
178
209
  catch (cause) {
@@ -184,6 +215,8 @@ export class StateReader {
184
215
  const element = { type: 'line', points: this.readPoints() };
185
216
  if (this.readBit())
186
217
  element.style = this.readStyle();
218
+ if (this.readBit())
219
+ throw new Error(`Tooltip not supported yet`);
187
220
  return element;
188
221
  }
189
222
  catch (cause) {
@@ -197,12 +230,31 @@ export class StateReader {
197
230
  element.style = this.readStyle();
198
231
  if (this.readBit())
199
232
  element.strokeStyle = this.readStyle();
233
+ if (this.readBit())
234
+ throw new Error(`Tooltip not supported yet`);
200
235
  return element;
201
236
  }
202
237
  catch (cause) {
203
238
  throw new Error(`Error reading polygon element`, { cause });
204
239
  }
205
240
  }
241
+ readElementCircle() {
242
+ try {
243
+ const point = this.readPoint();
244
+ const radius = this.readVarint();
245
+ const element = { type: 'circle', point, radius };
246
+ if (this.readBit())
247
+ element.style = this.readStyle();
248
+ if (this.readBit())
249
+ element.strokeStyle = this.readStyle();
250
+ if (this.readBit())
251
+ throw new Error(`Tooltip not supported yet`);
252
+ return element;
253
+ }
254
+ catch (cause) {
255
+ throw new Error(`Error reading circle element`, { cause });
256
+ }
257
+ }
206
258
  readStyle() {
207
259
  try {
208
260
  const style = {};
@@ -1,26 +1,38 @@
1
1
  export interface StateRoot {
2
2
  map?: {
3
3
  center: [number, number];
4
- zoom: number;
4
+ radius: number;
5
5
  };
6
+ meta?: StateMetadata;
6
7
  elements: StateElement[];
7
8
  }
8
- export type StateElement = StateElementMarker | StateElementLine | StateElementPolygon;
9
+ export type StateElement = StateElementMarker | StateElementLine | StateElementPolygon | StateElementCircle;
9
10
  export interface StateElementMarker {
10
11
  type: 'marker';
11
12
  point: [number, number];
12
13
  style?: StateStyle;
14
+ tooltip?: StateTooltip;
13
15
  }
14
16
  export interface StateElementLine {
15
17
  type: 'line';
16
18
  points: [number, number][];
17
19
  style?: StateStyle;
20
+ tooltip?: StateTooltip;
18
21
  }
19
22
  export interface StateElementPolygon {
20
23
  type: 'polygon';
21
24
  points: [number, number][];
22
25
  style?: StateStyle;
23
26
  strokeStyle?: StateStyle;
27
+ tooltip?: StateTooltip;
28
+ }
29
+ export interface StateElementCircle {
30
+ type: 'circle';
31
+ point: [number, number];
32
+ radius: number;
33
+ style?: StateStyle;
34
+ strokeStyle?: StateStyle;
35
+ tooltip?: StateTooltip;
24
36
  }
25
37
  export interface StateStyle {
26
38
  halo?: number;
@@ -34,3 +46,8 @@ export interface StateStyle {
34
46
  label?: string;
35
47
  visible?: boolean;
36
48
  }
49
+ export interface StateMetadata {
50
+ }
51
+ export interface StateTooltip {
52
+ text?: string;
53
+ }
@@ -0,0 +1,2 @@
1
+ import type { StateStyle } from './types.js';
2
+ export declare function removeDefaultFields(value: StateStyle, def: StateStyle): Partial<StateStyle> | undefined;
@@ -0,0 +1,12 @@
1
+ export function removeDefaultFields(value, def) {
2
+ const entries = Object.entries(value).filter(([k, v]) => {
3
+ if (v === undefined)
4
+ return false;
5
+ if (v === def[k])
6
+ return false;
7
+ return true;
8
+ });
9
+ if (entries.length === 0)
10
+ return undefined;
11
+ return Object.fromEntries(entries);
12
+ }
@@ -1,4 +1,4 @@
1
- import type { StateElementLine, StateElementMarker, StateElementPolygon, StateRoot, StateStyle } from './types.js';
1
+ import type { StateElementCircle, StateElementLine, StateElementMarker, StateElementPolygon, StateMetadata, StateRoot, StateStyle } from './types.js';
2
2
  export declare class StateWriter {
3
3
  bits: boolean[];
4
4
  constructor();
@@ -8,13 +8,15 @@ export declare class StateWriter {
8
8
  writeInteger(value: number, bits: number): number;
9
9
  writeVarint(value: number, signed?: true): void;
10
10
  writeArray<T>(array: T[], cb: (v: T) => void): void;
11
- writePoint(point: [number, number], level?: number): void;
12
- writePoints(points: [number, number][], level?: number): void;
11
+ writePoint(point: [number, number], resolutionInMeters?: number): void;
12
+ writePoints(points: [number, number][], resolutionInMeters?: number): void;
13
13
  writeRoot(root: StateRoot): void;
14
- writeMap(map: NonNullable<StateRoot['map']>): void;
14
+ writeMap(map: StateRoot['map']): void;
15
+ writeMetadata(metadata?: StateMetadata): void;
15
16
  writeElementMarker(element: StateElementMarker): StateElementMarker;
16
17
  writeElementLine(element: StateElementLine): StateElementLine;
17
18
  writeElementPolygon(element: StateElementPolygon): void;
19
+ writeElementCircle(element: StateElementCircle): void;
18
20
  writeStyle(style: StateStyle): void;
19
21
  writeColor(color: string): void;
20
22
  writeString(value: string): string;