Skip to content

Instantly share code, notes, and snippets.

@justinlewis
Created March 5, 2013 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinlewis/5095156 to your computer and use it in GitHub Desktop.
Save justinlewis/5095156 to your computer and use it in GitHub Desktop.
Add a simple WFS layers to an OpenLayers map from a Geoserver WFS service. Standard approach to getting around the browsers same origin policy with JavaScript.
var tipProjects = new OpenLayers.Layer.Vector("TIP Projects 2012 - 2017", {
strategies: [new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.Script({
url: "http://gis.drcog.org/geoserver/wfs",
callbackKey: "format_options",
callbackPrefix: "callback:",
params: {
service: "WFS",
version: "1.1.0",
srsName: "EPSG:4326",
request: "GetFeature",
typeName: "DRCOGPUB:tip_project_points_2012_2017",
outputFormat: "json"
},
filterToParams: function(filter, params) {
if (filter.type === OpenLayers.Filter.Spatial.BBOX) {
params.bbox = filter.value.toArray();
if (filter.projection) {
params.bbox.push(filter.projection.getCode());
}
}
return params;
}
})
})
map.addLayer(tipProjects);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment