WFS.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/Feature.js
  7. */
  8. /**
  9. * Class: OpenLayers.Feature.WFS
  10. * WFS handling class, for use as a featureClass on the WFS layer for handling
  11. * 'point' WFS types. Good for subclassing when creating a custom WFS like
  12. * XML application.
  13. *
  14. * Inherits from:
  15. * - <OpenLayers.Feature>
  16. */
  17. OpenLayers.Feature.WFS = OpenLayers.Class(OpenLayers.Feature, {
  18. /**
  19. * Constructor: OpenLayers.Feature.WFS
  20. * Create a WFS feature.
  21. *
  22. * Parameters:
  23. * layer - {<OpenLayers.Layer>}
  24. * xmlNode - {XMLNode}
  25. */
  26. initialize: function(layer, xmlNode) {
  27. var newArguments = arguments;
  28. var data = this.processXMLNode(xmlNode);
  29. newArguments = new Array(layer, data.lonlat, data);
  30. OpenLayers.Feature.prototype.initialize.apply(this, newArguments);
  31. this.createMarker();
  32. this.layer.addMarker(this.marker);
  33. },
  34. /**
  35. * Method: destroy
  36. * nullify references to prevent circular references and memory leaks
  37. */
  38. destroy: function() {
  39. if (this.marker != null) {
  40. this.layer.removeMarker(this.marker);
  41. }
  42. OpenLayers.Feature.prototype.destroy.apply(this, arguments);
  43. },
  44. /**
  45. * Method: processXMLNode
  46. * When passed an xmlNode, parses it for a GML point, and passes
  47. * back an object describing that point.
  48. *
  49. * For subclasses of Feature.WFS, this is the feature to change.
  50. *
  51. * Parameters:
  52. * xmlNode - {XMLNode}
  53. *
  54. * Returns:
  55. * {Object} Data Object with 'id', 'lonlat', and private properties set
  56. */
  57. processXMLNode: function(xmlNode) {
  58. //this should be overridden by subclasses
  59. // must return an Object with 'id' and 'lonlat' values set
  60. var point = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, "http://www.opengis.net/gml", "gml", "Point");
  61. var text = OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(point[0], "http://www.opengis.net/gml","gml", "coordinates")[0]);
  62. var floats = text.split(",");
  63. return {lonlat: new OpenLayers.LonLat(parseFloat(floats[0]),
  64. parseFloat(floats[1])),
  65. id: null};
  66. },
  67. CLASS_NAME: "OpenLayers.Feature.WFS"
  68. });