changeset 765:c1baaff348b0

client: add code to identify WFS features * Add demonstration code to the console that will print the identified vector features with their properties excluding the geometry.
author Bernhard Reiter <bernhard@intevation.de>
date Tue, 25 Sep 2018 16:25:42 +0200
parents a6a8fe89eb84
children afc635ab9f5b
files client/src/map/Maplayer.vue
diffstat 1 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/map/Maplayer.vue	Tue Sep 25 15:23:15 2018 +0200
+++ b/client/src/map/Maplayer.vue	Tue Sep 25 16:25:42 2018 +0200
@@ -181,18 +181,28 @@
     activateIdentifyMode() {
       this.openLayersMap.on("singleclick", event => {
         // console.log("single click on map:", event);
-        this.identify(
-          event.coordinate,
-          this.getLayerByName("Inland ECDIS chart Danube").data.getSource()
-        );
+        this.identify(event.coordinate, event.pixel);
       });
     },
-    identify(coordinate, wmsSource) {
-      // console.log(coordinate, wmsSource);
-      //var viewResolution = this.openLayersMap.view.getResolution();
+    identify(coordinate, pixel) {
+      // checking our WFS layers
+      var features = this.openLayersMap.getFeaturesAtPixel(pixel);
+      for (let feature of features) {
+        console.log("Identified:", feature.getId());
+        for (let key of feature.getKeys()) {
+          if (key != feature.getGeometryName()) {
+            console.log(key, feature.get(key));
+          }
+        }
+      }
+
+      // trying the GetFeatureInfo way for WMS
+      var wmsSource = this.getLayerByName(
+        "Inland ECDIS chart Danube"
+      ).data.getSource();
       var url = wmsSource.getGetFeatureInfoUrl(
         coordinate,
-        100,
+        100 /* resolution */,
         "EPSG:3857",
         // { INFO_FORMAT: "application/vnd.ogc.gml" } // not allowed by d4d
         { INFO_FORMAT: "text/plain" }
@@ -200,7 +210,7 @@
 
       if (url) {
         // cannot directly query here because of SOP
-        console.log(url);
+        console.log("GetFeatureInfo url:", url);
       }
     },
     buildVectorLoader(featureRequestOptions, endpoint, vectorSource) {