Skip to main content
1 of 4

OpenLayers 2, JSON vector through WFS

Consider this example,

https://geoext.github.io/geoext2/examples/grid/feature-grid.html

It uses

protocol: new OpenLayers.Protocol.HTTP({
                url: "../data/summits.json",
                format: new OpenLayers.Format.GeoJSON()
            })

for the locations and elevations of some mountains. There are three properties: name (string), height (long), and geometry (point).

What I want to do is put the json file onto GeoServer and call it that way. I imported the file into GeoServer, and I know it works because I can see it with a WFS url. But I'm trying to load it with the code

var vecLayer = new OpenLayers.Layer.Vector("vector", {
    styleMap: new OpenLayers.StyleMap({
        'default': style
    }),
    strategies: [new OpenLayers.Strategy.Fixed() ],
    protocol: new OpenLayers.Protocol.WFS({
        readFormat: new OpenLayers.Format.GeoJSON(),
        url: "http://fakeurl.com/geoserver/wfs",
        srsName: "EPSG:4326",
        featureNS: "http://fakeurl.com/geoext/geonodeuri",
        featureType: "summits",
        outputFormat: "json",
        version: "1.1.0"
   })
});

I know that url, featureNS, and featureType are all correct because I can successfully add other shapefile vectors in the same workspace with them. I'm quite stumped as far as getting the WFS protocol to work, however. Do I need to set geometryName or something? GeoServer lists three properties, and I need all three of them. Ideally I would get the exact same result as the simple OpenLayers.Protocol.HTTP protocol.

Thanks.