2

I created in OL3 selector elements new.ol.interacion.Select () on a WFS layer, and when I try to take these features returns an empty array.

My intention is to create a json with the selection check the map features.

This is my code:

  var Urbana_source = new ol.source.Vector({
   format: new ol.format.GeoJSON(),
   url: function(extent, resolution, projection) {
       return 'http://localhost:8080/geoserver/wfs?service=WFS&' +
    'version=1.1.0&request=GetFeature&typename=pucol:Urbana&' +
    'outputFormat=application/json&srsname=EPSG:3857&' +
    'bbox=' + extent.join(',') + ',EPSG:3857';
      },
     strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
     maxZoom: 19
     }))

     });

 var urbana_wfs = new ol.layer.Vector({
 source: Urbana_source,
 style: new ol.style.Style({

  stroke: new ol.style.Stroke({
   color: 'rgba(0, 0, 0, 0)',
   width: 2
   })
 })
});
 urbana_wfs.set('name', 'urbana');

select = new ol.interaction.Select({
        condition: ol.events.condition.click
    });
map.addInteraction(select);
//var feature_buff = select.getFeatures();
select.getFeatures().on('change:length', function(e)
{   
    var feature_buff = select.getFeatures();



    var geojson  = new ol.format.GeoJSON();
    var  json    = geojson.writeFeatures(feature_buff);

    });

and image enter image description here

0

I am not sure but I think I had some kind of this problem. Instead of using writeFeatures, iterate through your features and use the writeFeature method.

try something like this:

select.getFeatures().on('change:length', function(e)
{   
    var feature_buff = select.getFeatures();
    var geojson  = new ol.format.GeoJSON();
    var  json    = new ol.Collection();
    for (var i=0;i<feature_buff.getLength();i++){
    json.push(geojson.writeFeature(feature_buff.item(i)))
    }

    });

/// ORIGINAL AUTHOR POST

Still not working, thanks anyway : enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.