0

I have 2 WFS layer using openlayer 5 API. I am filtering 1st layer by ID so that one polygon is highlighted now I want to highlight all polygons which comes under the filtered polygon from 1st layer.

My code is here:

layerCadWFS = new ol.layer.Vector({
         title: 'Filtered Index Layer',
          visible: true,
          source: new ol.source.Vector({
            loader: function(extent) {
              $.ajax('http://localhost:8080/geoserver/wfs', {
                type: 'GET',
                data: {
                  service: 'WFS',
                  version: '1.1.0',
                  request: 'GetFeature',
                  typename: 'web_export:VILLAGE_BOUNADR_INDEX_1',

                  srsname: 'EPSG:3857',
                  bbox: extent.join(',') + ',EPSG:3857'
                }
              }).done(function(response) {

                var features = new ol.format.WFS().readFeatures(response);


                features = features.filter(function (feature) {
                  return feature.get('VILLAGE') == village && feature.get('INDEX_ID') == map_index_id  ;
                });


                layerCadWFS.getSource().addFeatures(features);
              });
            },
            strategy: ol.loadingstrategy.all,
            projection: 'EPSG:3857'
          }),
           style: new ol.style.Style({
                                  stroke: new ol.style.Stroke({
                                    color: 'aqua',
                                    width: 2
                                  }),
                                   opacity: 1, 
                                })
        }); 

            map.addLayer(layerCadWFS);

Now whatever polygons come within filtered polygon are needed to highlight. How to do that?

  • OpenLayers doesn't support testing intersections of two geometries (only intersection of geometries with points and extents) but third party libraries such as turf support it. See this demo where you draw a polygon over other polygons bl.ocks.org/pgiraud/7ac6155abed975ebf4b3 (instead of highlighting the features the intersections are shown in a third layer). This is the API call used turfjs.org/docs/#intersect – Mike Apr 24 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.