Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In an attempt to retrieve all features (point geometry) that fall in a selected polygon, I get the error this.layer.addFeatures is not a function. My code is as shown below:

function createWFSVector(map, WFS_HOST) {
var population = new OpenLayers.Layer.Vector("Population Vector", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.WFS({
        version: "1.1.0",
        url: WFS_HOST,
        featureType: "population_layer",
        featureNS: "pe_ns",
        srsName: "EPSG:4326"
    })
});

addMapControls(map, population);
map.addLayers([population]);
}

function addMapControls(map, wfsLayer) {
var select = new OpenLayers.Control.SelectFeature([wfsLayer], {
    box: true,
    multiple: true,
    onSelect: addSelected,
    onUnselect: clearSelected
});
map.addControl(select);
map.addControl(new OpenLayers.Control.EditingToolbar(select));
select.activate();
}

function addSelected(feature) {
selectedFeatures.push(feature);
}

function clearSelected(feature) {
selectedFeatures = [];
}

I can't seem to spot the problem with my code. Any assistance will be appreciated.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You've made mistake: new OpenLayers.Control.EditingToolbar(select) should be new OpenLayers.Control.EditingToolbar(wfsLayer) in your case.

share|improve this answer
    
You are right. Its not generating the error now. Now I'll have to try the other aspects; whether it actually retrieves the feature. –  okello Jul 7 '12 at 17:00
    
Please accept an answer if it was helpful. –  drnextgis Jul 7 '12 at 17:04
    
I had to confirm that it works. And, sorry it took me a while to do that. Thanks loads. It was helpful. –  okello Jul 9 '12 at 5:47

try to take out select and population from addMapControls and createWFSVector function respectively. and try this code:

var select = new OpenLayers.Control.SelectFeature(population, {
    box: true,
    clickout: false,
    hover: false,
    multiple: false,
    onSelect: function(f){
         var sltedFeature = population.selectedFeatures;
         alert(sltedFeature.length)       
                          },
    onUnselect: clearSelected
});
map.addControl(select);
map.addControl(new OpenLayers.Control.EditingToolbar(select));
select.activate();

i hope it helps you...

share|improve this answer
    
Thanks. I've done this, but the problem still persists. Still working on it. I hope to land a solution soon. –  okello Jul 6 '12 at 13:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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