@vcmap/viewshed 2.0.8 → 2.0.9

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": "2.0.8",
3
+ "version": "2.0.9",
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": "^4.0.3",
51
- "@vcmap/core": "^5.1.0",
52
- "@vcmap/ui": "^5.1.0",
51
+ "@vcmap/core": "^5.1.4",
52
+ "@vcmap/ui": "^5.1.5",
53
53
  "ol": "^7.5.2",
54
54
  "vue": "~2.7.3",
55
55
  "vuetify": "~2.6.7"
@@ -5,6 +5,7 @@ import {
5
5
  createListImportAction,
6
6
  createSupportedMapMappingFunction,
7
7
  downloadText,
8
+ NotificationType,
8
9
  } from '@vcmap/ui';
9
10
  import { name } from '../package.json';
10
11
  import Viewshed from './viewshed.js';
@@ -142,16 +143,52 @@ export async function createCategory(app) {
142
143
  const { action: importAction, destroy: destroyImportAction } =
143
144
  createListImportAction(
144
145
  async (files) => {
145
- await Promise.all(
146
+ const { vueI18n } = app;
147
+ const results = await Promise.all(
146
148
  files.map(async (file) => {
147
149
  const text = await file.text();
148
- const viewshedOptions = JSON.parse(text);
149
- viewshedOptions.forEach((options) => {
150
- const viewshed = new Viewshed(options);
151
- category.collection.add(viewshed);
152
- });
150
+ try {
151
+ const parsedOptions = JSON.parse(text);
152
+ return parsedOptions.map((options) => new Viewshed(options));
153
+ } catch (e) {
154
+ app.notifier.add({
155
+ type: NotificationType.ERROR,
156
+ message: vueI18n.t('components.import.failure', {
157
+ fileName: file.name,
158
+ }),
159
+ });
160
+ }
161
+ return [];
153
162
  }),
154
163
  );
164
+
165
+ const viewshedsToImport = results.flat();
166
+ const imported = viewshedsToImport
167
+ .map((v) => category.collection.add(v))
168
+ .filter((id) => id != null);
169
+ const importedDelta = viewshedsToImport.length - imported.length;
170
+ if (importedDelta > 0) {
171
+ app.notifier.add({
172
+ type: NotificationType.WARNING,
173
+ message: vueI18n.t('components.import.addFailure', [importedDelta]),
174
+ });
175
+ return false;
176
+ }
177
+ if (imported.length > 0) {
178
+ app.notifier.add({
179
+ type: NotificationType.SUCCESS,
180
+ message: vueI18n.t('components.import.featuresAdded', [
181
+ imported.length,
182
+ ]),
183
+ });
184
+ } else {
185
+ app.notifier.add({
186
+ type: NotificationType.ERROR,
187
+ message: vueI18n.t('components.import.nothingAdded'),
188
+ });
189
+ return false;
190
+ }
191
+ return true;
155
192
  },
156
193
  app.windowManager,
157
194
  name,