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.

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

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
1  
It works! much appreciated! –  Will Feb 20 '12 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 '12 at 18:31
add comment

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.