OpenLayers OpenLayers

AtomPublishingProtocol: app.2.patch

File app.2.patch, 29.6 kB (added by crschmidt, 1 year ago)

Atom Publishing Protocol simple demo: works with FeatureServer

  • tests/list-tests.html

    old new  
    6060    <li>Tile/test_Image.html</li> 
    6161    <li>test_Control.html</li> 
    6262    <li>Control/test_DragFeature.html</li> 
     63    <li>Control/test_ModifyFeature.html</li> 
    6364    <li>Control/test_DragPan.html</li> 
    6465    <li>Control/test_OverviewMap.html</li> 
    6566    <li>Control/test_NavToolbar.html</li> 
  • lib/OpenLayers/Control/ModifyFeature.js

    old new  
     1/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4 
     5 
     6/** 
     7 * @requires OpenLayers/Control/DragFeature.js 
     8 * @requires OpenLayers/Control/SelectFeature.js 
     9 * @requires OpenLayers/Handler/Keyboard.js 
     10 *  
     11 * Class: OpenLayers.Control.ModifyFeature 
     12 * Control to modify features.  When activated, a click renders the vertices 
     13 *     of a feature - these vertices can then be dragged.  By default, the 
     14 *     delete key will delete the vertex under the mouse.  New features are 
     15 *     added by dragging "virtual vertices" between vertices.  Create a new 
     16 *     control with the <OpenLayers.Control.ModifyFeature> constructor. 
     17 * 
     18 * Inherits From: 
     19 *  - <OpenLayers.Control> 
     20 */ 
     21OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, { 
     22 
     23    /** 
     24     * APIProperty: geometryTypes 
     25     * {Array(String)} To restrict modification to a limited set of geometry 
     26     *     types, send a list of strings corresponding to the geometry class 
     27     *     names. 
     28     */ 
     29    geometryTypes: null, 
     30 
     31    /** 
     32     * Property: layer 
     33     * {OpenLayers.Layer.Vector} 
     34     */ 
     35    layer: null, 
     36     
     37    /** 
     38     * Property: feature 
     39     * {<OpenLayers.Feature.Vector>} Feature currently available for modification. 
     40     */ 
     41    feature: null, 
     42     
     43    /** 
     44     * Property: vertices 
     45     * {Array(<OpenLayers.Feature.Vector>)} Verticies currently available 
     46     *     for dragging. 
     47     */ 
     48    vertices: null, 
     49     
     50    /** 
     51     * Property: virtualVertices 
     52     * {Array(<OpenLayers.Feature.Vector>)} Virtual vertices in the middle 
     53     *     of each edge. 
     54     */ 
     55    virtualVertices: null, 
     56 
     57    /** 
     58     * Property: selectControl 
     59     * {<OpenLayers.Control.Select>} 
     60     */ 
     61    selectControl: null, 
     62     
     63    /** 
     64     * Property: dragControl 
     65     * {<OpenLayers.Control.DragFeature>} 
     66     */ 
     67    dragControl: null, 
     68     
     69    /** 
     70     * Property: keyboardHandler 
     71     * {<OpenLayers.Handler.Keyboard>} 
     72     */ 
     73    keyboardHandler: null, 
     74     
     75    /** 
     76     * APIProperty: deleteCodes 
     77     * {Array(Integer)} Keycodes for deleting verticies.  Set to null to disable 
     78     *     vertex deltion by keypress.  If non-null, keypresses with codes 
     79     *     in this array will delete vertices under the mouse. Default 
     80     *     is 46 and 100, the 'delete' and lowercase 'd' keys. 
     81     */ 
     82    deleteCodes: null, 
     83 
     84    /** 
     85     * APIProperty: virtualStyle 
     86     * {<OpenLayers.Feature.Vector.Style>} 
     87     */ 
     88    virtualStyle: null, 
     89     
     90    /** 
     91     * APIProperty: onModificationStart  
     92     * {Function} Optional function to be called when a feature is selected 
     93     *     to be modified. The function should expect to be called with a 
     94     *     feature.  This could be used for example to allow to lock the 
     95     *     feature on server-side. 
     96     */ 
     97    onModificationStart: function() {}, 
     98 
     99    /** 
     100     * APIProperty: onModification 
     101     * {Function} Optional function to be called when a feature has been 
     102     *     modified.  The function should expect to be called with a feature. 
     103     */ 
     104    onModification: function() {}, 
     105 
     106    /** 
     107     * APIProperty: onModificationEnd 
     108     * {Function} Optional function to be called when a feature is finished  
     109     *     being modified.  The function should expect to be called with a 
     110     *     feature. 
     111     */ 
     112    onModificationEnd: function() {}, 
     113     
     114    /** 
     115     * Constructor: OpenLayers.Control.ModifyFeature 
     116     * Create a new modify feature control. 
     117     * 
     118     * Parameters: 
     119     * layer - {OpenLayers.Layer.Vector} Layer that contains features that 
     120     *     will be modified. 
     121     * options - {Object} Optional object whose properties will be set on the 
     122     *     control. 
     123     */ 
     124    initialize: function(layer, options) { 
     125        this.layer = layer; 
     126        this.vertices = []; 
     127        this.virtualVertices = []; 
     128        this.styleVirtual = OpenLayers.Util.extend({}, this.layer.style); 
     129        this.styleVirtual.fillOpacity = 0.3; 
     130        this.styleVirtual.strokeOpacity = 0.3; 
     131        this.deleteCodes = [46, 100]; 
     132        OpenLayers.Control.prototype.initialize.apply(this, [options]); 
     133        if(!(this.deleteCodes instanceof Array)) { 
     134            this.deleteCodes = [this.deleteCodes]; 
     135        } 
     136        var control = this; 
     137 
     138        // configure the select control 
     139        var selectOptions = { 
     140            geometryTypes: this.geometryTypes, 
     141            onSelect: function(feature) { 
     142                control.selectFeature.apply(control, [feature]); 
     143            }, 
     144            onUnselect: function(feature) { 
     145                control.unselectFeature.apply(control, [feature]); 
     146            } 
     147        }; 
     148        this.selectControl = new OpenLayers.Control.SelectFeature( 
     149            layer, selectOptions 
     150        ); 
     151 
     152        // configure the drag control 
     153        var dragOptions = { 
     154            geometryTypes: ["OpenLayers.Geometry.Point"], 
     155            snappingOptions: this.snappingOptions, 
     156            onStart: function(feature, pixel) { 
     157                control.dragStart.apply(control, [feature, pixel]); 
     158            }, 
     159            onDrag: function(feature) { 
     160                control.dragVertex.apply(control, [feature]); 
     161            }, 
     162            onComplete: function(feature) { 
     163                control.dragComplete.apply(control, [feature]); 
     164            } 
     165        }; 
     166        this.dragControl = new OpenLayers.Control.DragFeature( 
     167            layer, dragOptions 
     168        ); 
     169 
     170        // configure the keyboard handler 
     171        var keyboardOptions = { 
     172            keypress: this.handleKeypress 
     173        }; 
     174        this.keyboardHandler = new OpenLayers.Handler.Keyboard( 
     175            this, keyboardOptions 
     176        ); 
     177    }, 
     178 
     179    /** 
     180     * APIMethod: destroy 
     181     * Take care of things that are not handled in superclass. 
     182     */ 
     183    destroy: function() { 
     184        this.layer = null; 
     185        this.selectControl.destroy(); 
     186        this.dragControl.destroy(); 
     187        this.keyboardHandler.destroy(); 
     188        OpenLayers.Control.prototype.destroy.apply(this, []); 
     189    }, 
     190 
     191    /** 
     192     * APIMethod: activate 
     193     * Activate the control and the feature handler. 
     194     *  
     195     * Returns: 
     196     * {Boolean} Successfully activated the control and feature handler. 
     197     */ 
     198    activate: function() { 
     199        return (this.selectControl.activate() && 
     200                this.keyboardHandler.activate() && 
     201                OpenLayers.Control.prototype.activate.apply(this, arguments)); 
     202    }, 
     203 
     204    /** 
     205     * APIMethod: deactivate 
     206     * Deactivate the controls. 
     207     * 
     208     * Returns:  
     209     * {Boolean} Successfully deactivated the control. 
     210     */ 
     211    deactivate: function() { 
     212        var deactivated = false; 
     213        // the return from the controls is unimportant in this case 
     214        if(OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { 
     215            this.layer.removeFeatures(this.vertices); 
     216            this.layer.removeFeatures(this.virtualVertices); 
     217            this.vertices = []; 
     218            this.dragControl.deactivate(); 
     219            if(this.feature) { 
     220                this.selectControl.unselect.apply(this.selectControl, 
     221                                                  [this.feature]); 
     222            } 
     223            this.selectControl.deactivate(); 
     224            this.keyboardHandler.deactivate(); 
     225            deactivated = true; 
     226        } 
     227        return deactivated; 
     228    }, 
     229 
     230    /** 
     231     * Method: selectFeature 
     232     * Called when the select feature control selects a feature. 
     233     * 
     234     * Parameters: 
     235     * feature - {<OpenLayers.Feature.Vector>} The selected feature. 
     236     */ 
     237    selectFeature: function(feature) { 
     238        this.feature = feature; 
     239        this.resetVertices(); 
     240        this.dragControl.activate(); 
     241        this.onModificationStart(this.feature); 
     242    }, 
     243 
     244    /** 
     245     * Method: unselectFeature 
     246     * Called when the select feature control unselects a feature. 
     247     * 
     248     * Parameters: 
     249     * feature - {<OpenLayers.Feature.Vector>} The unselected feature. 
     250     */ 
     251    unselectFeature: function(feature) { 
     252        this.layer.removeFeatures(this.vertices); 
     253        this.layer.removeFeatures(this.virtualVertices); 
     254        this.vertices = []; 
     255        this.virtualVertices = []; 
     256        this.feature = null; 
     257        this.dragControl.deactivate(); 
     258        this.onModificationEnd(feature); 
     259    }, 
     260 
     261    /** 
     262     * Method: dragStart 
     263     * Called by the drag feature control with before a feature is dragged. 
     264     *     This method is used to differentiate between points and vertices 
     265     *     of higher order geometries.  This respects the <geometryTypes> 
     266     *     property and forces a select of points when the drag control is 
     267     *     already active (and stops events from propagating to the select 
     268     *     control). 
     269     * 
     270     * Parameters: 
     271     * feature - {<OpenLayers.Feature.Vector>} The point or vertex about to be 
     272     *     dragged. 
     273     * pixel - {<OpenLayers.Pixel>} Pixel location of the mouse event. 
     274     */ 
     275    dragStart: function(feature, pixel) { 
     276        // only change behavior if the feature is not in the vertices array 
     277        if(feature != this.feature && 
     278           OpenLayers.Util.indexOf(this.vertices, feature) == -1 && 
     279           OpenLayers.Util.indexOf(this.virtualVertices, feature) == -1) { 
     280            if(this.feature) { 
     281                // unselect the currently selected feature 
     282                this.selectControl.clickFeature.apply(this.selectControl, 
     283                                                      [this.feature]); 
     284            } 
     285            // check any constraints on the geometry type 
     286            if(this.geometryTypes == null || 
     287               OpenLayers.Util.indexOf(this.geometryTypes, 
     288                                       feature.geometry.CLASS_NAME) != -1) { 
     289                // select the point 
     290                this.selectControl.clickFeature.apply(this.selectControl, 
     291                                                      [feature]); 
     292                /** 
     293                 * TBD: These lines improve workflow by letting the user 
     294                 *     immediately start dragging after the mouse down. 
     295                 *     However, it is very ugly to be messing with controls 
     296                 *     and their handlers in this way.  I'd like a better 
     297                 *     solution if the workflow change is necessary. 
     298                 */ 
     299                // prepare the point for dragging 
     300                this.dragControl.overFeature.apply(this.dragControl, 
     301                                                   [feature]); 
     302                this.dragControl.lastPixel = pixel; 
     303                this.dragControl.dragHandler.started = true; 
     304                this.dragControl.dragHandler.start = pixel; 
     305                this.dragControl.dragHandler.last = pixel; 
     306            } 
     307        } 
     308    }, 
     309     
     310    /** 
     311     * Method: dragVertex 
     312     * Called by the drag feature control with each drag move of a vertex. 
     313     * 
     314     * Parameters: 
     315     * vertex - {<OpenLayers.Feature.Vector>} The vertex being dragged. 
     316     */ 
     317    dragVertex: function(vertex) { 
     318        if(this.feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { 
     319            if(this.feature != vertex) { 
     320                this.feature = vertex; 
     321            } 
     322        } else { 
     323            if(OpenLayers.Util.indexOf(this.virtualVertices, vertex) != -1) { 
     324                vertex.geometry.parent.addComponent(vertex.geometry, 
     325                                                    vertex._index); 
     326                delete vertex._index; 
     327                OpenLayers.Util.removeItem(this.virtualVertices, vertex); 
     328                this.layer.removeFeatures(vertex); 
     329            } 
     330        } 
     331        this.layer.drawFeature(this.feature, this.selectControl.selectStyle); 
     332        this.layer.removeFeatures(this.virtualVertices); 
     333        // keep the vertex on top so it gets the mouseout after dragging 
     334        // this should be removed in favor of an option to draw under or 
     335        // maintain node z-index 
     336        this.layer.drawFeature(vertex); 
     337    }, 
     338     
     339    /** 
     340     * Method: dragComplete 
     341     * Called by the drag feature control when the feature dragging is complete. 
     342     * 
     343     * Parameters: 
     344     * vertex - {<OpenLayers.Feature.Vector>} The vertex being dragged. 
     345     */ 
     346    dragComplete: function(vertex) { 
     347        this.resetVertices(); 
     348        this.onModification(this.feature); 
     349    }, 
     350     
     351    /** 
     352     * Method: resetVertices 
     353     */ 
     354    resetVertices: function() { 
     355        if(this.vertices.length > 0) { 
     356            this.layer.removeFeatures(this.vertices); 
     357            this.vertices = []; 
     358        } 
     359        if(this.virtualVertices.length > 0) { 
     360            this.layer.removeFeatures(this.virtualVertices); 
     361            this.virtualVertices = []; 
     362        } 
     363        if(this.feature.geometry.CLASS_NAME != "OpenLayers.Geometry.Point") { 
     364            this.collectVertices(this.feature.geometry); 
     365            this.layer.addFeatures(this.vertices); 
     366            this.layer.addFeatures(this.virtualVertices); 
     367        } 
     368    }, 
     369     
     370    /** 
     371     * Method: handleKeypress 
     372     * Called by the feature handler on keypress.  This is used to delete 
     373     *     vertices and point features.  If the <deleteCode> property is set, 
     374     *     vertices and points will be deleted when a feature is selected 
     375     *     for modification and the mouse is over a vertex. 
     376     * 
     377     * Parameters: 
     378     * {Integer} Key code corresponding to the keypress event. 
     379     */ 
     380    handleKeypress: function(code) { 
     381        // check for delete key 
     382        if(OpenLayers.Util.indexOf(this.deleteCodes, code) != -1) {  
     383            var vertex = this.dragControl.feature; 
     384            if(vertex) { 
     385                if(this.feature.geometry.CLASS_NAME == 
     386                   "OpenLayers.Geometry.Point") { 
     387                    // delete the point 
     388                    this.layer.removeFeatures([vertex]); 
     389                } else { 
     390                    if(OpenLayers.Util.indexOf(this.vertices, vertex) != -1) { 
     391                        // remove the vertex 
     392                        vertex.geometry.parent.removeComponent(vertex.geometry); 
     393                        this.layer.drawFeature(this.feature, 
     394                                               this.selectControl.selectStyle); 
     395                        this.resetVertices(); 
     396                    } 
     397                } 
     398            } 
     399        } 
     400    }, 
     401 
     402    /** 
     403     * Method: collectVertices 
     404     * Collect the vertices from the modifiable feature's geometry and push 
     405     *     them on to the control's vertices array. 
     406     */ 
     407    collectVertices: function() { 
     408        this.vertices = []; 
     409        this.virtualVirtices = [];         
     410        var control = this; 
     411        function collectComponentVertices(geometry) { 
     412            var i, vertex, component; 
     413            if(geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { 
     414                vertex = new OpenLayers.Feature.Vector(geometry); 
     415                control.vertices.push(vertex); 
     416            } else { 
     417                for(i=0; i<geometry.components.length; ++i) { 
     418                    component = geometry.components[i]; 
     419                    if(component.CLASS_NAME == "OpenLayers.Geometry.Point") { 
     420                        vertex = new OpenLayers.Feature.Vector(component); 
     421                        control.vertices.push(vertex); 
     422                    } else { 
     423                        collectComponentVertices(component); 
     424                    } 
     425                } 
     426                 
     427                // add virtual vertices in the middle of each edge 
     428                if(geometry.CLASS_NAME != "OpenLayers.Geometry.MultiPoint") { 
     429                    for(i=0; i<geometry.components.length-1; ++i) { 
     430                        var prevVertex = geometry.components[i]; 
     431                        var nextVertex = geometry.components[i + 1]; 
     432                        if(prevVertex.CLASS_NAME == "OpenLayers.Geometry.Point" && 
     433                           nextVertex.CLASS_NAME == "OpenLayers.Geometry.Point") { 
     434                            var x = (prevVertex.x + nextVertex.x) / 2; 
     435                            var y = (prevVertex.y + nextVertex.y) / 2; 
     436                            var point = new OpenLayers.Feature.Vector( 
     437                                new OpenLayers.Geometry.Point(x, y), 
     438                                null, control.styleVirtual 
     439                            ); 
     440                            // set the virtual parent and intended index 
     441                            point.geometry.parent = geometry; 
     442                            point._index = i + 1; 
     443                            control.virtualVertices.push(point); 
     444                        } 
     445                    } 
     446                } 
     447            } 
     448        }        
     449        collectComponentVertices(this.feature.geometry); 
     450    }, 
     451 
     452    /** 
     453     * Method: setMap 
     454     * Set the map property for the control and all handlers. 
     455     * 
     456     * Parameters: 
     457     * map - {OpenLayers.Map} The control's map. 
     458     */ 
     459    setMap: function(map) { 
     460        this.selectControl.setMap(map); 
     461        this.dragControl.setMap(map); 
     462        OpenLayers.Control.prototype.setMap.apply(this, arguments); 
     463    }, 
     464 
     465    CLASS_NAME: "OpenLayers.Control.ModifyFeature" 
     466}); 
  • lib/OpenLayers/Format/APP.js

    old new  
     1/* Copyright (c) 2006-2007 MetaCarta, Inc., published under a modified BSD license. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4 
     5/** 
     6 * @requires OpenLayers/Format.js 
     7 * 
     8 * Class: OpenLayers.Format.APP 
     9 * Write-only APP. Create a new instance with the  
     10 *     <OpenLayers.Format.APP> constructor. 
     11 * 
     12 * Inherits from: 
     13 *  - <OpenLayers.Format> 
     14 */ 
     15OpenLayers.Format.APP = OpenLayers.Class(OpenLayers.Format.XML, { 
     16     
     17    /** 
     18     * APIProperty: rssns 
     19     * RSS namespace to use. 
     20     */ 
     21    rssns: "http://backend.userland.com/rss2", 
     22     
     23    /** 
     24     * APIProperty: featurens 
     25     * Feature Attributes namespace 
     26     */ 
     27    featureNS: "http://mapserver.gis.umn.edu/mapserver", 
     28     
     29    /** 
     30     * APIProperty: georssns 
     31     * APP namespace to use. 
     32     */ 
     33    georssns: "http://www.georss.org/georss", 
     34     
     35     
     36    /** 
     37     * Constructor: OpenLayers.Format.APP 
     38     * Create a new parser for APP 
     39     * 
     40     * Parameters: 
     41     * options - {Object} An optional object whose properties will be set on 
     42     *                    this instance. 
     43     */ 
     44    initialize: function(options) { 
     45        OpenLayers.Format.prototype.initialize.apply(this, [options]); 
     46    }, 
     47     
     48    /** 
     49     * APIMethod: read 
     50     * Return a list of features from a APP doc 
     51      
     52     * Parameters: 
     53     * data - {Element}  
     54     * 
     55     * Returns: 
     56     * An Array of <OpenLayers.Feature.Vector>s 
     57     */ 
     58    read: function(doc) { 
     59        if (typeof doc == "string") {  
     60            doc = OpenLayers.Format.XML.prototype.read.apply(this, [doc]); 
     61        } 
     62 
     63        /* Try RSS items first, then Atom entries */ 
     64        var itemlist = null; 
     65        itemlist = this.getElementsByTagNameNS(doc, '*', 'item'); 
     66        if (itemlist.length == 0) { 
     67            itemlist = this.getElementsByTagNameNS(doc, '*', 'entry'); 
     68        } 
     69         
     70        var features = []; 
     71        for(var i=0; i<itemlist.length; i++) { 
     72            // this is horrendous - please change this 
     73            var point = OpenLayers.Util.getNodes(itemlist[i], 'georss:point'); 
     74            var lat = OpenLayers.Util.getNodes(itemlist[i], 'geo:lat'); 
     75            var lon = OpenLayers.Util.getNodes(itemlist[i], 'geo:long'); 
     76            if (point.length > 0) { 
     77                var location = point[0].firstChild.nodeValue.trim().split(/\s+/); 
     78                 
     79                if (location.length !=2) { 
     80                    var location = point[0].firstChild.nodeValue.trim().split(/\s*,\s*/); 
     81                } 
     82            } else if (lat.length > 0 && lon.length > 0) { 
     83                var location = [parseFloat(lat[0].firstChild.nodeValue), parseFloat(lon[0].firstChild.nodeValue)]; 
     84            } else { 
     85                continue; 
     86            } 
     87            var geometry = new OpenLayers.Geometry.Point(parseFloat(location[1]), 
     88                                                         parseFloat(location[0])); 
     89 
     90            /* Provide defaults for title and description */ 
     91            var title = "Untitled"; 
     92            try { 
     93                title = OpenLayers.Util.getNodes(itemlist[i],  
     94                        "title")[0].firstChild.nodeValue; 
     95            } 
     96            catch (e) { title="Untitled"; } 
     97            
     98            /* First try RSS descriptions, then Atom summaries */ 
     99            var descr_nodes = this.getElementsByTagNameNS(itemlist[i], 
     100                                                          "*", 
     101                                                          "description"); 
     102            if (descr_nodes.length == 0) { 
     103                descr_nodes = this.getElementsByTagNameNS(itemlist[i], 
     104                                                          "*", 
     105                                                          "summary"); 
     106            } 
     107            var description = "No description."; 
     108            try { 
     109              description = descr_nodes[0].firstChild.nodeValue; 
     110            } 
     111            catch (e) { description="No description."; } 
     112 
     113            /* If no link URL is found in the first child node, try the 
     114               href attribute */ 
     115            var link = null; 
     116            var edit_link = null; 
     117            try { 
     118                var link = OpenLayers.Util.getNodes(itemlist[i], "link")[0].firstChild.nodeValue; 
     119            } 
     120            catch (e) { 
     121                var link_list = OpenLayers.Util.getNodes(itemlist[i], "link"); 
     122                for (var i = 0; i < link_list.length; i++) { 
     123                    var this_link = link_list[i]; 
     124                    if (this_link.getAttribute("href") && this_link.getAttribute("rel") == "edit") { 
     125                        edit_link = this_link.getAttribute("href"); 
     126                    }  else { 
     127                        link = this_link.getAttribute("href"); 
     128                    }     
     129                }     
     130            } 
     131             
     132            var data = { 
     133                "title": title, 
     134                "description": description, 
     135                "link": link, 
     136                "edit_link": edit_link 
     137            }; 
     138            features.push(new OpenLayers.Feature.Vector(geometry, data)); 
     139        } 
     140        return features; 
     141    }, 
     142     
     143 
     144    /** 
     145     * APIMethod: write 
     146     * Accept Feature Collection, and return a string.  
     147     *  
     148     * Parameters:  
     149     * features - Array({<OpenLayers.Feature.Vector>}) List of features to serialize into a string. 
     150     */ 
     151    write: function(features) { 
     152        var georss; 
     153        if(features instanceof Array) { 
     154            georss = this.createElementNS(this.rssns, "rss"); 
     155            for(var i=0; i < features.length; i++) { 
     156                georss.appendChild(this.createFeatureXML(features[i])); 
     157            } 
     158        } else { 
     159            georss = this.createFeatureXML(features); 
     160        } 
     161        return OpenLayers.Format.XML.prototype.write.apply(this, [georss]); 
     162     }, 
     163 
     164    /** 
     165     * Method: createFeatureXML 
     166     * Accept an <OpenLayers.Feature.Vector>, and build a geometry for it. 
     167     *  
     168     * Parameters: 
     169     * feature - {<OpenLayers.Feature.Vector>}  
     170     * 
     171     * Returns: 
     172     * {DOMElement} 
     173     */ 
     174    createFeatureXML: function(feature) { 
     175        var geometryNode = this.buildGeometryNode(feature.geometry); 
     176        var featureNode = this.createElementNS(this.rssns, "item"); 
     177        var titleNode = this.createElementNS(this.rssns, "title"); 
     178        titleNode.appendChild(this.createTextNode(feature.attributes.title ? feature.attributes.title : "")); 
     179        var descNode = this.createElementNS(this.rssns, "description"); 
     180        descNode.appendChild(this.createTextNode(feature.attributes.description ? feature.attributes.description : "")); 
     181        featureNode.appendChild(titleNode); 
     182        featureNode.appendChild(descNode); 
     183        for(var attr in feature.attributes) { 
     184            if (attr == "edit_link" || attr == "title" || attr == "description" ) { continue; } 
     185            var attrText = this.createTextNode(feature.attributes[attr]);  
     186            var nodename = attr; 
     187            if (attr.search(":") != -1) { 
     188                nodename = attr.split(":")[1]; 
     189            }     
     190            var attrContainer = this.createElementNS(this.featureNS, "feature:"+nodename); 
     191            attrContainer.appendChild(attrText); 
     192            featureNode.appendChild(attrContainer); 
     193        }     
     194        featureNode.appendChild(geometryNode); 
     195        return featureNode; 
     196    },     
     197     
     198    /**  
     199     * Method: buildGeometryNode 
     200     * builds a APP node with a given geometry 
     201     *  
     202     * Parameters: 
     203     * geometry - {<OpenLayers.Geometry>}  
     204     */ 
     205    buildGeometryNode: function(geometry) { 
     206        var gml = ""; 
     207        // match MultiPolygon or Polygon 
     208        if (geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon") { 
     209            gml = this.createElementNS(this.georssns, 'georss:polygon'); 
     210             
     211            gml.appendChild(this.buildCoordinatesNode(geometry.components[0])); 
     212        } 
     213        // match MultiLineString or LineString 
     214        else if (geometry.CLASS_NAME == "OpenLayers.Geometry.LineString") { 
     215            gml = this.createElementNS(this.georssns, 'georss:line'); 
     216             
     217            gml.appendChild(this.buildCoordinatesNode(geometry)); 
     218        } 
     219        // match MultiPoint or Point 
     220        else if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { 
     221            gml = this.createElementNS(this.georssns, 'georss:point'); 
     222            gml.appendChild(this.buildCoordinatesNode(geometry)); 
     223        } else {     
     224            alert("Couldn't parse " + geometry.CLASS_NAME); 
     225        }   
     226        return gml;          
     227    }, 
     228     
     229    /**  
     230     * Method: buildCoordinatesNode 
     231     *  
     232     * Parameters: 
     233     * geometry - {<OpenLayers.Geometry>} 
     234     */ 
     235    buildCoordinatesNode: function(geometry) { 
     236        var points = null; 
     237         
     238        if (geometry.components) { 
     239            points = geometry.components; 
     240        } 
     241 
     242        var path = ""; 
     243        if (points) { 
     244            for (var i = 0; i < points.length; i++) { 
     245                path += points[i].y + " " + points[i].x + " "; 
     246            } 
     247        } else { 
     248           path += geometry.y + " " + geometry.x + " "; 
     249        } 
     250        return this.createTextNode(path); 
     251    }, 
     252 
     253    CLASS_NAME: "OpenLayers.Format.APP"  
     254});      
  • lib/OpenLayers.js

    old new  
    139139            "OpenLayers/Control/LayerSwitcher.js", 
    140140            "OpenLayers/Control/DrawFeature.js", 
    141141            "OpenLayers/Control/DragFeature.js", 
     142            "OpenLayers/Control/ModifyFeature.js", 
    142143            "OpenLayers/Control/Panel.js", 
    143144            "OpenLayers/Control/SelectFeature.js", 
    144145            "OpenLayers/Geometry.js", 
     
    164165            "OpenLayers/Format/GML.js", 
    165166            "OpenLayers/Format/KML.js", 
    166167            "OpenLayers/Format/GeoRSS.js", 
     168            "OpenLayers/Format/APP.js", 
    167169            "OpenLayers/Format/JSON.js", 
    168170            "OpenLayers/Format/GeoJSON.js", 
    169171            "OpenLayers/Format/WFS.js", 
  • examples/gml-layer.html

    old new  
    1616        var map, layer; 
    1717 
    1818        function init(){ 
     19            OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url="; 
    1920            map = new OpenLayers.Map('map'); 
    2021            layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
    2122                    "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); 
    2223            map.addLayer(layer); 
    23             map.zoomToExtent(new OpenLayers.Bounds(-3.922119,44.335327,4.866943,49.553833)); 
    24             map.addLayer(new OpenLayers.Layer.GML("GML", "gml/polygon.xml")); 
     24            map.zoomToExtent(new OpenLayers.Bounds(-105.034779,39.676066,-104.89745,39.757605)); 
     25            map.addLayer(new OpenLayers.Layer.GML("GML", "/cgi-bin/fs-2/featureserver.cgi/scribble/54.atom", {format: OpenLayers.Format.APP})); 
     26            var mf = new OpenLayers.Control.ModifyFeature(map.layers[1]); 
     27            format = new OpenLayers.Format.APP(); 
     28            mf.onModification= function(feature) {  
     29              var atom = format.write(feature); 
     30              var url = feature.attributes.edit_link; 
     31                   new OpenLayers.Ajax.Request(url, 
     32                         {   method: 'post', 
     33                             postBody: atom, 
     34                             onComplete: function() { console.log("success"); }, 
     35                          } 
     36                         );  
     37            } 
     38            map.addControl(mf); 
     39            mf.activate(); 
    2540        } 
    2641        // --> 
    2742    </script>