WFS.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
  2. * full list of contributors). Published under the Clear BSD license.
  3. * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
  4. * full text of the license. */
  5. /**
  6. * @requires OpenLayers/Protocol.js
  7. */
  8. /**
  9. * Class: OpenLayers.Protocol.WFS
  10. * Used to create a versioned WFS protocol. Default version is 1.0.0.
  11. *
  12. * Returns:
  13. * {<OpenLayers.Protocol>} A WFS protocol of the given version.
  14. *
  15. * Example:
  16. * (code)
  17. * var protocol = new OpenLayers.Protocol.WFS({
  18. * version: "1.1.0",
  19. * url: "http://demo.opengeo.org/geoserver/wfs",
  20. * featureType: "tasmania_roads",
  21. * featureNS: "http://www.openplans.org/topp",
  22. * geometryName: "the_geom"
  23. * });
  24. * (end)
  25. *
  26. * See the protocols for specific WFS versions for more detail.
  27. */
  28. OpenLayers.Protocol.WFS = function(options) {
  29. options = OpenLayers.Util.applyDefaults(
  30. options, OpenLayers.Protocol.WFS.DEFAULTS
  31. );
  32. var cls = OpenLayers.Protocol.WFS["v"+options.version.replace(/\./g, "_")];
  33. if(!cls) {
  34. throw "Unsupported WFS version: " + options.version;
  35. }
  36. return new cls(options);
  37. };
  38. /**
  39. * Function: fromWMSLayer
  40. * Convenience function to create a WFS protocol from a WMS layer. This makes
  41. * the assumption that a WFS requests can be issued at the same URL as
  42. * WMS requests and that a WFS featureType exists with the same name as the
  43. * WMS layer.
  44. *
  45. * This function is designed to auto-configure <url>, <featureType>,
  46. * <featurePrefix> and <srsName> for WFS <version> 1.1.0. Note that
  47. * srsName matching with the WMS layer will not work with WFS 1.0.0.
  48. *
  49. * Parameters:
  50. * layer - {<OpenLayers.Layer.WMS>} WMS layer that has a matching WFS
  51. * FeatureType at the same server url with the same typename.
  52. * options - {Object} Default properties to be set on the protocol.
  53. *
  54. */
  55. OpenLayers.Protocol.WFS.fromWMSLayer = function(layer, options) {
  56. var typeName, featurePrefix;
  57. var param = layer.params["LAYERS"];
  58. var parts = (OpenLayers.Util.isArray(param) ? param[0] : param).split(":");
  59. if(parts.length > 1) {
  60. featurePrefix = parts[0];
  61. }
  62. typeName = parts.pop();
  63. var protocolOptions = {
  64. url: layer.url,
  65. featureType: typeName,
  66. featurePrefix: featurePrefix,
  67. srsName: layer.projection && layer.projection.getCode() ||
  68. layer.map && layer.map.getProjectionObject().getCode(),
  69. version: "1.1.0"
  70. };
  71. return new OpenLayers.Protocol.WFS(OpenLayers.Util.applyDefaults(
  72. options, protocolOptions
  73. ));
  74. };
  75. /**
  76. * Constant: OpenLayers.Protocol.WFS.DEFAULTS
  77. */
  78. OpenLayers.Protocol.WFS.DEFAULTS = {
  79. "version": "1.0.0"
  80. };