@vcmap/viewshed 3.0.2 → 3.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcmap/viewshed",
3
- "version": "3.0.2",
3
+ "version": "3.0.5",
4
4
  "description": "Tool to simulate a \"viewer\" and their field of vision from a certain standpoint in the map. It allows the user to see which areas and buildings can or can't be seen from a specific standpoint, regarding different viewing distances, viewers' sizes and orientations.Th",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -48,8 +48,8 @@
48
48
  "prettier": "@vcsuite/eslint-config/prettier.js",
49
49
  "peerDependencies": {
50
50
  "@vcmap-cesium/engine": "^11.0.2",
51
- "@vcmap/core": "^6.0.0",
52
- "@vcmap/ui": "^6.0.2",
51
+ "@vcmap/core": "^6.0.4",
52
+ "@vcmap/ui": "^6.0.6",
53
53
  "ol": "^10.2.1",
54
54
  "vue": "~3.4.38",
55
55
  "vuetify": "^3.7.3"
@@ -57,11 +57,11 @@
57
57
  "devDependencies": {
58
58
  "@vcmap/plugin-cli": "^4.0.1",
59
59
  "@vcsuite/eslint-config": "^3.0.8",
60
- "@vitest/coverage-v8": "^2.1.3",
60
+ "@vitest/coverage-v8": "^2.1.4",
61
61
  "jest-canvas-mock": "^2.5.2",
62
62
  "jsdom": "^22.1.0",
63
63
  "resize-observer-polyfill": "^1.5.1",
64
- "vitest": "^2.1.3"
64
+ "vitest": "^2.1.4"
65
65
  },
66
66
  "dependencies": {
67
67
  "@vcsuite/check": "^2.1.0",
package/src/index.js CHANGED
@@ -74,9 +74,6 @@ export default function plugin(config) {
74
74
  const { activeMap } = vcsUiApp.maps;
75
75
  function activateCachedViewshed(map) {
76
76
  if (state?.m && state.cv && map instanceof CesiumMap) {
77
- if (state.cv.properties.title) {
78
- delete state.cv.properties.title;
79
- }
80
77
  const activeViewshed = new Viewshed(state.cv);
81
78
  if (state.m === ViewshedPluginModes.VIEW) {
82
79
  viewshedManager.viewViewshed(activeViewshed);
@@ -141,9 +138,10 @@ export default function plugin(config) {
141
138
  },
142
139
  /**
143
140
  * should return the plugins state
141
+ * @param {boolean} forUrl
144
142
  * @returns {ViewshedPluginState}
145
143
  */
146
- getState() {
144
+ getState(forUrl) {
147
145
  const state = {};
148
146
  const mode = viewshedManager.mode.value;
149
147
  const currentViewshed = viewshedManager.currentViewshed.value?.toJSON();
@@ -151,6 +149,13 @@ export default function plugin(config) {
151
149
  if (mode !== null && mode !== 'create' && currentViewshed) {
152
150
  state.m = mode;
153
151
  state.cv = currentViewshed;
152
+ if (forUrl && state.cv.properties?.title) {
153
+ if (Object.keys(state.properties).length === 1) {
154
+ delete state.cv.properties;
155
+ } else {
156
+ delete state.cv.properties.title;
157
+ }
158
+ }
154
159
  }
155
160
 
156
161
  return state;
@@ -21,52 +21,95 @@ import { ViewshedPluginModes } from '../viewshedManager.js';
21
21
  * @returns {ViewshedToolbox} A select toolbox with buttons to create 360 and cone viewshed.
22
22
  */
23
23
  function createViewshedToolbox(app, manager, name, tools) {
24
- const toolbox = {
25
- type: ToolboxType.SELECT,
26
- action: reactive({
27
- name,
28
- currentIndex: 0,
29
- active: false,
30
- background: false,
31
- disabled: !(app.maps.activeMap instanceof CesiumMap),
32
- callback() {
33
- if (this.active) {
34
- if (this.background && manager.currentViewshed.value) {
35
- manager.editViewshed(manager.currentViewshed.value);
24
+ /**
25
+ * @param {string} tool The tool to create.
26
+ * @returns {{name:ViewshedTypes, icon:string, title:string, } | undefined} A tool object.
27
+ */
28
+ function parseTool(tool) {
29
+ if (tool === ViewshedTypes.CONE) {
30
+ return {
31
+ name: ViewshedTypes.CONE,
32
+ icon: ViewshedIcons[ViewshedTypes.CONE],
33
+ title: `viewshed.create.${ViewshedTypes.CONE}`,
34
+ };
35
+ } else if (tool === ViewshedTypes.THREESIXTY) {
36
+ return {
37
+ name: ViewshedTypes.THREESIXTY,
38
+ icon: ViewshedIcons[ViewshedTypes.THREESIXTY],
39
+ title: `viewshed.create.${ViewshedTypes.THREESIXTY}`,
40
+ };
41
+ } else {
42
+ return undefined;
43
+ }
44
+ }
45
+
46
+ let toolbox;
47
+ let currentViewshedWatcher;
48
+ if (tools.length === 1) {
49
+ const tool = parseTool(tools[0]);
50
+ toolbox = {
51
+ type: ToolboxType.SINGLE,
52
+ action: reactive({
53
+ ...tool,
54
+ active: false,
55
+ background: false,
56
+ disabled: !(app.maps.activeMap instanceof CesiumMap),
57
+ callback() {
58
+ if (this.active) {
59
+ if (this.background && manager.currentViewshed.value) {
60
+ manager.editViewshed(manager.currentViewshed.value);
61
+ } else {
62
+ manager.stop();
63
+ }
64
+ } else {
65
+ manager.createViewshed(tool.name);
66
+ }
67
+ },
68
+ }),
69
+ };
70
+ } else {
71
+ toolbox = {
72
+ type: ToolboxType.SELECT,
73
+ action: reactive({
74
+ name,
75
+ currentIndex: 0,
76
+ active: false,
77
+ background: false,
78
+ disabled: !(app.maps.activeMap instanceof CesiumMap),
79
+ callback() {
80
+ if (this.active) {
81
+ if (this.background && manager.currentViewshed.value) {
82
+ manager.editViewshed(manager.currentViewshed.value);
83
+ } else {
84
+ manager.stop();
85
+ }
36
86
  } else {
37
- manager.stop();
87
+ const toolName = this.tools[this.currentIndex].name;
88
+ manager.createViewshed(toolName);
89
+ }
90
+ },
91
+ selected(newIndex) {
92
+ if (newIndex !== this.currentIndex) {
93
+ this.currentIndex = newIndex;
38
94
  }
39
- } else {
40
95
  const toolName = this.tools[this.currentIndex].name;
41
96
  manager.createViewshed(toolName);
97
+ },
98
+ tools: tools.flatMap(parseTool),
99
+ }),
100
+ };
101
+
102
+ currentViewshedWatcher = watch(
103
+ manager.currentViewshed,
104
+ (currentViewshed) => {
105
+ if (currentViewshed) {
106
+ toolbox.action.currentIndex = toolbox.action.tools.findIndex(
107
+ (tool) => tool.name === currentViewshed.type,
108
+ );
42
109
  }
43
110
  },
44
- selected(newIndex) {
45
- if (newIndex !== this.currentIndex) {
46
- this.currentIndex = newIndex;
47
- }
48
- const toolName = this.tools[this.currentIndex].name;
49
- manager.createViewshed(toolName);
50
- },
51
- tools: tools.flatMap((tool) => {
52
- if (tool === ViewshedTypes.CONE) {
53
- return {
54
- name: ViewshedTypes.CONE,
55
- icon: ViewshedIcons[ViewshedTypes.CONE],
56
- title: `viewshed.create.${ViewshedTypes.CONE}`,
57
- };
58
- } else if (tool === ViewshedTypes.THREESIXTY) {
59
- return {
60
- name: ViewshedTypes.THREESIXTY,
61
- icon: ViewshedIcons[ViewshedTypes.THREESIXTY],
62
- title: `viewshed.create.${ViewshedTypes.THREESIXTY}`,
63
- };
64
- } else {
65
- return [];
66
- }
67
- }),
68
- }),
69
- };
111
+ );
112
+ }
70
113
 
71
114
  const viewshedModeWatcher = watch(manager.mode, (mode) => {
72
115
  if (mode === ViewshedPluginModes.VIEW) {
@@ -81,17 +124,6 @@ function createViewshedToolbox(app, manager, name, tools) {
81
124
  }
82
125
  });
83
126
 
84
- const currentViewshedWatcher = watch(
85
- manager.currentViewshed,
86
- (currentViewshed) => {
87
- if (currentViewshed) {
88
- toolbox.action.currentIndex = toolbox.action.tools.findIndex(
89
- (tool) => tool.name === currentViewshed.type,
90
- );
91
- }
92
- },
93
- );
94
-
95
127
  const mapChangedListener = app.maps.mapActivated.addEventListener((map) => {
96
128
  if (map instanceof CesiumMap) {
97
129
  toolbox.action.disabled = false;
@@ -103,7 +135,7 @@ function createViewshedToolbox(app, manager, name, tools) {
103
135
  return {
104
136
  destroy() {
105
137
  viewshedModeWatcher();
106
- currentViewshedWatcher();
138
+ currentViewshedWatcher?.();
107
139
  mapChangedListener();
108
140
  },
109
141
  toolbox,
@@ -24,6 +24,7 @@ import ViewshedInteraction from './viewshedInteraction.js';
24
24
  * @property {import("vue").ShallowRef<import("./viewshed.js").default | null>} currentViewshed The current viewshed, that is displayed in the map.
25
25
  * @property {import("vue").Ref<null | boolean>} currentIsPersisted Whether current viewshed is persisted or not.
26
26
  * @property {import("vue").Ref<import("@vcmap/core").EditFeaturesSession | import("@vcmap/core").EditGeometrySession | null>} currentEditSession The current edit session, when in MOVE mode. Read only.
27
+ * @property {import("vue").ShallowRef<import("ol").Feature[]>} currentFeatures The feature that is created for feature/geometry editing in {@link moveCurrentViewshed}. Needed to match the EditorManager API from the UI.
27
28
  * @property {function(import("./viewshed.js").ViewshedTypes): void} createViewshed Creates a new viewshed and stops a running create process.
28
29
  * @property {function(import("./viewshed.js").default):void} viewViewshed Changes mode to VIEW for passed Viewshed.
29
30
  * @property {function(import("./viewshed.js").default):void} editViewshed Changes mode to EDIT for passed Viewshed.
@@ -129,6 +130,11 @@ export default function createViewshedManager(app, config, categoryHelper) {
129
130
  let removeInteraction = () => {};
130
131
  /** @type {import("vue").Ref<import("@vcmap/core").EditFeaturesSession | import("@vcmap/core").EditGeometrySession | null>} */
131
132
  const currentEditSession = shallowRef(null);
133
+ /**
134
+ * The feature that is created for feature/geometry editing in {@link moveCurrentViewshed}. Needed to match the EditorManager API from the UI.
135
+ * @type {import("vue").ShallowRef<import("ol").Feature[]>}
136
+ */
137
+ const currentFeatures = shallowRef([]);
132
138
 
133
139
  let shadowMapChangedListener = () => {};
134
140
 
@@ -242,6 +248,8 @@ export default function createViewshedManager(app, config, categoryHelper) {
242
248
  } = createLayerWithFeature(currentViewshed.value.position);
243
249
  app.layers.add(layer);
244
250
 
251
+ currentFeatures.value = [feature];
252
+
245
253
  if (heightMode.value === HeightModes.ABSOLUTE) {
246
254
  currentEditSession.value = startEditFeaturesSession(app, layer);
247
255
  currentEditSession.value.setFeatures([feature]);
@@ -276,6 +284,7 @@ export default function createViewshedManager(app, config, categoryHelper) {
276
284
  }
277
285
  currentEditSession.value?.stop();
278
286
  currentEditSession.value = null;
287
+ currentFeatures.value = [];
279
288
  app.layers.remove(layer);
280
289
  destroyLayerWithFeature();
281
290
  mode.value = ViewshedPluginModes.EDIT;
@@ -382,6 +391,7 @@ export default function createViewshedManager(app, config, categoryHelper) {
382
391
  currentViewshed,
383
392
  currentIsPersisted,
384
393
  currentEditSession,
394
+ currentFeatures,
385
395
  createViewshed,
386
396
  viewViewshed(viewshed) {
387
397
  changeMode(ViewshedPluginModes.VIEW, viewshed);