From ec296e19a8f2bb99c3f5f1a8cd56db72ff9cc924 Mon Sep 17 00:00:00 2001 From: Brice Schaffner Date: Tue, 6 Aug 2024 10:08:37 +0200 Subject: [PATCH 1/4] Corrected docu and removed unused functions --- src/store/modules/features.store.js | 4 +- src/utils/identifyOnVectorLayer.js | 73 ----------------------------- 2 files changed, 2 insertions(+), 75 deletions(-) diff --git a/src/store/modules/features.store.js b/src/store/modules/features.store.js index 9b9c0309e..b467c39f8 100644 --- a/src/store/modules/features.store.js +++ b/src/store/modules/features.store.js @@ -157,9 +157,9 @@ export default { * have a LineString or Polygon feature */ profileFeature: null, - /** @type {ElevationProfile | null} Profile Data for the profile geometry */ + /** @type {LayerFeature | null} Profile Data for the profile geometry */ profileData: null, - /** @type {ProfileError | null} */ + /** @type {ElevationProfile | null} */ profileRequestError: null, }, getters: { diff --git a/src/utils/identifyOnVectorLayer.js b/src/utils/identifyOnVectorLayer.js index 9e770356e..15cb098b2 100644 --- a/src/utils/identifyOnVectorLayer.js +++ b/src/utils/identifyOnVectorLayer.js @@ -1,4 +1,3 @@ -import { gpx as gpxToGeoJSON, kml as kmlToGeoJSON } from '@mapbox/togeojson' import booleanPointInPolygon from '@turf/boolean-point-in-polygon' import distance from '@turf/distance' import { point } from '@turf/helpers' @@ -129,75 +128,3 @@ export function identifyGeoJSONFeatureAt(geoJsonLayer, coordinate, projection, r } ) } - -/** - * Finds and returns all features, from the given KML layer, that are under or close to the given - * coordinate (we require the map resolution as input, so that we may calculate a 10-pixels - * tolerance for feature identification) - * - * This means we do not require OpenLayers to perform this search anymore, and that this code can be - * used in any mapping framework. - * - * @param {KMLLayer} kmlLayer The KML layer in which we want to find feature at the given - * coordinate. This layer must have its kmlData loaded in order for this identification of feature - * to work properly (this function will not load the data if it is missing) - * @param {[Number, Number]} coordinate Where we want to find features ([x, y]) - * @param {CoordinateSystem} projection The projection used to describe the coordinate where we want - * to search for feature - * @param {Number} resolution The current map resolution, in meters/pixel. Used to calculate a - * tolerance of 10 pixels around the given coordinate. - * @returns {SelectableFeature[]} The feature found at the coordinate, or an empty array if none - * were found - */ -export function identifyKMLFeatureAt(kmlLayer, coordinate, projection, resolution) { - if (kmlLayer?.kmlData) { - const parseKml = new DOMParser().parseFromString(kmlLayer.kmlData, 'text/xml') - const convertedKml = kmlToGeoJSON(parseKml) - return identifyInGeoJson(convertedKml, coordinate, projection, resolution).map( - (feature) => { - return new LayerFeature({ - layer: kmlLayer, - id: feature.id, - name: kmlLayer.name, - data: { - title: feature.properties.name, - description: feature.properties.description, - }, - coordinates: reprojectCoordinates(feature.geometry.coordinates, projection), - geometry: reproject(feature.geometry, WGS84.epsg, projection.epsg), - }) - } - ) - } - return [] -} - -/** - * @param {GPXLayer} gpxLayer - * @param {[Number, Number]} coordinate Where we want to find features ([x, y]) - * @param {CoordinateSystem} projection The projection used to describe the coordinate where we want - * to search for feature - * @param {Number} resolution The current map resolution, in meters/pixel. Used to calculate a - * tolerance of 10 pixels around the given coordinate. - * @returns {SelectableFeature[]} The feature found at the coordinate, or an empty array if none - * were found - */ -export function identifyGPXFeatureAt(gpxLayer, coordinate, projection, resolution) { - if (gpxLayer?.gpxData) { - const parseGpx = new DOMParser().parseFromString(gpxLayer.gpxData, 'text/xml') - const convertedGpx = gpxToGeoJSON(parseGpx) - return identifyInGeoJson(convertedGpx, coordinate, projection, resolution).map( - (feature) => { - return new LayerFeature({ - layer: gpxLayer, - id: `${gpxLayer.name}-${feature.properties?.name}`, - name: feature.properties?.name, - data: { ...feature.properties }, - coordinates: reprojectCoordinates(feature.geometry.coordinates, projection), - geometry: reproject(feature.geometry, WGS84.epsg, projection.epsg), - }) - } - ) - } - return [] -} From 521e4b8e94eba391db661719cbf847b1126249f4 Mon Sep 17 00:00:00 2001 From: Brice Schaffner Date: Tue, 6 Aug 2024 10:22:54 +0200 Subject: [PATCH 2/4] Fix crash on left click on the 3D map When clicking on the left click on 3D on the map, the application crashed because the identifyGeoJSONFeatureAt function expected an array for the coordinate but got an object. --- src/modules/map/components/cesium/CesiumMap.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/map/components/cesium/CesiumMap.vue b/src/modules/map/components/cesium/CesiumMap.vue index 5937b19a7..335afbb2d 100644 --- a/src/modules/map/components/cesium/CesiumMap.vue +++ b/src/modules/map/components/cesium/CesiumMap.vue @@ -559,7 +559,7 @@ export default { features.push( ...identifyGeoJSONFeatureAt( geoJSonLayer, - event.position, + [event.position.x, event.position.y], this.projection, this.resolution ) From fa7945af1fdc6729847f559acead8d18fd992045 Mon Sep 17 00:00:00 2001 From: Brice Schaffner Date: Tue, 6 Aug 2024 10:26:44 +0200 Subject: [PATCH 3/4] PB-866: Fix undefined profile name for GPX track When displaying a GPX track, its title in the profile was undefined. This was due to the fact that GPX on a ol feature seems to have no ID, but have a name. --- .../openlayers/utils/useMapInteractions.composable.js | 2 ++ src/utils/identifyOnVectorLayer.js | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/map/components/openlayers/utils/useMapInteractions.composable.js b/src/modules/map/components/openlayers/utils/useMapInteractions.composable.js index 8baed9122..e79e49b70 100644 --- a/src/modules/map/components/openlayers/utils/useMapInteractions.composable.js +++ b/src/modules/map/components/openlayers/utils/useMapInteractions.composable.js @@ -143,6 +143,8 @@ export default function useMapInteractions(map) { // - ch.meteoschweiz.messwerte-niederschlag-10min // - ch.meteoschweiz.messwerte-lufttemperatur-10min olFeature.get('station_name') ?? + // GPX track feature don't have an ID but have a name ! + olFeature.get('name') ?? olFeature.getId(), data: { title: olFeature.get('name'), diff --git a/src/utils/identifyOnVectorLayer.js b/src/utils/identifyOnVectorLayer.js index 15cb098b2..c993385bf 100644 --- a/src/utils/identifyOnVectorLayer.js +++ b/src/utils/identifyOnVectorLayer.js @@ -117,7 +117,12 @@ export function identifyGeoJSONFeatureAt(geoJsonLayer, coordinate, projection, r // some of their layers are // - ch.meteoschweiz.messwerte-niederschlag-10min // - ch.meteoschweiz.messwerte-lufttemperatur-10min - name: feature.properties.station_name ?? feature.properties.label ?? feature.id, + name: + feature.properties.label ?? + feature.properties.station_name ?? + // GPX track feature don't have an ID but have a name ! + feature.properties.name ?? + feature.id, data: { title: feature.properties.name, description: feature.properties.description, From 4b8f4b9cf66e8ad8d468f9d5e7848aa910cd3c53 Mon Sep 17 00:00:00 2001 From: Brice Schaffner Date: Wed, 7 Aug 2024 09:15:23 +0200 Subject: [PATCH 4/4] Fix docuwq --- src/store/modules/features.store.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/modules/features.store.js b/src/store/modules/features.store.js index b467c39f8..9b9c0309e 100644 --- a/src/store/modules/features.store.js +++ b/src/store/modules/features.store.js @@ -157,9 +157,9 @@ export default { * have a LineString or Polygon feature */ profileFeature: null, - /** @type {LayerFeature | null} Profile Data for the profile geometry */ + /** @type {ElevationProfile | null} Profile Data for the profile geometry */ profileData: null, - /** @type {ElevationProfile | null} */ + /** @type {ProfileError | null} */ profileRequestError: null, }, getters: {