@versatiles/svelte 2.0.1 → 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 +6 -14
  14. package/dist/components/MapEditor/components/EditorFill.svelte +3 -3
  15. package/dist/components/MapEditor/components/EditorStroke.svelte +3 -3
  16. package/dist/components/MapEditor/components/EditorSymbol.svelte +9 -9
  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 +51 -98
  23. package/dist/components/MapEditor/components/Sidebar.svelte.d.ts +3 -3
  24. package/dist/components/MapEditor/components/SidebarPanel.svelte +13 -5
  25. package/dist/components/MapEditor/lib/element/abstract.d.ts +8 -4
  26. package/dist/components/MapEditor/lib/element/abstract.js +10 -1
  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 -160
  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 -1
  43. package/dist/components/MapEditor/lib/map_layer/abstract.js +25 -22
  44. package/dist/components/MapEditor/lib/map_layer/fill.js +2 -4
  45. package/dist/components/MapEditor/lib/map_layer/line.js +1 -1
  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 +7 -10
  53. package/dist/components/MapEditor/lib/state/manager.js +19 -54
  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,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,17 +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;
5
+ geometryManager: GeometryManagerInteractive;
4
6
  private disableLogging;
5
- constructor(geometryManager: GeometryManager);
6
- getHash(): string;
7
+ readonly history: StateHistory;
8
+ constructor(geometryManager: GeometryManagerInteractive);
9
+ getHash(additionalMeta?: StateMetadata): string;
7
10
  setHash(hash: string): void;
8
- private history;
9
- private historyIndex;
10
- undoEnabled: import("svelte/store").Writable<boolean>;
11
- redoEnabled: import("svelte/store").Writable<boolean>;
12
- private resetHistory;
13
11
  log(): void;
14
12
  undo(): void;
15
13
  redo(): void;
16
- private updateButtons;
17
14
  }
@@ -1,17 +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;
7
6
  disableLogging = false;
7
+ history;
8
8
  constructor(geometryManager) {
9
9
  this.geometryManager = geometryManager;
10
- this.resetHistory();
10
+ this.history = new StateHistory(geometryManager.getState());
11
11
  }
12
- getHash() {
12
+ getHash(additionalMeta) {
13
13
  const writer = new StateWriter();
14
- 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);
15
25
  return writer.asBase64();
16
26
  }
17
27
  setHash(hash) {
@@ -22,66 +32,21 @@ export class StateManager {
22
32
  this.disableLogging = true;
23
33
  this.geometryManager.setState(state);
24
34
  this.disableLogging = false;
25
- this.history = [{ ...state, map: undefined }];
26
- this.historyIndex = 0;
27
- this.updateButtons();
35
+ this.history.reset(state);
28
36
  }
29
37
  catch (error) {
30
38
  console.error(error);
31
39
  }
32
40
  }
33
- // History of state hashes
34
- // The first element is the most recent state
35
- history = [];
36
- // The index of the current state in the history
37
- // 0 means the most recent state
38
- // 1 means the second most recent state
39
- historyIndex = 0;
40
- undoEnabled = writable(false);
41
- redoEnabled = writable(false);
42
- resetHistory() {
43
- this.history = [this.geometryManager.getState()];
44
- this.historyIndex = 0;
45
- this.updateButtons();
46
- }
47
41
  log() {
48
42
  if (this.disableLogging)
49
43
  return;
50
- const state = this.geometryManager.getState();
51
- state.map = undefined; // Remove map state from history
52
- if (this.historyIndex > 0) {
53
- this.history.splice(0, this.historyIndex);
54
- this.historyIndex = 0;
55
- }
56
- this.history.unshift(state);
57
- // Remove old history
58
- if (this.history.length > MAXLENGTH) {
59
- this.history.length = MAXLENGTH;
60
- }
61
- this.updateButtons();
44
+ this.history.push(this.geometryManager.getState());
62
45
  }
63
46
  undo() {
64
- if (this.historyIndex < this.history.length - 1) {
65
- this.historyIndex++;
66
- const state = this.history[this.historyIndex];
67
- this.disableLogging = true;
68
- this.geometryManager.setState(state);
69
- this.disableLogging = false;
70
- this.updateButtons();
71
- }
47
+ this.geometryManager.setState(this.history.undo());
72
48
  }
73
49
  redo() {
74
- if (this.historyIndex > 0) {
75
- this.historyIndex--;
76
- const state = this.history[this.historyIndex];
77
- this.disableLogging = true;
78
- this.geometryManager.setState(state);
79
- this.disableLogging = false;
80
- this.updateButtons();
81
- }
82
- }
83
- updateButtons() {
84
- this.undoEnabled.set(this.historyIndex < this.history.length - 1);
85
- this.redoEnabled.set(this.historyIndex > 0);
50
+ this.geometryManager.setState(this.history.redo());
86
51
  }
87
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;
@@ -50,14 +50,16 @@ export class StateWriter {
50
50
  for (let i = 0; i < length; i++)
51
51
  cb(array[i]);
52
52
  }
53
- writePoint(point, level = 14) {
54
- const scale = Math.pow(2, level + 2);
55
- this.writeInteger(Math.round(point[0] * scale), level + 11);
56
- this.writeInteger(Math.round(point[1] * scale), level + 10);
57
- }
58
- writePoints(points, level = 14) {
53
+ writePoint(point, resolutionInMeters = 1) {
54
+ if (!resolutionInMeters || resolutionInMeters < 1)
55
+ resolutionInMeters = 1;
56
+ const scale = Math.round(1e5 / resolutionInMeters);
57
+ this.writeVarint(Math.round(point[0] * scale), true);
58
+ this.writeVarint(Math.round(point[1] * scale), true);
59
+ }
60
+ writePoints(points, resolutionInMeters = 1) {
59
61
  this.writeVarint(points.length);
60
- const scale = Math.pow(2, level + 2);
62
+ const scale = Math.round(1e5 / resolutionInMeters);
61
63
  let x = 0;
62
64
  let y = 0;
63
65
  points.forEach((point) => {
@@ -72,15 +74,8 @@ export class StateWriter {
72
74
  writeRoot(root) {
73
75
  // Write the version
74
76
  this.writeInteger(0, 3);
75
- if (root.map) {
76
- this.writeBit(true);
77
- this.writeMap(root.map);
78
- }
79
- else {
80
- this.writeBit(false);
81
- }
82
- // metadata is not used yet
83
- this.writeBit(false);
77
+ this.writeMap(root.map);
78
+ this.writeMetadata(root.meta);
84
79
  root.elements.forEach((element) => {
85
80
  switch (element.type) {
86
81
  case 'marker':
@@ -95,12 +90,35 @@ export class StateWriter {
95
90
  this.writeInteger(3, 3);
96
91
  this.writeElementPolygon(element);
97
92
  break;
93
+ case 'circle':
94
+ this.writeInteger(4, 3);
95
+ this.writeElementCircle(element);
96
+ break;
98
97
  }
99
98
  });
100
99
  }
101
100
  writeMap(map) {
102
- this.writeInteger(Math.round(map.zoom * 32), 10);
103
- this.writePoint(map.center, Math.ceil(map.zoom));
101
+ if (!map) {
102
+ return this.writeBit(false);
103
+ }
104
+ this.writeBit(true);
105
+ const value = Math.round(Math.log2(map.radius) * 40);
106
+ const radius = Math.pow(2, value / 40);
107
+ this.writeInteger(value, 10);
108
+ // effective resolution of coordinates is 1000 times the visible radius
109
+ this.writePoint(map.center, radius / 1e3);
110
+ this.writeBit(false); // additional map data not supported yet
111
+ }
112
+ writeMetadata(metadata) {
113
+ if (!metadata || Object.keys(metadata).length === 0) {
114
+ return this.writeBit(false);
115
+ }
116
+ this.writeBit(true);
117
+ //if (metadata.heading) {
118
+ // this.writeInteger(1, 6);
119
+ // this.writeString(metadata.heading);
120
+ //}
121
+ this.writeInteger(0, 6);
104
122
  }
105
123
  writeElementMarker(element) {
106
124
  this.writePoint(element.point);
@@ -111,6 +129,7 @@ export class StateWriter {
111
129
  else {
112
130
  this.writeBit(false);
113
131
  }
132
+ this.writeBit(false); // tooltip not supported yet
114
133
  return element;
115
134
  }
116
135
  writeElementLine(element) {
@@ -122,6 +141,7 @@ export class StateWriter {
122
141
  else {
123
142
  this.writeBit(false);
124
143
  }
144
+ this.writeBit(false); // tooltip not supported yet
125
145
  return element;
126
146
  }
127
147
  writeElementPolygon(element) {
@@ -140,6 +160,26 @@ export class StateWriter {
140
160
  else {
141
161
  this.writeBit(false);
142
162
  }
163
+ this.writeBit(false); // tooltip not supported yet
164
+ }
165
+ writeElementCircle(element) {
166
+ this.writePoint(element.point);
167
+ this.writeVarint(Math.round(element.radius));
168
+ if (element.style) {
169
+ this.writeBit(true);
170
+ this.writeStyle(element.style);
171
+ }
172
+ else {
173
+ this.writeBit(false);
174
+ }
175
+ if (element.strokeStyle) {
176
+ this.writeBit(true);
177
+ this.writeStyle(element.strokeStyle);
178
+ }
179
+ else {
180
+ this.writeBit(false);
181
+ }
182
+ this.writeBit(false); // tooltip not supported yet
143
183
  }
144
184
  writeStyle(style) {
145
185
  if (style.halo != null) {
@@ -184,7 +224,7 @@ export class StateWriter {
184
224
  this.writeInteger(0, 4);
185
225
  }
186
226
  writeColor(color) {
187
- const rgb = Color.parse(color).toRGB();
227
+ const rgb = Color.parse(color).asRGB();
188
228
  this.writeInteger(rgb.r, 8);
189
229
  this.writeInteger(rgb.g, 8);
190
230
  this.writeInteger(rgb.b, 8);
@@ -11,6 +11,6 @@ export declare class SymbolLibrary {
11
11
  private map;
12
12
  constructor(map: maplibregl.Map);
13
13
  getSymbol(index: number): SymbolInfo;
14
- drawSymbol(canvas: HTMLCanvasElement, index: number, halo?: boolean): void;
14
+ drawSymbol(canvas: HTMLCanvasElement, index: number, halo?: number): void;
15
15
  asList(): SymbolInfo[];
16
16
  }