]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Feature/WFS.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Feature / WFS.js
1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2  * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3  * full text of the license. */
4
5 /**
6  * @requires OpenLayers/Feature.js
7  */
8
9 /**
10  * Class: OpenLayers.Feature.WFS
11  * WFS handling class, for use as a featureClass on the WFS layer for handling
12  * 'point' WFS types. Good for subclassing when creating a custom WFS like
13  * XML application.
14  * 
15  * Inherits from:
16  *  - <OpenLayers.Feature>
17  */
18 OpenLayers.Feature.WFS = OpenLayers.Class(OpenLayers.Feature, {
19       
20     /** 
21      * Constructor: OpenLayers.Feature.WFS
22      * Create a WFS feature.
23      *
24      * Parameters:
25      * layer - {<OpenLayers.Layer>} 
26      * xmlNode - {XMLNode} 
27      */
28     initialize: function(layer, xmlNode) {
29         var newArguments = arguments;
30         var data = this.processXMLNode(xmlNode);
31         newArguments = new Array(layer, data.lonlat, data);
32         OpenLayers.Feature.prototype.initialize.apply(this, newArguments);
33         this.createMarker();
34         this.layer.addMarker(this.marker);
35     },
36     
37     /** 
38      * Method: destroy
39      * nullify references to prevent circular references and memory leaks
40      */
41     destroy: function() {
42         if (this.marker != null) {
43             this.layer.removeMarker(this.marker);  
44         }
45         OpenLayers.Feature.prototype.destroy.apply(this, arguments);
46     },
47
48     /**
49      * Method: processXMLNode
50      * When passed an xmlNode, parses it for a GML point, and passes
51      * back an object describing that point.
52      *
53      * For subclasses of Feature.WFS, this is the feature to change.
54      *
55      * Parameters:
56      * xmlNode - {XMLNode} 
57      * 
58      * Returns:
59      * {Object} Data Object with 'id', 'lonlat', and private properties set
60      */
61     processXMLNode: function(xmlNode) {
62         //this should be overridden by subclasses
63         // must return an Object with 'id' and 'lonlat' values set
64         var point = OpenLayers.Ajax.getElementsByTagNameNS(xmlNode, "http://www.opengis.net/gml", "gml", "Point");
65         var text  = OpenLayers.Util.getXmlNodeValue(OpenLayers.Ajax.getElementsByTagNameNS(point[0], "http://www.opengis.net/gml","gml", "coordinates")[0]);
66         var floats = text.split(",");
67         return {lonlat: new OpenLayers.LonLat(parseFloat(floats[0]),
68                                               parseFloat(floats[1])),
69                 id: null};
70
71     },
72
73     CLASS_NAME: "OpenLayers.Feature.WFS"
74 });
75   
76   
77   
78   
79