@vcmap/viewshed 3.0.5 → 4.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.
@@ -1,5 +1,11 @@
1
+ import type { VcsMap } from '@vcmap/core';
1
2
  import { CesiumMap, moduleIdSymbol } from '@vcmap/core';
3
+ import type { PluginConfigEditor, VcsPlugin, VcsUiApp } from '@vcmap/ui';
4
+ import { getLogger } from '@vcsuite/logger';
5
+ import { reactive } from 'vue';
6
+ import type { ColorOptions, ViewshedOptions } from './viewshed.js';
2
7
  import Viewshed, { ViewshedTypes } from './viewshed.js';
8
+ import type { ViewshedManager } from './viewshedManager.js';
3
9
  import createViewshedManager, {
4
10
  ViewshedPluginModes,
5
11
  } from './viewshedManager.js';
@@ -7,52 +13,104 @@ import { setupViewshedWindow } from './util/windowHelper.js';
7
13
  import addViewshedToolButtons from './util/toolboxHelper.js';
8
14
  import { name, version, mapVersion } from '../package.json';
9
15
  import ViewshedCategory, { createCategory } from './viewshedCategory.js';
10
- import ViewshedConfigEditor, {
11
- getDefaultOptions,
12
- } from './ViewshedConfigEditor.vue';
16
+ import type { ViewshedConfig } from './ViewshedConfigEditor.vue';
17
+ import ViewshedConfigEditor from './ViewshedConfigEditor.vue';
18
+ import ActivateViewshedCallback from './callbacks/activateViewshedCallback.js';
19
+ import DeactivateViewshedCallback from './callbacks/deactivateViewshedCallback.js';
13
20
 
14
- /**
15
- * @typedef {Object} ViewshedPluginState
16
- * @property {import("./viewshedManager.js").ViewshedPluginModes | null} mode Which mode the plugin is currently in.
17
- * @property {import("./viewshed.js").ViewshedOptions | null} currentViewshed The currents viewshed options.
18
- */
21
+ export type ViewshedPluginState = {
22
+ /** Which mode the plugin is currently in. */
23
+ m?: ViewshedPluginModes | null;
24
+ /** The currents viewshed options. */
25
+ cv?: ViewshedOptions | null;
26
+ };
19
27
 
20
- /**
21
- * @typedef {import("./viewshed.js").ColorOptions & {tools?: Array<ViewshedTypes>}} ViewshedPluginOptions
22
- */
28
+ export type ViewshedPluginOptions = ColorOptions & {
29
+ tools?: ViewshedTypes[];
30
+ };
23
31
 
24
- /**
25
- * Implementation of VcsPlugin interface. This function should not throw! Put exceptions in initialize instead.
26
- * @param {ViewshedPluginOptions} config - the configuration of this plugin instance, passed in from the app.
27
- * @returns {import("@vcmap/ui/src/vcsUiApp").VcsPlugin<T, ViewshedPluginState>}
28
- */
29
- export default function plugin(config) {
30
- let viewshedManager;
31
- let app;
32
- let destroy = () => {};
32
+ export function getDefaultOptions(): ViewshedConfig {
33
+ return {
34
+ visibleColor: Viewshed.getDefaultOptions().colorOptions.visibleColor,
35
+ shadowColor: Viewshed.getDefaultOptions().colorOptions.shadowColor,
36
+ tools: [...Object.values(ViewshedTypes)],
37
+ };
38
+ }
39
+
40
+ export type ViewshedPlugin = VcsPlugin<
41
+ ViewshedPluginOptions,
42
+ ViewshedPluginState
43
+ > & {
44
+ readonly state: ViewshedPluginState;
45
+ activate: () => void;
46
+ deactivate: () => void;
47
+ };
48
+
49
+ function activateCachedViewshed(
50
+ map: VcsMap,
51
+ viewshedManager?: ViewshedManager,
52
+ state?: ViewshedPluginState,
53
+ ): void {
54
+ if (!state?.m || !(map instanceof CesiumMap)) {
55
+ return;
56
+ }
57
+ if (state.m === ViewshedPluginModes.CREATE) {
58
+ const viewshedType = state.cv?.viewshedType ?? ViewshedTypes.CONE;
59
+ viewshedManager?.createViewshed(viewshedType).catch((e: unknown) => {
60
+ getLogger(name).error('Failed to create viewshed', String(e));
61
+ });
62
+ } else if (state.cv) {
63
+ const activeViewshed = new Viewshed(state.cv);
64
+ if (state.m === ViewshedPluginModes.VIEW) {
65
+ viewshedManager?.viewViewshed(activeViewshed);
66
+ } else {
67
+ viewshedManager?.editViewshed(activeViewshed);
68
+ }
69
+ }
70
+ }
71
+
72
+ export default function plugin(options: ViewshedPluginOptions): ViewshedPlugin {
73
+ let app: VcsUiApp | undefined;
74
+ let viewshedManager: ViewshedManager | undefined;
75
+ let destroy = (): void => {};
76
+
77
+ const defaultOptions = getDefaultOptions();
78
+ const config = { ...defaultOptions, ...options };
79
+ const defaultState: ViewshedPluginState = reactive({});
33
80
 
34
81
  return {
35
- get name() {
82
+ get name(): string {
36
83
  return name;
37
84
  },
38
- get version() {
85
+ get version(): string {
39
86
  return version;
40
87
  },
41
- get mapVersion() {
88
+ get mapVersion(): string {
42
89
  return mapVersion;
43
90
  },
44
- /**
45
- * @param {import("@vcmap/ui").VcsUiApp} vcsUiApp
46
- * @param {ViewshedPluginState=} state
47
- * @returns {Promise<void>}
48
- */
49
- async initialize(vcsUiApp, state) {
91
+ getDefaultOptions,
92
+ state: defaultState,
93
+ async initialize(
94
+ vcsUiApp: VcsUiApp,
95
+ state?: ViewshedPluginState,
96
+ ): Promise<void> {
50
97
  app = vcsUiApp;
98
+ app.callbackClassRegistry.registerClass(
99
+ this[moduleIdSymbol],
100
+ ActivateViewshedCallback.className,
101
+ ActivateViewshedCallback,
102
+ );
103
+ app.callbackClassRegistry.registerClass(
104
+ this[moduleIdSymbol],
105
+ DeactivateViewshedCallback.className,
106
+ DeactivateViewshedCallback,
107
+ );
51
108
  vcsUiApp.categoryClassRegistry.registerClass(
52
109
  this[moduleIdSymbol],
53
110
  ViewshedCategory.className,
54
111
  ViewshedCategory,
55
112
  );
113
+
56
114
  const viewshedCategoryHelper = await createCategory(vcsUiApp);
57
115
  viewshedManager = createViewshedManager(
58
116
  vcsUiApp,
@@ -63,7 +121,7 @@ export default function plugin(config) {
63
121
  vcsUiApp,
64
122
  viewshedManager,
65
123
  name,
66
- config.tools || getDefaultOptions().tools,
124
+ config.tools || defaultOptions.tools,
67
125
  );
68
126
  const { destroy: destroyViewshedWindow } = setupViewshedWindow(
69
127
  viewshedManager,
@@ -72,85 +130,77 @@ export default function plugin(config) {
72
130
  );
73
131
 
74
132
  const { activeMap } = vcsUiApp.maps;
75
- function activateCachedViewshed(map) {
76
- if (state?.m && state.cv && map instanceof CesiumMap) {
77
- const activeViewshed = new Viewshed(state.cv);
78
- if (state.m === ViewshedPluginModes.VIEW) {
79
- viewshedManager.viewViewshed(activeViewshed);
80
- } else {
81
- viewshedManager.editViewshed(activeViewshed);
82
- }
83
- }
84
- }
133
+
85
134
  let appliedCachedViewshed = false;
86
135
  if (activeMap) {
87
136
  appliedCachedViewshed = true;
88
- activateCachedViewshed(activeMap);
137
+ activateCachedViewshed(activeMap, viewshedManager, state);
89
138
  }
90
139
  const mapActivatedListener = vcsUiApp.maps.mapActivated.addEventListener(
91
140
  (map) => {
92
- viewshedManager.stop();
141
+ viewshedManager?.stop();
93
142
  if (!appliedCachedViewshed) {
94
- activateCachedViewshed(map);
143
+ activateCachedViewshed(map, viewshedManager, state);
95
144
  appliedCachedViewshed = true;
96
145
  }
97
146
  },
98
147
  );
99
148
 
100
- destroy = () => {
149
+ destroy = (): void => {
101
150
  mapActivatedListener();
102
151
  destroyButtons();
103
152
  destroyViewshedWindow();
104
- viewshedCategoryHelper.destroy();
105
- viewshedManager.destroy();
153
+ viewshedCategoryHelper?.destroy();
154
+ viewshedManager?.destroy();
106
155
  };
107
156
  },
108
- /**
109
- * should return all default values of the configuration
110
- * @returns {ViewshedPluginOptions}
111
- */
112
- getDefaultOptions,
113
- /**
114
- * should return the plugin's serialization excluding all default values
115
- * @returns {ViewshedPluginOptions}
116
- */
117
- toJSON() {
118
- const serial = {};
119
- if (
120
- config.tools &&
121
- getDefaultOptions().tools.length !== config.tools.length
122
- ) {
157
+ activate(): void {
158
+ if (!viewshedManager || !app) {
159
+ getLogger(name).error('Cannot activate plugin before initialization');
160
+ return;
161
+ }
162
+ if (!app.maps.activeMap) {
163
+ getLogger(name).error('Cannot activate plugin without an active map');
164
+ return;
165
+ }
166
+ activateCachedViewshed(app.maps.activeMap, viewshedManager, this.state);
167
+ },
168
+ deactivate(): void {
169
+ viewshedManager?.stop();
170
+ },
171
+ toJSON(): ViewshedPluginOptions {
172
+ const serial: ViewshedPluginOptions = {};
173
+ if (config.tools && defaultOptions.tools.length !== config.tools.length) {
123
174
  serial.tools = [...config.tools];
124
175
  }
125
176
  if (
126
177
  config.shadowColor &&
127
- config.shadowColor !== Viewshed.getDefaultOptions().shadowColor
178
+ config.shadowColor !== defaultOptions.shadowColor
128
179
  ) {
129
180
  serial.shadowColor = config.shadowColor;
130
181
  }
131
182
  if (
132
183
  config.visibleColor &&
133
- config.visibleColor !== Viewshed.getDefaultOptions().visibleColor
184
+ config.visibleColor !== defaultOptions.visibleColor
134
185
  ) {
135
186
  serial.visibleColor = config.visibleColor;
136
187
  }
137
188
  return serial;
138
189
  },
139
- /**
140
- * should return the plugins state
141
- * @param {boolean} forUrl
142
- * @returns {ViewshedPluginState}
143
- */
144
- getState(forUrl) {
145
- const state = {};
146
- const mode = viewshedManager.mode.value;
147
- const currentViewshed = viewshedManager.currentViewshed.value?.toJSON();
190
+ getState(forUrl?: boolean): ViewshedPluginState {
191
+ const state: ViewshedPluginState = {};
192
+ const mode = viewshedManager?.mode.value;
193
+ const currentViewshed = viewshedManager?.currentViewshed.value?.toJSON();
148
194
 
149
- if (mode !== null && mode !== 'create' && currentViewshed) {
195
+ if (
196
+ mode !== null &&
197
+ mode !== ViewshedPluginModes.CREATE &&
198
+ currentViewshed
199
+ ) {
150
200
  state.m = mode;
151
201
  state.cv = currentViewshed;
152
- if (forUrl && state.cv.properties?.title) {
153
- if (Object.keys(state.properties).length === 1) {
202
+ if (forUrl && state.cv?.properties?.title) {
203
+ if (Object.keys(state.cv?.properties).length === 1) {
154
204
  delete state.cv.properties;
155
205
  } else {
156
206
  delete state.cv.properties.title;
@@ -160,11 +210,7 @@ export default function plugin(config) {
160
210
 
161
211
  return state;
162
212
  },
163
- /**
164
- * components for configuring the plugin and/ or custom items defined by the plugin
165
- * @returns {Array<import("@vcmap/ui").PluginConfigEditor>}
166
- */
167
- getConfigEditors() {
213
+ getConfigEditors(): PluginConfigEditor<object>[] {
168
214
  return [
169
215
  {
170
216
  component: ViewshedConfigEditor,
@@ -176,7 +222,6 @@ export default function plugin(config) {
176
222
  },
177
223
  ];
178
224
  },
179
- destroy: () => destroy(),
180
225
  i18n: {
181
226
  en: {
182
227
  viewshed: {
@@ -191,7 +236,6 @@ export default function plugin(config) {
191
236
  heightMode: 'Height mode',
192
237
  relative: 'Relative to ground',
193
238
  absolute: 'Absolute',
194
- new: 'New',
195
239
  cancel: 'Cancel',
196
240
  [ViewshedTypes.CONE]: 'Cone viewshed analysis',
197
241
  [ViewshedTypes.THREESIXTY]: '360° viewshed analysis',
@@ -199,7 +243,6 @@ export default function plugin(config) {
199
243
  [ViewshedTypes.CONE]: 'Create cone viewshed analysis',
200
244
  [ViewshedTypes.THREESIXTY]: 'Create 360° viewshed analysis',
201
245
  },
202
- addToMyWorkspace: 'Add to My Workspace',
203
246
  temporary: 'Temporary',
204
247
  jumpToViewpoint: 'Jump to viewpoint',
205
248
  returnToViewpoint: 'Return to previous viewpoint',
@@ -231,7 +274,6 @@ export default function plugin(config) {
231
274
  heightMode: 'Höhenmodus',
232
275
  relative: 'Relativ zum Gelände',
233
276
  absolute: 'Absolut',
234
- new: 'Neu',
235
277
  cancel: 'Abbrechen',
236
278
  [ViewshedTypes.CONE]: 'Sichtkegelanalyse',
237
279
  [ViewshedTypes.THREESIXTY]: '360° Sichtsanalyse',
@@ -239,7 +281,6 @@ export default function plugin(config) {
239
281
  [ViewshedTypes.CONE]: 'Sichtkegelanalyse erstellen',
240
282
  [ViewshedTypes.THREESIXTY]: '360° Sichtanalyse erstellen',
241
283
  },
242
- addToMyWorkspace: 'Zu Mein Arbeitsbereich hinzufügen',
243
284
  temporary: 'Temporäre',
244
285
  jumpToViewpoint: 'Zu Standpunkt springen',
245
286
  returnToViewpoint: 'Zu vorherigem Standpunkt zurück springen',
@@ -259,5 +300,18 @@ export default function plugin(config) {
259
300
  },
260
301
  },
261
302
  },
303
+ destroy(): void {
304
+ if (app) {
305
+ app.callbackClassRegistry.unregisterClass(
306
+ this[moduleIdSymbol],
307
+ ActivateViewshedCallback.className,
308
+ );
309
+ app.callbackClassRegistry.unregisterClass(
310
+ this[moduleIdSymbol],
311
+ DeactivateViewshedCallback.className,
312
+ );
313
+ }
314
+ destroy();
315
+ },
262
316
  };
263
317
  }
@@ -1,41 +1,53 @@
1
1
  import { CesiumMap } from '@vcmap/core';
2
+ import type {
3
+ SelectToolboxComponentOptions,
4
+ SingleToolboxComponentOptions,
5
+ VcsUiApp,
6
+ } from '@vcmap/ui';
2
7
  import { ToolboxType } from '@vcmap/ui';
3
8
  import { check, ofEnum } from '@vcsuite/check';
4
9
  import { reactive, watch } from 'vue';
5
10
  import { ViewshedTypes } from '../viewshed.js';
6
- import { ViewshedIcons } from './windowHelper.js';
11
+ import { viewshedIcons } from './windowHelper.js';
12
+ import type { ViewshedManager } from '../viewshedManager.js';
7
13
  import { ViewshedPluginModes } from '../viewshedManager.js';
8
14
 
9
- /**
10
- * @typedef {Object} ViewshedToolbox
11
- * @property {import("@vcmap/ui/src/manager/toolbox/toolboxManager").SelectToolboxComponentOptions} toolbox
12
- * @property {function():void} destroy
13
- */
15
+ type ViewshedToolbox = {
16
+ toolbox: SingleToolboxComponentOptions | SelectToolboxComponentOptions;
17
+ destroy: () => void;
18
+ };
14
19
 
15
20
  /**
16
21
  *
17
- * @param {import("@vcmap/ui").VcsUiApp} app The VcsUiApp instance
18
- * @param {import("../viewshedManager.js").ViewshedManager} manager The viewshed manager.
19
- * @param {string} name Name of toolbox.
20
- * @param {Array<string>} tools The tools to be available in the toolbox
21
- * @returns {ViewshedToolbox} A select toolbox with buttons to create 360 and cone viewshed.
22
+ * @param app The VcsUiApp instance
23
+ * @param manager The viewshed manager.
24
+ * @param name Name of toolbox.
25
+ * @param tools The tools to be available in the toolbox
26
+ * @returns A select toolbox with buttons to create 360 and cone viewshed.
22
27
  */
23
- function createViewshedToolbox(app, manager, name, tools) {
28
+ function createViewshedToolbox(
29
+ app: VcsUiApp,
30
+ manager: ViewshedManager,
31
+ name: string,
32
+ tools: string[],
33
+ ): ViewshedToolbox {
24
34
  /**
25
- * @param {string} tool The tool to create.
26
- * @returns {{name:ViewshedTypes, icon:string, title:string, } | undefined} A tool object.
35
+ * @param tool The tool to create.
36
+ * @returns A tool object.
27
37
  */
28
- function parseTool(tool) {
38
+ function parseTool(
39
+ tool: ViewshedTypes,
40
+ ): { name: ViewshedTypes; icon: string; title: string } | undefined {
29
41
  if (tool === ViewshedTypes.CONE) {
30
42
  return {
31
43
  name: ViewshedTypes.CONE,
32
- icon: ViewshedIcons[ViewshedTypes.CONE],
44
+ icon: viewshedIcons[ViewshedTypes.CONE],
33
45
  title: `viewshed.create.${ViewshedTypes.CONE}`,
34
46
  };
35
47
  } else if (tool === ViewshedTypes.THREESIXTY) {
36
48
  return {
37
49
  name: ViewshedTypes.THREESIXTY,
38
- icon: ViewshedIcons[ViewshedTypes.THREESIXTY],
50
+ icon: viewshedIcons[ViewshedTypes.THREESIXTY],
39
51
  title: `viewshed.create.${ViewshedTypes.THREESIXTY}`,
40
52
  };
41
53
  } else {
@@ -43,10 +55,10 @@ function createViewshedToolbox(app, manager, name, tools) {
43
55
  }
44
56
  }
45
57
 
46
- let toolbox;
47
- let currentViewshedWatcher;
58
+ let toolbox: SingleToolboxComponentOptions | SelectToolboxComponentOptions;
59
+ let currentViewshedWatcher: () => void;
48
60
  if (tools.length === 1) {
49
- const tool = parseTool(tools[0]);
61
+ const tool = parseTool(tools[0] as ViewshedTypes)!;
50
62
  toolbox = {
51
63
  type: ToolboxType.SINGLE,
52
64
  action: reactive({
@@ -54,15 +66,15 @@ function createViewshedToolbox(app, manager, name, tools) {
54
66
  active: false,
55
67
  background: false,
56
68
  disabled: !(app.maps.activeMap instanceof CesiumMap),
57
- callback() {
69
+ async callback() {
58
70
  if (this.active) {
59
71
  if (this.background && manager.currentViewshed.value) {
60
72
  manager.editViewshed(manager.currentViewshed.value);
61
73
  } else {
62
74
  manager.stop();
63
75
  }
64
- } else {
65
- manager.createViewshed(tool.name);
76
+ } else if (tool) {
77
+ await manager.createViewshed(tool.name);
66
78
  }
67
79
  },
68
80
  }),
@@ -76,7 +88,7 @@ function createViewshedToolbox(app, manager, name, tools) {
76
88
  active: false,
77
89
  background: false,
78
90
  disabled: !(app.maps.activeMap instanceof CesiumMap),
79
- callback() {
91
+ async callback() {
80
92
  if (this.active) {
81
93
  if (this.background && manager.currentViewshed.value) {
82
94
  manager.editViewshed(manager.currentViewshed.value);
@@ -85,17 +97,17 @@ function createViewshedToolbox(app, manager, name, tools) {
85
97
  }
86
98
  } else {
87
99
  const toolName = this.tools[this.currentIndex].name;
88
- manager.createViewshed(toolName);
100
+ await manager.createViewshed(toolName);
89
101
  }
90
102
  },
91
- selected(newIndex) {
103
+ async selected(newIndex: number) {
92
104
  if (newIndex !== this.currentIndex) {
93
105
  this.currentIndex = newIndex;
94
106
  }
95
107
  const toolName = this.tools[this.currentIndex].name;
96
- manager.createViewshed(toolName);
108
+ await manager.createViewshed(toolName);
97
109
  },
98
- tools: tools.flatMap(parseTool),
110
+ tools: tools.flatMap((t) => parseTool(t as ViewshedTypes)),
99
111
  }),
100
112
  };
101
113
 
@@ -103,8 +115,10 @@ function createViewshedToolbox(app, manager, name, tools) {
103
115
  manager.currentViewshed,
104
116
  (currentViewshed) => {
105
117
  if (currentViewshed) {
106
- toolbox.action.currentIndex = toolbox.action.tools.findIndex(
107
- (tool) => tool.name === currentViewshed.type,
118
+ (toolbox as SelectToolboxComponentOptions).action.currentIndex = (
119
+ toolbox as SelectToolboxComponentOptions
120
+ ).action.tools.findIndex(
121
+ (tool) => (tool.name as ViewshedTypes) === currentViewshed.type,
108
122
  );
109
123
  }
110
124
  },
@@ -133,24 +147,29 @@ function createViewshedToolbox(app, manager, name, tools) {
133
147
  });
134
148
 
135
149
  return {
136
- destroy() {
150
+ toolbox,
151
+ destroy(): void {
137
152
  viewshedModeWatcher();
138
153
  currentViewshedWatcher?.();
139
154
  mapChangedListener();
140
155
  },
141
- toolbox,
142
156
  };
143
157
  }
144
158
 
145
159
  /**
146
160
  *
147
- * @param {import("@vcmap/ui").VcsUiApp} app The VcsUiApp instance
148
- * @param {import("../viewshedManager.js").ViewshedManager} manager The viewshed manager.
149
- * @param {string} name Name of toolbox action and owner of toolbox component
150
- * @param {Array<string>} tools The tools to be available in the toolbox
151
- * @returns {function():void} Function to remove toolbox component.
161
+ * @param app The VcsUiApp instance
162
+ * @param manager The viewshed manager.
163
+ * @param name Name of toolbox action and owner of toolbox component
164
+ * @param tools The tools to be available in the toolbox
165
+ * @returns Function to remove toolbox component.
152
166
  */
153
- export default function addToolButtons(app, manager, name, tools) {
167
+ export default function addToolButtons(
168
+ app: VcsUiApp,
169
+ manager: ViewshedManager,
170
+ name: string,
171
+ tools: string[],
172
+ ): () => void {
154
173
  check(tools, [ofEnum(ViewshedTypes)]);
155
174
 
156
175
  const { toolbox: createToolbox, destroy: destroyCreateToolbox } =
@@ -1,41 +1,40 @@
1
1
  import { ref, watch } from 'vue';
2
+ import type {
3
+ CollectionComponentClass,
4
+ WindowComponentOptions,
5
+ VcsUiApp,
6
+ } from '@vcmap/ui';
2
7
  import { WindowSlot, makeEditorCollectionComponentClass } from '@vcmap/ui';
3
8
  import ViewshedWindow from '../ViewshedWindow.vue';
4
9
  import { name } from '../../package.json';
10
+ import type Viewshed from '../viewshed.js';
5
11
  import { ViewshedTypes } from '../viewshed.js';
12
+ import type { ViewshedManager } from '../viewshedManager.js';
6
13
  import { ViewshedPluginModes } from '../viewshedManager.js';
7
14
 
8
- export const ViewshedIcons = {
15
+ export const viewshedIcons = {
9
16
  [ViewshedTypes.CONE]: '$vcsViewshed',
10
17
  [ViewshedTypes.THREESIXTY]: '$vcsViewshedCone',
11
18
  };
12
19
 
13
20
  /**
14
- * @typedef {Object} ViewshedWindow
15
- * @property {function():void} destroy Destroys watchers and removes window.
16
- * @property {function():void} toggleWindow Toggles window. Only opens window when manager has current viewshed.
21
+ * @param manager The viewshed manager.
22
+ * @param app The VcsUiApp instance
23
+ * @param collectionComponent The collection component of the category.
24
+ * @returns The destroy function.
17
25
  */
18
-
19
- /**
20
- *
21
- * @param {import("../viewshedManager.js").ViewshedManager} manager The viewshed manager.
22
- * @param {import("@vcmap/ui").VcsUiApp} app The VcsUiApp instance
23
- * @param {import("@vcmap/ui").CollectionComponent} collectionComponent The collection component of the category.
24
- * @returns {ViewshedWindow} Viewshed window api.
25
- */
26
- export function setupViewshedWindow(manager, app, collectionComponent) {
27
- /**
28
- * @type {import("vue").Ref<undefined | string | string[]>}
29
- */
30
- const headerTitle = ref();
26
+ export function setupViewshedWindow(
27
+ manager: ViewshedManager,
28
+ app: VcsUiApp,
29
+ collectionComponent: CollectionComponentClass<Viewshed>,
30
+ ): { destroy: () => void } {
31
+ const headerTitle = ref<string | string[]>('');
31
32
  const headerIcon = ref();
32
33
  const windowId = `${collectionComponent.id}-editor`;
33
34
 
34
- const editor = {
35
+ const editor: WindowComponentOptions = {
35
36
  component: ViewshedWindow,
36
- provides: {
37
- manager,
38
- },
37
+ provides: { manager },
39
38
  state: {
40
39
  headerTitle,
41
40
  headerIcon,
@@ -49,17 +48,19 @@ export function setupViewshedWindow(manager, app, collectionComponent) {
49
48
  ...editor,
50
49
  props: {
51
50
  selection: collectionComponent.selection,
52
- getViewshed: () => collectionComponent.collection.getByKey(item.name),
51
+ getViewshed: (): Viewshed | undefined =>
52
+ collectionComponent.collection.getByKey(item.name),
53
53
  },
54
54
  }),
55
55
  });
56
56
 
57
- function updateHeader() {
57
+ function updateHeader(): void {
58
58
  if (manager.currentViewshed.value) {
59
- headerIcon.value = ViewshedIcons[manager.currentViewshed.value.type];
59
+ headerIcon.value = viewshedIcons[manager.currentViewshed.value.type];
60
60
 
61
61
  if (manager.currentIsPersisted.value) {
62
- headerTitle.value = manager.currentViewshed.value.properties.title;
62
+ headerTitle.value = manager.currentViewshed.value.properties
63
+ .title as string;
63
64
  } else if (manager.mode.value === ViewshedPluginModes.CREATE) {
64
65
  headerTitle.value = `viewshed.create.${manager.currentViewshed.value.type}`;
65
66
  } else {
@@ -71,7 +72,7 @@ export function setupViewshedWindow(manager, app, collectionComponent) {
71
72
  }
72
73
  }
73
74
 
74
- function updateWindow() {
75
+ function updateWindow(): void {
75
76
  updateHeader();
76
77
  if (
77
78
  manager.currentViewshed.value &&
@@ -115,7 +116,7 @@ export function setupViewshedWindow(manager, app, collectionComponent) {
115
116
  });
116
117
 
117
118
  return {
118
- destroy() {
119
+ destroy(): void {
119
120
  app.windowManager.remove(windowId);
120
121
  viewshedListener();
121
122
  viewshedModeListener();