# HG changeset patch # User Markus Kottlaender # Date 1557328217 -7200 # Node ID 1253fe15e3e30f574335e087037b4177d83aabc6 # Parent cb67ee72485b9a0e7937e5df6f568acf9d42e3e4 client: identify: implemented popup when clicking the map and the intention is not clear... ...because multiple features were identified. In that case no dialog will be opened automatically but a popup with possible options is shown. diff -r cb67ee72485b -r 1253fe15e3e3 client/src/components/App.vue --- a/client/src/components/App.vue Wed May 08 16:19:31 2019 +0200 +++ b/client/src/components/App.vue Wed May 08 17:10:17 2019 +0200 @@ -23,6 +23,7 @@ + @@ -101,7 +102,8 @@ Contextbox: () => import("./Contextbox"), Toolbar: () => import("./toolbar/Toolbar"), Popup: () => import("./Popup"), - Statistics: () => import("./Statistics") + Statistics: () => import("./Statistics"), + MapPopup: () => import("./map/MapPopup") } }; diff -r cb67ee72485b -r 1253fe15e3e3 client/src/components/Bottlenecks.vue --- a/client/src/components/Bottlenecks.vue Wed May 08 16:19:31 2019 +0200 +++ b/client/src/components/Bottlenecks.vue Wed May 08 17:10:17 2019 +0200 @@ -156,9 +156,6 @@ bottleneck.properties.name ) .then(() => { - this.$store.commit("bottlenecks/setFirstSurveySelected"); - }) - .then(() => { this.$store.dispatch("map/moveToFeauture", { feature: bottleneck, zoom: 17, diff -r cb67ee72485b -r 1253fe15e3e3 client/src/components/fairway/Profiles.vue --- a/client/src/components/fairway/Profiles.vue Wed May 08 16:19:31 2019 +0200 +++ b/client/src/components/fairway/Profiles.vue Wed May 08 17:10:17 2019 +0200 @@ -342,11 +342,7 @@ return this.$store.state.bottlenecks.selectedBottleneck; }, set(name) { - this.$store - .dispatch("bottlenecks/setSelectedBottleneck", name) - .then(() => { - this.$store.commit("bottlenecks/setFirstSurveySelected"); - }); + this.$store.dispatch("bottlenecks/setSelectedBottleneck", name); } }, selectedWaterLevel: { diff -r cb67ee72485b -r 1253fe15e3e3 client/src/components/map/MapPopup.vue --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/src/components/map/MapPopup.vue Wed May 08 17:10:17 2019 +0200 @@ -0,0 +1,243 @@ + + + + + diff -r cb67ee72485b -r 1253fe15e3e3 client/src/store/bottlenecks.js --- a/client/src/store/bottlenecks.js Wed May 08 16:19:31 2019 +0200 +++ b/client/src/store/bottlenecks.js Wed May 08 17:10:17 2019 +0200 @@ -73,9 +73,6 @@ .clear(); }); } - if (name) { - commit("application/showProfiles", true, { root: true }); - } commit("setSelectedBottleneck", name); if (name) { commit("surveysLoading", true); @@ -90,6 +87,7 @@ a.date_info < b.date_info ? 1 : -1 ); commit("setSurveys", surveys); + commit("setFirstSurveySelected"); resolve(response); }) .catch(error => { diff -r cb67ee72485b -r 1253fe15e3e3 client/src/store/map.js --- a/client/src/store/map.js Wed May 08 16:19:31 2019 +0200 +++ b/client/src/store/map.js Wed May 08 17:10:17 2019 +0200 @@ -18,13 +18,13 @@ import { Stroke, Style, Fill, Circle } from "ol/style"; import { fromLonLat } from "ol/proj"; import { getLength, getArea } from "ol/sphere"; -import { getCenter } from "ol/extent"; import { transformExtent } from "ol/proj"; import bbox from "@turf/bbox"; import app from "@/main"; import { HTTP } from "@/lib/http"; import Feature from "ol/Feature"; import Point from "ol/geom/Point"; +import { toLonLat } from "ol/proj"; // initial state const init = () => { @@ -32,6 +32,7 @@ openLayersMaps: [], syncedMaps: [], syncedView: null, + mapPopup: null, initialLoad: true, extent: { lat: 6155376, @@ -39,6 +40,7 @@ zoom: 11 }, identifiedFeatures: [], // map features identified by clicking on the map + identifiedCoordinates: null, currentMeasurement: null, // distance or area from line-/polygon-/cutTool lineToolEnabled: false, polygonToolEnabled: false, @@ -86,6 +88,9 @@ syncedView: (state, view) => { state.syncedView = view; }, + mapPopup: (state, popup) => { + state.mapPopup = popup; + }, setIdentifiedFeatures: (state, identifiedFeatures) => { state.identifiedFeatures = identifiedFeatures; }, @@ -94,6 +99,9 @@ identifiedFeatures ); }, + identifiedCoordinates: (state, coordinates) => { + state.identifiedCoordinates = coordinates; + }, setCurrentMeasurement: (state, measurement) => { state.currentMeasurement = measurement; }, @@ -286,6 +294,11 @@ }, initIdentifyTool({ state, rootState, commit, dispatch }, map) { map.on(["singleclick", "dblclick"], event => { + commit( + "identifiedCoordinates", + toLonLat(event.coordinate, map.getView().getProjection()) + ); + state.mapPopup.setPosition(undefined); if ( state.lineToolEnabled || state.polygonToolEnabled || @@ -296,93 +309,78 @@ // checking our WFS layers var features = map.getFeaturesAtPixel(event.pixel, { hitTolerance: 7 }); if (features) { - let identifiedFeatures = []; + let all = []; + let bottlenecks = []; + let gauges = []; + let stretches = []; + let sections = []; for (let feature of features) { + // avoid identifying the same feature twice + if (all.findIndex(f => f.getId() === feature.getId()) === -1) + all.push(feature); + let id = feature.getId(); - // avoid identifying the same feature twice - if ( - identifiedFeatures.findIndex( - f => f.getId() === feature.getId() - ) === -1 - ) { - identifiedFeatures.push(feature); - } - - // get selected bottleneck // RegExp.prototype.test() works with number, str and undefined - if (/^bottlenecks/.test(id)) { - if ( - rootState.bottlenecks.selectedBottleneck != - feature.get("objnam") - ) { - dispatch( - "bottlenecks/setSelectedBottleneck", - feature.get("objnam"), - { root: true } - ).then(() => { - this.commit("bottlenecks/setFirstSurveySelected"); - }); - dispatch("moveMap", { - coordinates: getCenter( - feature - .getGeometry() - .clone() - .transform("EPSG:3857", "EPSG:4326") - .getExtent() - ), - zoom: 17, - preventZoomOut: true - }); - } - } - + // get selected bottleneck + if (/^bottlenecks/.test(id)) bottlenecks.push(feature); // get selected gauge - if (/^gauges/.test(id)) { - if ( - rootState.gauges.selectedGaugeISRS !== feature.get("isrs_code") - ) { - dispatch("gauges/selectedGaugeISRS", feature.get("isrs_code"), { - root: true - }); - dispatch("moveMap", { - coordinates: getCenter( - feature - .getGeometry() - .clone() - .transform("EPSG:3857", "EPSG:4326") - .getExtent() - ), - zoom: 15, - preventZoomOut: true - }); - } - } + if (/^gauges/.test(id)) gauges.push(feature); + // get selected stretch + if (/^stretches/.test(id)) stretches.push(feature); + // get selected section + if (/^sections/.test(id)) sections.push(feature); + } + + commit("setIdentifiedFeatures", all); - // get selected stretch - if (/^stretches/.test(id)) { - if (rootState.imports.selectedStretchId === feature.getId()) { - commit("imports/selectedStretchId", null, { root: true }); - } else { - commit("imports/selectedStretchId", feature.getId(), { - root: true - }); - dispatch("moveMap", { - coordinates: getCenter( - feature - .getGeometry() - .clone() - .transform("EPSG:3857", "EPSG:4326") - .getExtent() - ), - zoom: null, - preventZoomOut: true - }); - } + // Decide whether we open a related dialog immediately or show the + // popup with possible options first. + // The following cases require a manual decision via the popup because + // the targeted feature is not clear. + if ( + bottlenecks.length || + gauges.length > 1 || + stretches.length > 1 || + sections.length > 1 || + (sections.length && stretches.length) || + (gauges.length && sections.length) || + (gauges.length && stretches.length) + ) { + state.mapPopup.setMap(map); + state.mapPopup.setPosition(event.coordinate); + } + // The following scenarios lead to a distinct action without popup. + if ( + gauges.length === 1 && + !bottlenecks.length && + !sections.length && + !stretches.length + ) { + commit("application/showGauges", true, { root: true }); + dispatch("gauges/selectedGaugeISRS", gauges[0].get("isrs_code"), { + root: true + }); + } + if ( + stretches.length === 1 && + !sections.length && + !bottlenecks.length && + !gauges.length + ) { + if (rootState.imports.selectedStretchId === stretches[0].getId()) { + commit("application/showStatistics", false, { root: true }); + commit("imports/selectedStretchId", null, { + root: true + }); + } else { + commit("application/showStatistics", true, { root: true }); + commit("imports/selectedStretchId", stretches[0].getId(), { + root: true + }); + dispatch("moveToFeauture", { feature: stretches[0], zoom: 17 }); } } - - commit("setIdentifiedFeatures", identifiedFeatures); } // DEBUG output and example how to remove the GeometryName @@ -531,7 +529,13 @@ }); }, moveToFeauture({ dispatch }, { feature, zoom, preventZoomOut }) { - const boundingBox = bbox(feature.geometry); + const boundingBox = feature.hasOwnProperty("geometry") + ? bbox(feature.geometry) + : feature + .getGeometry() + .clone() + .transform("EPSG:3857", "EPSG:4326") + .getExtent(); dispatch("moveToBoundingBox", { boundingBox, zoom, preventZoomOut }); }, moveMap({ state }, { coordinates, zoom, preventZoomOut }) {