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.
If I put the JSON file in a web directory and do an HTTP protocol to it, it works. Which is to say,
protocol: new OpenLayers.Protocol.HTTP({
url: "http://fakeurl/data/summits.json",
format: new OpenLayers.Format.GeoJSON()
})
displays just fine. However, when I link to a WFS Getfeature request, like
protocol: new OpenLayers.Protocol.HTTP({
url: "http://fakeurl/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=geonode:summits&maxFeatures=50",
format: new OpenLayers.Format.GeoJSON()
})
I get no result. But the url provided displays the JSON file in a browser. I don't understand. I just want some way of getting those contents via GeoServer, but it continues to elude me.
turns out there's something wrong with the layer itself. I can view the JSON data through a link but only if I'm logged into Geoserver. If I'm not logged in, then I get a "Could not find layer" message. So I guess that's my issue: why data imported in GeoServer it not made public (my JSON), but a layer through Geonode is.
protocol: new OpenLayers.Protocol.WFS