3

I'm struggling to get my vector layer working. The wfs works as I have tested it by creating a wfs layer and adding it to the map, now I'm trying to display a vector layer with the results of a search but nothing is showing up. The results of the search appear in the gridpanel but not in the vector layer. Here is the code for the search:

var features = [];
var wfs = new OpenLayers.Layer.Vector("Search");
var select = new GeoExt.grid.FeatureSelectionModel();

var protocol = new OpenLayers.Protocol.WFS({
    url:  "http://localhost:8080/geoserver/wfs",
featureType: "location_points",
featureNS: "http://www.openplans.org/topp",
geometryName: "the_geom"
});


formPanel = new GeoExt.form.FormPanel({
title: "Species Search",
height: 150,
region: "north",
protocol: protocol,
items: [{
    xtype: "textfield",
    width: 200,
    name: "scientific__like",
    fieldLabel: "name",
    allowBlank: false,
    minLength: 4
}],
listeners: {
    actioncomplete: function(form, action) {
        features = action.response.features;
        store.loadData(features);
        vm=map.getLayersByName("Search");
        if(vm.length===0){
            wfs = new OpenLayers.Layer.Vector("Search");
            map.addLayers(wfs);
            store.bind(wfs);
            select.bind(wfs);
        }
    }
},
buttons: [{text: 'search',
    handler: function(){
        formPanel.search();
    }
}],
keys: [{ key: [Ext.EventObject.ENTER], 
    handler: function() {
        formPanel.search();
    }
}]
});

Firebug shows the following error:

layer.map is null

layer.map.addControl(selectControl); (FeatureSelectionModel.js (line 174))

I followed an example on line (http://ian01.geog.psu.edu/geoserver_docs/apps/gaz/index.html). I appologise if someone has already asked this, I've looked everywhere for the answer and found nothing, I'm quite new to this, so any help would be very much appreciated.

Thanks

Will

1 Answer 1

6

Looking at your code you either need to:

map.addLayer(wfs);

or

map.addLayers([wfs]);

You have map.addLayers(wfs), which is incorrect, I believe.

2
  • 1
    It works! much appreciated!
    – Will
    Feb 20, 2012 at 17:35
  • 3
    @Will : Give the_skua credit and mark this question as answered by clicking on the check mark next to this answer. :)
    – CaptDragon
    Feb 20, 2012 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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