|
1 | 1 | import AbstractLayer from '@/api/layers/AbstractLayer.class'
|
2 | 2 | import ExternalGroupOfLayers from '@/api/layers/ExternalGroupOfLayers.class'
|
3 | 3 | import LayerTypes from '@/api/layers/LayerTypes.enum'
|
| 4 | +import { getKmlExtent, getKmlExtentForProjection, parseKmlName } from '@/utils/kmlUtils' |
4 | 5 | import { ActiveLayerConfig } from '@/utils/layerUtils'
|
5 | 6 | import log from '@/utils/logging'
|
6 | 7 |
|
@@ -429,6 +430,48 @@ const actions = {
|
429 | 430 | clearPreviewYear({ commit }) {
|
430 | 431 | commit('setPreviewYear', null)
|
431 | 432 | },
|
| 433 | + setLayerErrorKey({ commit, getters }, payload) { |
| 434 | + const { layerId, errorKey } = payload |
| 435 | + const currentLayer = getters.getActiveLayerById(layerId) |
| 436 | + if (!currentLayer) { |
| 437 | + throw new Error( |
| 438 | + `Failed to update layer error key "${layerId}", layer not found in active layers` |
| 439 | + ) |
| 440 | + } |
| 441 | + const updatedLayer = currentLayer.clone() |
| 442 | + updatedLayer.errorKey = errorKey |
| 443 | + updatedLayer.hasError = !!errorKey |
| 444 | + commit('updateLayer', updatedLayer) |
| 445 | + }, |
| 446 | + updateKmlLayer({ commit, getters, rootState }, payload) { |
| 447 | + const { layerId, kmlData, kmlMetadata } = payload |
| 448 | + const currentLayer = getters.getActiveLayerById(layerId) |
| 449 | + if (!currentLayer) { |
| 450 | + throw new Error( |
| 451 | + `Failed to update KML layer data/metadata "${layerId}", ` + |
| 452 | + `layer not found in active layers` |
| 453 | + ) |
| 454 | + } |
| 455 | + const updatedLayer = currentLayer.clone() |
| 456 | + |
| 457 | + if (kmlData) { |
| 458 | + updatedLayer.name = parseKmlName(kmlData) || 'KML' |
| 459 | + updatedLayer.kmlData = kmlData |
| 460 | + updatedLayer.isLoading = false |
| 461 | + const extent = getKmlExtent(kmlData) |
| 462 | + if (!extent) { |
| 463 | + updatedLayer.errorKey = 'kml_gpx_file_empty' |
| 464 | + updatedLayer.hasError = true |
| 465 | + } else if (!getKmlExtentForProjection(rootState.position.projection, extent)) { |
| 466 | + updatedLayer.errorKey = 'kml_gpx_file_out_of_bounds' |
| 467 | + updatedLayer.hasError = true |
| 468 | + } |
| 469 | + } |
| 470 | + if (kmlMetadata) { |
| 471 | + updatedLayer.kmlMetadata = kmlMetadata |
| 472 | + } |
| 473 | + commit('updateLayer', updatedLayer) |
| 474 | + }, |
432 | 475 | }
|
433 | 476 |
|
434 | 477 | const mutations = {
|
|
0 commit comments