Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);

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

function addSelected(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
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;
    onUnselect: clearSelected
map.addControl(new OpenLayers.Control.EditingToolbar(select));

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


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.