diff options
author | Dave Arter <davea@mysociety.org> | 2017-11-29 11:11:39 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2018-02-13 12:39:50 +0000 |
commit | df717b92c41418b287140ddb999c64f21b4fb6ca (patch) | |
tree | ed14b775b68837230d3111a3353a2b579cc1444f | |
parent | 220432931da1472eb9d403df6419aa86b34d3ee6 (diff) |
Make asset layer WFS configuration more customisable
This commit makes it easier to customise the way asset layers are loaded
over WFS, including:
- Adds support for WFS layers via GET method
The standard HTTP method for WFS GetFeature requests is POST, but
some WFS services only support GET. OpenLayers.Protocol.WFS is
hardcoded to use POST, but we can use OpenLayers.Protocol.HTTP
instead to use GET.
The options passed to fixmystreet.add_assets should include a
'http_options' object which configures the HTTP protocol.
- Allows HTTP asset layers to provide their own format
This makes it simpler to use GeoJSON, for example, instead of the
default of GML.
- Asset layers can provide their own loading strategy
The default strategy can be overridden if, for example, you want to
use a BBOX strategy with a smaller ratio in order to load fewer
features at a time.
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index e24e76495..5cbd8923a 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -258,29 +258,51 @@ fixmystreet.add_assets = function(options) { } // An interactive layer for selecting a street light - var protocol_options = { - version: "1.1.0", - url: options.wfs_url, - featureType: options.wfs_feature, - geometryName: options.geometryName - }; - if (fixmystreet.wmts_config) { - protocol_options.srsName = fixmystreet.wmts_config.map_projection; - } - if (options.propertyNames) { - protocol_options.propertyNames = options.propertyNames; + var protocol_options; + var protocol; + if (options.http_options !== undefined) { + protocol_options = OpenLayers.Util.extend(options.http_options, {}); + if (protocol_options.format_class) { + protocol_options.format = new protocol_options.format_class(protocol_options.format_options); + } else { + protocol_options.format = new OpenLayers.Format.GML({ + featureNS: "http://mapserver.gis.umn.edu/mapserver", + geometryName: options.geometryName + }); + } + protocol = new OpenLayers.Protocol.HTTP(protocol_options); + } else { + protocol_options = { + version: "1.1.0", + url: options.wfs_url, + featureType: options.wfs_feature, + geometryName: options.geometryName + }; + if (options.srsName !== undefined) { + protocol_options.srsName = options.srsName; + } + if (fixmystreet.wmts_config && protocol_options.srsName === undefined) { + protocol_options.srsName = fixmystreet.wmts_config.map_projection; + } + if (options.propertyNames) { + protocol_options.propertyNames = options.propertyNames; + } + protocol = new OpenLayers.Protocol.WFS(protocol_options); } - var protocol = new OpenLayers.Protocol.WFS(protocol_options); + var StrategyClass = options.strategy_class || OpenLayers.Strategy.BBOX; var layer_options = { fixmystreet: options, - strategies: [new OpenLayers.Strategy.BBOX()], + strategies: [new StrategyClass()], protocol: protocol, visibility: false, maxResolution: options.max_resolution, minResolution: options.min_resolution, styleMap: get_asset_stylemap() }; - if (fixmystreet.wmts_config) { + if (options.srsName !== undefined) { + layer_options.projection = new OpenLayers.Projection(options.srsName); + } + if (fixmystreet.wmts_config && layer_options.projection === undefined) { layer_options.projection = new OpenLayers.Projection(fixmystreet.wmts_config.map_projection); } if (options.filter_key) { |