Ticket #1648: wfs_with_tests.patch
| File wfs_with_tests.patch, 77.7 kB (added by ahocevar, 1 year ago) |
|---|
-
tests/Format/WFST/v1_0_0.html
old new 1 <html> 2 <head> 3 <script src="../../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"> 5 6 function test_initialize(t) { 7 t.plan(1); 8 9 var format = new OpenLayers.Format.WFST.v1_0_0({}); 10 t.ok(format instanceof OpenLayers.Format.WFST.v1_0_0, "constructor returns instance"); 11 } 12 13 function test_read(t) { 14 t.plan(2); 15 16 var data = readXML("Transaction_Response"); 17 var format = new OpenLayers.Format.WFST.v1_0_0({ 18 featureNS: "http://www.openplans.org/topp", 19 featureType: "states" 20 }); 21 var result = format.read(data); 22 t.eq(result.insertIds[0], "none", "InsertIds read correctly"); 23 t.eq(result.success, true, "Success read correctly"); 24 } 25 26 function test_write(t) { 27 28 var format = new OpenLayers.Format.WFST.v1_0_0({ 29 featureNS: "http://www.openplans.org/topp", 30 featureType: "states", 31 featurePrefix: "topp", 32 geometryName: "the_geom" 33 }); 34 35 t.plan(1); 36 var snippets = { 37 "Query": { 38 filter: new OpenLayers.Filter.Spatial({ 39 type: OpenLayers.Filter.Spatial.BBOX, 40 value: new OpenLayers.Bounds (1,2,3,4) 41 })} 42 } 43 44 var arg; 45 for(var snippet in snippets) { 46 arg = snippets[snippet] 47 var expected = readXML(snippet); 48 var got = format.writers["wfs"][snippet].apply(format, [arg]); 49 t.xml_eq(got, expected, snippet + " request created correctly"); 50 } 51 } 52 53 function readXML(id) { 54 var xml = document.getElementById(id).firstChild.nodeValue; 55 return new OpenLayers.Format.XML().read(xml).documentElement; 56 } 57 58 </script> 59 </head> 60 <body> 61 <div id="map" style="width:512px; height:256px"> </div> 62 <div id="Transaction_Response"><!-- 63 <wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc"> 64 <wfs:InsertResult> 65 <ogc:FeatureId fid="none"/> 66 </wfs:InsertResult> 67 <wfs:TransactionResult> 68 <wfs:Status> 69 <wfs:SUCCESS/> 70 </wfs:Status> 71 </wfs:TransactionResult> 72 </wfs:WFS_TransactionResponse> 73 --></div> 74 <div id="Query"><!-- 75 <wfs:Query xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp"> 76 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> 77 <ogc:BBOX> 78 <ogc:PropertyName>the_geom</ogc:PropertyName> 79 <gml:Box xmlns:gml="http://www.opengis.net/gml"> 80 <gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates> 81 </gml:Box> 82 </ogc:BBOX> 83 </ogc:Filter> 84 </wfs:Query> 85 --></div> 86 </body> 87 </html> -
tests/Format/WFST/v1_1_0.html
old new 1 <html> 2 <head> 3 <script src="../../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"> 5 6 function test_initialize(t) { 7 t.plan(1); 8 9 var format = new OpenLayers.Format.WFST.v1_1_0({}); 10 t.ok(format instanceof OpenLayers.Format.WFST.v1_1_0, "constructor returns instance"); 11 } 12 13 function test_read(t) { 14 t.plan(2); 15 16 var data = readXML("TransactionResponse"); 17 var format = new OpenLayers.Format.WFST.v1_1_0({ 18 featureNS: "http://www.openplans.org/topp", 19 featureType: "states" 20 }); 21 var result = format.read(data); 22 t.eq(result.insertIds[0], "none", "InsertIds read correctly"); 23 t.eq(result.success, true, "Success read correctly"); 24 } 25 26 function test_write(t) { 27 28 var format = new OpenLayers.Format.WFST.v1_1_0({ 29 featureNS: "http://www.openplans.org/topp", 30 featureType: "states", 31 featurePrefix: "topp", 32 geometryName: "the_geom" 33 }); 34 35 t.plan(1); 36 var snippets = { 37 "Query": { 38 filter: new OpenLayers.Filter.Spatial({ 39 type: OpenLayers.Filter.Spatial.BBOX, 40 value: new OpenLayers.Bounds (1,2,3,4) 41 })} 42 } 43 44 var arg; 45 for(var snippet in snippets) { 46 arg = snippets[snippet] 47 var expected = readXML(snippet); 48 var got = format.writers["wfs"][snippet].apply(format, [arg]); 49 t.xml_eq(got, expected, snippet + " request created correctly"); 50 } 51 } 52 53 function readXML(id) { 54 var xml = document.getElementById(id).firstChild.nodeValue; 55 return new OpenLayers.Format.XML().read(xml).documentElement; 56 } 57 58 </script> 59 </head> 60 <body> 61 <div id="map" style="width:512px; height:256px"> </div> 62 <div id="TransactionResponse"><!-- 63 <wfs:TransactionResponse version="1.1.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:tiger="http://www.census.gov" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink"> 64 <wfs:TransactionSummary> 65 <wfs:totalInserted>0</wfs:totalInserted> 66 <wfs:totalUpdated>1</wfs:totalUpdated> 67 <wfs:totalDeleted>0</wfs:totalDeleted> 68 </wfs:TransactionSummary> 69 <wfs:TransactionResults/> 70 <wfs:InsertResults> 71 <wfs:Feature> 72 <ogc:FeatureId fid="none"/> 73 </wfs:Feature> 74 </wfs:InsertResults> 75 </wfs:TransactionResponse> 76 --></div> 77 <div id="Query"><!-- 78 <wfs:Query xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp"> 79 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> 80 <ogc:BBOX> 81 <ogc:PropertyName>the_geom</ogc:PropertyName> 82 <gml:Envelope xmlns:gml="http://www.opengis.net/gml"> 83 <gml:lowerCorner>1 2</gml:lowerCorner> 84 <gml:upperCorner>3 4</gml:upperCorner> 85 </gml:Envelope> 86 </ogc:BBOX> 87 </ogc:Filter> 88 </wfs:Query> 89 --></div> 90 </body> 91 </html> -
tests/Format/WFST/v1.html
old new 1 <html> 2 <head> 3 <script src="../../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"> 5 6 function test_read(t) { 7 t.plan(1); 8 9 var data = readXML("FeatureCollection"); 10 var format = new OpenLayers.Format.WFST({ 11 featureNS: "http://www.openplans.org/topp", 12 featureType: "states" 13 }); 14 var features = format.read(data); 15 16 t.eq(features.length, 1, "number of features read from FeatureCollection is correct"); 17 } 18 19 function test_write(t) { 20 21 var format = new OpenLayers.Format.WFST({ 22 featureNS: "http://www.openplans.org/topp", 23 featureType: "states", 24 featurePrefix: "topp", 25 geometryName: "the_geom" 26 }); 27 28 var feature = new OpenLayers.Feature.Vector( 29 new OpenLayers.Geometry.Point(1,2), 30 {foo: "bar"}); 31 32 var insertFeature = feature.clone(); 33 insertFeature.state = OpenLayers.State.INSERT; 34 var updateFeature = feature.clone(); 35 updateFeature.fid = "fid.42"; 36 updateFeature.state = OpenLayers.State.UPDATE; 37 var deleteFeature = feature.clone(); 38 deleteFeature.state = OpenLayers.State.DELETE; 39 deleteFeature.fid = "fid.37"; 40 41 t.plan(5); 42 var snippets = { 43 "GetFeature": {maxFeatures: 1}, 44 "Transaction": null, 45 "Insert": insertFeature, 46 "Update": updateFeature, 47 "Delete": deleteFeature 48 } 49 50 var arg; 51 for(var snippet in snippets) { 52 arg = snippets[snippet] 53 var expected = readXML(snippet); 54 var got = format.writers["wfs"][snippet].apply(format, [arg]); 55 t.xml_eq(got, expected, snippet + " request created correctly"); 56 } 57 } 58 59 function readXML(id) { 60 var xml = document.getElementById(id).firstChild.nodeValue; 61 return new OpenLayers.Format.XML().read(xml).documentElement; 62 } 63 64 </script> 65 </head> 66 <body> 67 <div id="map" style="width:512px; height:256px"> </div> 68 69 <div id="FeatureCollection"><!-- 70 <wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml"> 71 <gml:featureMember> 72 <topp:states fid="states.3"> 73 <topp:the_geom> 74 <gml:MultiPolygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"> 75 <gml:polygonMember> 76 <gml:Polygon> 77 <gml:outerBoundaryIs> 78 <gml:LinearRing> 79 <gml:coordinates decimal="." cs="," ts=" ">-75.70742,38.557476 -75.71106,38.649551 -75.724937,38.83017 -75.752922,39.141548 -75.761658,39.247753 -75.764664,39.295849 -75.772697,39.383007 -75.791435,39.723755 -75.775269,39.724442 -75.745934,39.774818 -75.695114,39.820347 -75.644341,39.838196 -75.583794,39.840008 -75.470345,39.826435 -75.42083,39.79887 -75.412117,39.789658 -75.428009,39.77813 -75.460754,39.763248 -75.475128,39.741718 -75.476334,39.719971 -75.489639,39.714745 -75.610725,39.612793 -75.562996,39.566723 -75.590187,39.463768 -75.515572,39.36694 -75.402481,39.257637 -75.397728,39.073036 -75.324852,39.012386 -75.307899,38.945911 -75.190941,38.80867 -75.083138,38.799812 -75.045998,38.44949 -75.068298,38.449963 -75.093094,38.450451 -75.350204,38.455208 -75.69915,38.463066 -75.70742,38.557476</gml:coordinates> 80 </gml:LinearRing> 81 </gml:outerBoundaryIs> 82 </gml:Polygon> 83 </gml:polygonMember> 84 </gml:MultiPolygon> 85 </topp:the_geom> 86 <topp:STATE_NAME>Delaware</topp:STATE_NAME> 87 <topp:STATE_FIPS>10</topp:STATE_FIPS> 88 <topp:SUB_REGION>S Atl</topp:SUB_REGION> 89 <topp:STATE_ABBR>DE</topp:STATE_ABBR> 90 <topp:LAND_KM>5062.456</topp:LAND_KM> 91 <topp:WATER_KM>1385.022</topp:WATER_KM> 92 <topp:PERSONS>666168.0</topp:PERSONS> 93 <topp:FAMILIES>175867.0</topp:FAMILIES> 94 <topp:HOUSHOLD>247497.0</topp:HOUSHOLD> 95 <topp:MALE>322968.0</topp:MALE> 96 <topp:FEMALE>343200.0</topp:FEMALE> 97 <topp:WORKERS>247566.0</topp:WORKERS> 98 <topp:DRVALONE>258087.0</topp:DRVALONE> 99 <topp:CARPOOL>42968.0</topp:CARPOOL> 100 <topp:PUBTRANS>8069.0</topp:PUBTRANS> 101 <topp:EMPLOYED>335147.0</topp:EMPLOYED> 102 <topp:UNEMPLOY>13945.0</topp:UNEMPLOY> 103 <topp:SERVICE>87973.0</topp:SERVICE> 104 <topp:MANUAL>44140.0</topp:MANUAL> 105 <topp:P_MALE>0.485</topp:P_MALE> 106 <topp:P_FEMALE>0.515</topp:P_FEMALE> 107 <topp:SAMP_POP>102776.0</topp:SAMP_POP> 108 </topp:states> 109 </gml:featureMember> 110 </wfs:FeatureCollection> 111 --></div> 112 113 <div id="GetFeature"><!-- 114 <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" maxFeatures="1" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 115 <wfs:Query typeName="topp:states" xmlns:topp="http://www.openplans.org/topp"/> 116 </wfs:GetFeature> 117 --></div> 118 <div id="Transaction"><!-- 119 <wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"/> 120 --></div> 121 <div id="Insert"><!-- 122 <wfs:Insert xmlns:wfs="http://www.opengis.net/wfs"> 123 <feature:states xmlns:feature="http://www.openplans.org/topp"> 124 <feature:the_geom> 125 <gml:Point xmlns:gml="http://www.opengis.net/gml"> 126 <gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates> 127 </gml:Point> 128 </feature:the_geom> 129 <feature:foo>bar</feature:foo> 130 </feature:states> 131 </wfs:Insert> 132 --></div> 133 <div id="Update"><!-- 134 <wfs:Update xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp"> 135 <wfs:Property> 136 <wfs:Name>the_geom</wfs:Name> 137 <wfs:Value> 138 <gml:Point xmlns:gml="http://www.opengis.net/gml"> 139 <gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates> 140 </gml:Point> 141 </wfs:Value> 142 </wfs:Property> 143 <wfs:Property> 144 <wfs:Name>foo</wfs:Name> 145 <wfs:Value>bar</wfs:Value> 146 </wfs:Property> 147 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> 148 <ogc:FeatureId fid="fid.42"/> 149 </ogc:Filter> 150 </wfs:Update> 151 --></div> 152 <div id="Delete"><!-- 153 <wfs:Delete xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp"> 154 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> 155 <ogc:FeatureId fid="fid.37"/> 156 </ogc:Filter> 157 </wfs:Delete> 158 --></div> 159 </body> 160 </html> -
tests/Format/WFST.html
old new 1 <html> 2 <head> 3 <script src="../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"> 5 6 function test_initialize(t) { 7 t.plan(2); 8 9 var format = new OpenLayers.Format.WFST(); 10 t.ok(format instanceof OpenLayers.Format.WFST.v1_0_0, "constructor returns instance with default versioned format"); 11 12 format = new OpenLayers.Format.WFST({ 13 version: "1.1.0" 14 }); 15 t.ok(format instanceof OpenLayers.Format.WFST.v1_1_0, "constructor returns instance with custom versioned format"); 16 } 17 18 </script> 19 </head> 20 <body> 21 <div id="map" style="width:512px; height:256px"> </div> 22 </body> 23 </html> -
tests/Protocol/WFS.html
old new 1 <html> 2 <head> 3 <script src="../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"> 5 6 function test_initialize(t) { 7 t.plan(2); 8 9 var protocol = new OpenLayers.Protocol.WFS({ 10 url: "http://some.url.org", 11 featureNS: "http://namespace.org", 12 featureType: "type" 13 }); 14 t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_0_0, 15 "initialize returns instance of default versioned protocol") 16 17 var protocol = new OpenLayers.Protocol.WFS({ 18 url: "http://some.url.org", 19 featureNS: "http://namespace.org", 20 featureType: "type", 21 version: "1.1.0" 22 }); 23 t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_1_0, 24 "initialize returns instance of custom versioned protocol") 25 } 26 27 function test_read(t) { 28 t.plan(6); 29 30 var protocol = new OpenLayers.Protocol.WFS({ 31 url: "http://some.url.org", 32 featureNS: "http://namespace.org", 33 featureType: "type", 34 parseFeatures: function(request) { 35 t.eq(request.responseText, "foo", "parseFeatures called properly"); 36 return "foo"; 37 } 38 }); 39 40 var _POST = OpenLayers.Request.POST; 41 42 var expected, status; 43 OpenLayers.Request.POST = function(obj) { 44 t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeature request is correct"); 45 obj.status = status; 46 obj.responseText = "foo"; 47 obj.options = {}; 48 t.delay_call(0.1, function() {obj.callback.call(this)}); 49 return obj; 50 }; 51 52 expected = readXML("GetFeature_1"); 53 status = 200; 54 var response = protocol.read({callback: function(response) { 55 t.eq(response.features, "foo", "user callback properly called with features"); 56 t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly"); 57 }}); 58 59 options = { 60 maxFeatures: 10, 61 featureType: 'type2', 62 srsName: 'EPSG:900913', 63 featureNS: 'htttp://alternative.namespace.org', 64 callback: function(response) { 65 t.eq(response.code, OpenLayers.Protocol.Response.FAILURE, "failure reported properly to user callback"); 66 } 67 }; 68 expected = readXML("GetFeature_2"); 69 status = 400; 70 var response = protocol.read(options); 71 72 OpenLayers.Request.POST = _POST; 73 } 74 75 function test_commit(t){ 76 t.plan(4); 77 78 var url = "http://some.url.org"; 79 var protocol = new OpenLayers.Protocol.WFS({ 80 url: url, 81 featureNS: "http://namespace.org", 82 featureType: "type" 83 }); 84 protocol.format.read = function(data) { 85 t.eq(data, "foo", "callback called with correct argument"); 86 return { 87 insertIds: new Array(3), 88 success: true 89 } 90 }; 91 92 var _POST = OpenLayers.Request.POST; 93 94 var expected; 95 OpenLayers.Request.POST = function(obj) { 96 t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "Transaction XML with Insert, Update and Delete created correctly"); 97 obj.responseText = "foo"; 98 obj.options = {}; 99 t.delay_call(0.1, function() {obj.callback.call(this)}); 100 return obj; 101 }; 102 103 var featureDelete = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(42, 7), {has : "cheeseburger"}); 104 featureDelete.fid = "fid.37"; 105 featureDelete.state = OpenLayers.State.DELETE; 106 featureDelete.layer = { 107 projection: { 108 getCode : function(){ 109 return "EPSG:4326"; 110 } 111 } 112 } 113 var featureInsert = featureDelete.clone(); 114 featureInsert.state = OpenLayers.State.INSERT; 115 var featureModify = featureDelete.clone(); 116 featureModify.fid = "fid.37"; 117 featureModify.state = OpenLayers.State.UPDATE; 118 119 options = { 120 featureNS: "http://some.namespace.org", 121 featureType: "type", 122 callback: function(response) { 123 t.eq(response.insertIds.length, 3, "correct response passed to user callback"); 124 t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success properly reported to user callback"); 125 } 126 } 127 128 expected = readXML("commit"); 129 var response = protocol.commit([featureInsert, featureModify, featureDelete], options); 130 131 OpenLayers.Request.POST = _POST; 132 133 } 134 135 function test_filterDelete(t) { 136 t.plan(2) 137 138 var url = "http://some.url.org"; 139 var protocol = new OpenLayers.Protocol.WFS({ 140 url: url, 141 featureNS: "http://namespace.org", 142 featureType: "type" 143 }); 144 145 var filter = new OpenLayers.Filter.Spatial({ 146 type: OpenLayers.Filter.Spatial.BBOX, 147 value: new OpenLayers.Bounds(-5, -5, 5, 5) 148 }); 149 150 var _POST = OpenLayers.Request.POST; 151 152 var expected = readXML("filter_delete"); 153 OpenLayers.Request.POST = function(obj) { 154 t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "request data correct"); 155 t.delay_call(0.1, function() {obj.callback.call(this)}); 156 return obj; 157 }; 158 159 var response = protocol.filterDelete(filter, { 160 callback: function() { 161 t.ok("user callback function called"); 162 } 163 }); 164 165 OpenLayers.Request.POST = _POST; 166 } 167 168 function readXML(id) { 169 var xml = document.getElementById(id).firstChild.nodeValue; 170 return new OpenLayers.Format.XML().read(xml).documentElement; 171 } 172 173 </script> 174 </head> 175 <body> 176 <div id="map" style="width:512px; height:256px"> </div> 177 <div id="GetFeature_1"><!-- 178 <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 179 <wfs:Query typeName="feature:type" xmlns:feature="http://namespace.org"/> 180 </wfs:GetFeature> 181 --></div> 182 <div id="GetFeature_2"><!-- 183 <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" maxFeatures="10" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 184 <wfs:Query typeName="feature:type2" xmlns:feature="htttp://alternative.namespace.org"/> 185 </wfs:GetFeature> 186 --></div> 187 <div id="commit"><!-- 188 <wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 189 <wfs:Insert> 190 <feature:type xmlns:feature="http://namespace.org"> 191 <feature:the_geom> 192 <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"> 193 <gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates> 194 </gml:Point> 195 </feature:the_geom> 196 <feature:has>cheeseburger</feature:has> 197 </feature:type> 198 </wfs:Insert> 199 <wfs:Update typeName="feature:type" xmlns:feature="http://namespace.org"> 200 <wfs:Property> 201 <wfs:Name>the_geom</wfs:Name> 202 <wfs:Value> 203 <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"> 204 <gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates> 205 </gml:Point> 206 </wfs:Value> 207 </wfs:Property> 208 <wfs:Property> 209 <wfs:Name>has</wfs:Name> 210 <wfs:Value>cheeseburger</wfs:Value> 211 </wfs:Property> 212 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> 213 <ogc:FeatureId fid="fid.37"/> 214 </ogc:Filter> 215 </wfs:Update> 216 <wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org"> 217 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> 218 <ogc:FeatureId fid="fid.37"/> 219 </ogc:Filter> 220 </wfs:Delete> 221 </wfs:Transaction> 222 --></div> 223 <div id="filter_delete"><!-- 224 <wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"> 225 <wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org"> 226 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> 227 <ogc:BBOX> 228 <ogc:PropertyName/> 229 <gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"> 230 <gml:coordinates decimal="." cs="," ts=" ">-5,-5 5,5</gml:coordinates> 231 </gml:Box> 232 </ogc:BBOX> 233 </ogc:Filter> 234 </wfs:Delete> 235 </wfs:Transaction> 236 --></div> 237 </body> 238 </html> -
tests/list-tests.html
old new 54 54 <li>Format/Filter.html</li> 55 55 <li>Format/Filter/v1_0_0.html</li> 56 56 <li>Format/Filter/v1_1_0.html</li> 57 <li>Format/WFST.html</li> 58 <li>Format/WFST/v1_0_0.html</li> 59 <li>Format/WFST/v1_1_0.html</li> 60 <li>Format/WFST/v1.html</li> 57 61 <li>Format/WKT.html</li> 58 62 <li>Format/WMC.html</li> 59 63 <li>Format/WMC/v1_1_0.html</li> … … 120 124 <li>Protocol/HTTP.html</li> 121 125 <li>Protocol/SQL.html</li> 122 126 <li>Protocol/SQL/Gears.html</li> 127 <li>Protocol/WFS.html</li> 123 128 <li>Renderer.html</li> 124 129 <li>Renderer/Canvas.html</li> 125 130 <li>Renderer/Elements.html</li> -
lib/OpenLayers/Format/WFST/v1_0_0.js
old new 1 /** 2 * @requires OpenLayers/Format/WFST/v1.js 3 * @requires OpenLayers/Format/GML/v2.js 4 * @requires OpenLayers/Format/Filter/v1_0_0.js 5 */ 6 7 /** 8 * Class: OpenLayers.Format.WFST.v1_0_0 9 * A format for creating WFS v1.0.0 transactions. Create a new instance with the 10 * <OpenLayers.Format.WFST.v1_0_0> constructor. 11 * 12 * Inherits from: 13 * - <OpenLayers.Format.WFST.v1> 14 */ 15 OpenLayers.Format.WFST.v1_0_0 = OpenLayers.Class(OpenLayers.Format.WFST.v1, { 16 17 /** 18 * Property: version 19 * {String} WFS version number. 20 */ 21 version: "1.0.0", 22 23 /** 24 * Property: schemaLocations 25 * {Object} Properties are namespace aliases, values are schema locations. 26 */ 27 schemaLocations: { 28 "wfs": "http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" 29 }, 30 31 /** 32 * Constructor: OpenLayers.Format.WFST.v1_0_0 33 * A class for parsing and generating WFS v1.0.0 transactions. 34 * 35 * Parameters: 36 * options - {Object} Optional object whose properties will be set on the 37 * instance. 38 * 39 * Valid options properties: 40 * featureType - {String} Local (without prefix) feature typeName (required). 41 * featureNS - {String} Feature namespace (optional). 42 * featurePrefix - {String} Feature namespace alias (optional - only used 43 * if featureNS is provided). Default is 'feature'. 44 * geometryName - {String} Name of geometry attribute. Default is 'the_geom'. 45 */ 46 initialize: function(options) { 47 OpenLayers.Format.WFST.v1.prototype.initialize.apply(this, [options]); 48 OpenLayers.Format.GML.v2.prototype.setGeometryTypes.call(this); 49 }, 50 51 /** 52 * Property: readers 53 * Contains public functions, grouped by namespace prefix, that will 54 * be applied when a namespaced node is found matching the function 55 * name. The function will be applied in the scope of this parser 56 * with two arguments: the node being read and a context object passed 57 * from the parent. 58 */ 59 readers: { 60 "wfs": OpenLayers.Util.applyDefaults({ 61 "WFS_TransactionResponse": function(node, obj) { 62 obj.insertIds = []; 63 obj.success = false; 64 this.readChildNodes(node, obj); 65 }, 66 "InsertResult": function(node, container) { 67 var obj = {fids: []}; 68 this.readChildNodes(node, obj); 69 container.insertIds.push(obj.fids[0]); 70 }, 71 "TransactionResult": function(node, obj) { 72 this.readChildNodes(node, obj); 73 }, 74 "Status": function(node, obj) { 75 this.readChildNodes(node, obj); 76 }, 77 "SUCCESS": function(node, obj) { 78 obj.success = true; 79 } 80 }, OpenLayers.Format.WFST.v1.prototype.readers["wfs"]), 81 "gml": OpenLayers.Format.GML.v2.prototype.readers["gml"], 82 "feature": OpenLayers.Format.GML.v2.prototype.readers["feature"], 83 "ogc": OpenLayers.Format.Filter.v1_0_0.prototype.readers["ogc"] 84 }, 85 86 /** 87 * Property: writers 88 * As a compliment to the readers property, this structure contains public 89 * writing functions grouped by namespace alias and named like the 90 * node names they produce. 91 */ 92 writers: { 93 "wfs": OpenLayers.Util.applyDefaults({ 94 "Query": function(options) { 95 options = OpenLayers.Util.extend({ 96 featureNS: this.featureNS, 97 featurePrefix: this.featurePrefix, 98 featureType: this.featureType, 99 srsName: this.srsName 100 }, options); 101 var node = this.createElementNSPlus("wfs:Query", { 102 attributes: { 103 typeName: (options.featureNS ? options.featurePrefix + ":" : "") + 104 options.featureType 105 } 106 }); 107 if(options.featureNS) { 108 node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS); 109 } 110 if(options.filter) { 111 this.setFilterProperty(options.filter); 112 this.writeNode("ogc:Filter", options.filter, node); 113 } 114 return node; 115 } 116 }, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]), 117 "gml": OpenLayers.Format.GML.v2.prototype.writers["gml"], 118 "feature": OpenLayers.Format.GML.v2.prototype.writers["feature"], 119 "ogc": OpenLayers.Format.Filter.v1_0_0.prototype.writers["ogc"] 120 }, 121 122 CLASS_NAME: "OpenLayers.Format.WFST.v1_0_0" 123 }); -
lib/OpenLayers/Format/WFST/v1_1_0.js
old new 1 /** 2 * @requires OpenLayers/Format/WFST/v1.js 3 * @requires OpenLayers/Format/GML/v3.js 4 * @requires OpenLayers/Format/Filter/v1_1_0.js 5 */ 6 7 /** 8 * Class: OpenLayers.Format.WFST.v1_1_0 9 * A format for creating WFS v1.1.0 transactions. Create a new instance with the 10 * <OpenLayers.Format.WFST.v1_1_0> constructor. 11 * 12 * Inherits from: 13 * - <OpenLayers.Format.WFST.v1> 14 */ 15 OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(OpenLayers.Format.WFST.v1, { 16 17 /** 18 * Property: version 19 * {String} WFS version number. 20 */ 21 version: "1.1.0", 22 23 /** 24 * Property: schemaLocations 25 * {Object} Properties are namespace aliases, values are schema locations. 26 */ 27 schemaLocations: { 28 "wfs": "http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" 29 }, 30 31 /** 32 * Constructor: OpenLayers.Format.WFST.v1_1_0 33 * A class for parsing and generating WFS v1.1.0 transactions. 34 * 35 * Parameters: 36 * options - {Object} Optional object whose properties will be set on the 37 * instance. 38 * 39 * Valid options properties: 40 * featureType - {String} Local (without prefix) feature typeName (required). 41 * featureNS - {String} Feature namespace (optional). 42 * featurePrefix - {String} Feature namespace alias (optional - only used 43 * if featureNS is provided). Default is 'feature'. 44 * geometryName - {String} Name of geometry attribute. Default is 'the_geom'. 45 */ 46 initialize: function(options) { 47 OpenLayers.Format.WFST.v1.prototype.initialize.apply(this, [options]); 48 OpenLayers.Format.GML.v3.prototype.setGeometryTypes.call(this); 49 }, 50 51 /** 52 * Property: readers 53 * Contains public functions, grouped by namespace prefix, that will 54 * be applied when a namespaced node is found matching the function 55 * name. The function will be applied in the scope of this parser 56 * with two arguments: the node being read and a context object passed 57 * from the parent. 58 */ 59 readers: { 60 "wfs": OpenLayers.Util.applyDefaults({ 61 "TransactionResponse": function(node, obj) { 62 obj.insertIds = []; 63 obj.success = false; 64 this.readChildNodes(node, obj); 65 }, 66 "TransactionSummary": function(node, obj) { 67 // this is a limited test of success 68 obj.success = true; 69 }, 70 "InsertResults": function(node, obj) { 71 this.readChildNodes(node, obj); 72 }, 73 "Feature": function(node, container) { 74 var obj = {fids: []}; 75 this.readChildNodes(node, obj); 76 container.insertIds.push(obj.fids[0]); 77 } 78 }, OpenLayers.Format.WFST.v1.prototype.readers["wfs"]), 79 "gml": OpenLayers.Format.GML.v3.prototype.readers["gml"], 80 "feature": OpenLayers.Format.GML.v3.prototype.readers["feature"], 81 "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.readers["ogc"] 82 }, 83 84 /** 85 * Property: writers 86 * As a compliment to the readers property, this structure contains public 87 * writing functions grouped by namespace alias and named like the 88 * node names they produce. 89 */ 90 writers: { 91 "wfs": OpenLayers.Util.applyDefaults({ 92 "Query": function(options) { 93 options = OpenLayers.Util.extend({ 94 featureNS: this.featureNS, 95 featurePrefix: this.featurePrefix, 96 featureType: this.featureType, 97 srsName: this.srsName 98 }, options); 99 var node = this.createElementNSPlus("wfs:Query", { 100 attributes: { 101 typeName: (options.featureNS ? options.featurePrefix + ":" : "") + 102 options.featureType, 103 srsName: options.srsName 104 } 105 }); 106 if(options.featureNS) { 107 node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS); 108 } 109 if(options.filter) { 110 this.setFilterProperty(options.filter); 111 this.writeNode("ogc:Filter", options.filter, node); 112 } 113 return node; 114 } 115 }, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]), 116 "gml": OpenLayers.Format.GML.v3.prototype.writers["gml"], 117 "feature": OpenLayers.Format.GML.v3.prototype.writers["feature"], 118 "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers["ogc"] 119 }, 120 121 CLASS_NAME: "OpenLayers.Format.WFST.v1_1_0" 122 }); -
lib/OpenLayers/Format/WFST/v1.js
old new 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/Format/XML.js 7 * @requires OpenLayers/Format/WFST.js 8 */ 9 10 /** 11 * Class: OpenLayers.Format.WFST.v1 12 * Superclass for WFST parsers. 13 * 14 * Inherits from: 15 * - <OpenLayers.Format.XML> 16 */ 17 OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { 18 19 /** 20 * Property: namespaces 21 * {Object} Mapping of namespace aliases to namespace URIs. 22 */ 23 namespaces: { 24 xlink: "http://www.w3.org/1999/xlink", 25 xsi: "http://www.w3.org/2001/XMLSchema-instance", 26 wfs: "http://www.opengis.net/wfs", 27 gml: "http://www.opengis.net/gml", 28 ogc: "http://www.opengis.net/ogc" 29 }, 30 31 /** 32 * Property: defaultPrefix 33 */ 34 defaultPrefix: "wfs", 35 36 /** 37 * Property: version 38 * {String} WFS version number. 39 */ 40 version: null, 41 42 /** 43 * Property: schemaLocation 44 * {String} Schema location for a particular minor version. 45 */ 46 schemaLocations: null, 47 48 /** 49 * APIProperty: srsName 50 * {String} URI for spatial reference system. 51 */ 52 srsName: null, 53 54 /** 55 * APIProperty: extractAttributes 56 * {Boolean} Extract attributes from GML. Default is true. 57 */ 58 extractAttributes: true, 59 60 /** 61 * APIProperty: xy 62 * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x) 63 * Changing is not recommended, a new Format should be instantiated. 64 */ 65 xy: true, 66 67 /** 68 * Property: stateName 69 * {Object} Maps feature states to node names. 70 */ 71 stateName: null, 72 73 /** 74 * Constructor: OpenLayers.Format.WFST.v1 75 * Instances of this class are not created directly. Use the 76 * <OpenLayers.Format.WFST.v1_0_0> or <OpenLayers.Format.WFST.v1_1_0> 77 * constructor instead. 78 * 79 * Parameters: 80 * options - {Object} An optional object whose properties will be set on 81 * this instance. 82 */ 83 initialize: function(options) { 84 if(options.featureNS) { 85 this.namespaces = OpenLayers.Util.extend( 86 {feature: options.featureNS}, 87 OpenLayers.Format.WFST.v1.prototype.namespaces 88 ); 89 } 90 // set state name mapping 91 this.stateName = {}; 92 this.stateName[OpenLayers.State.INSERT] = "wfs:Insert"; 93 this.stateName[OpenLayers.State.UPDATE] = "wfs:Update"; 94 this.stateName[OpenLayers.State.DELETE] = "wfs:Delete"; 95 // extend format with misc properties from filter and gml formats 96 var filterProto = OpenLayers.Format.Filter.v1.prototype; 97 var gmlProto = OpenLayers.Format.GML.Base.prototype; 98 OpenLayers.Util.extend(this, { 99 readOgcExpression: filterProto.readOgcExpression, 100 getFilterType: filterProto.getFilterType, 101 filterMap: filterProto.filterMap, 102 regExes: gmlProto.regExes 103 }); 104 OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); 105 }, 106 107 /** 108 * Method: getSrsName 109 */ 110 getSrsName: function(feature, options) { 111 var srsName = options && options.srsName; 112 if(!srsName) { 113 if(feature && feature.layer) { 114 srsName = feature.layer.projection.getCode(); 115 } else { 116 srsName = this.srsName; 117 } 118 } 119 return srsName; 120 }, 121 122 /** 123 * Method: read 124 * Parse the response from a transaction. Because WFS is split into 125 * Transaction requests (create, update, and delete) and GetFeature 126 * requests (read), this method handles parsing of both types of 127 * responses. 128 */ 129 read: function(data) { 130 if(typeof data == "string") { 131 data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); 132 } 133 if(data && data.nodeType == 9) { 134 data = data.documentElement; 135 } 136 var obj = {}; 137 this.readNode(data, obj); 138 if(obj.features) { 139 obj = obj.features; 140 } 141 return obj; 142 }, 143 144 /** 145 * Property: readers 146 * Contains public functions, grouped by namespace prefix, that will 147 * be applied when a namespaced node is found matching the function 148 * name. The function will be applied in the scope of this parser 149 * with two arguments: the node being read and a context object passed 150 * from the parent. 151 */ 152 readers: { 153 "wfs": { 154 "FeatureCollection": function(node, obj) { 155 obj.features = []; 156 this.readChildNodes(node, obj); 157 } 158 } 159 }, 160 161 /** 162 * Method: write 163 * Given an array of features, write a WFS transaction. This assumes 164 * the features have a state property that determines the operation 165 * type - insert, update, or delete. 166 * 167 * Parameters: 168 * features - {Array(<OpenLayers.Feature.Vector>)} A list of features. 169 * 170 * Returns: 171 * {String} A serialized WFS transaction. 172 */ 173 write: function(features) { 174 var node = this.writeNode("wfs:Transaction", features); 175 var value = this.schemaLocationAttr(); 176 if(value) { 177 this.setAttributeNS( 178 node, this.namespaces["xsi"], "xsi:schemaLocation", value 179 ) 180 } 181 return OpenLayers.Format.XML.prototype.write.apply(this, [node]); 182 }, 183 184 /** 185 * Property: writers 186 * As a compliment to the readers property, this structure contains public 187 * writing functions grouped by namespace alias and named like the 188 * node names they produce. 189 */ 190 writers: { 191 "wfs": { 192 "GetFeature": function(options) { 193 var node = this.createElementNSPlus("wfs:GetFeature", { 194 attributes: { 195 service: "WFS", 196 version: this.version, 197 maxFeatures: options && options.maxFeatures, 198 "xsi:schemaLocation": this.schemaLocationAttr(options) 199 } 200 }); 201 this.writeNode("Query", options, node); 202 return node; 203 }, 204 "Query": function(options) { 205 options = OpenLayers.Util.extend({ 206 featureNS: this.featureNS, 207 featurePrefix: this.featurePrefix, 208 featureType: this.featureType, 209 srsName: this.srsName 210 }, options); 211 // TODO: this is still version specific and should be separated out 212 // v1.0.0 does not allow srsName on wfs:Query 213 var node = this.createElementNSPlus("wfs:Query", { 214 attributes: { 215 typeName: (options.featureNS ? options.featurePrefix + ":" : "") + 216 options.featureType, 217 srsName: options.srsName 218 } 219 }); 220 if(options.featureNS) { 221 node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS); 222 } 223 if(options.filter) { 224 this.setFilterProperty(options.filter); 225 this.writeNode("ogc:Filter", options.filter, node); 226 } 227 return node; 228 }, 229 "Transaction": function(features) { 230 var node = this.createElementNSPlus("wfs:Transaction", { 231 attributes: { 232 service: "WFS", 233 version: this.version 234 } 235 }); 236 if(features) { 237 var name, feature; 238 for(var i=0, len=features.length; i<len; ++i) { 239 feature = features[i]; 240 name = this.stateName[feature.state]; 241 if(name) { 242 this.writeNode(name, feature, node); 243 } 244 } 245 } 246 return node; 247 }, 248 "Insert": function(feature) { 249 var node = this.createElementNSPlus("wfs:Insert"); 250 this.srsName = this.getSrsName(feature); 251 this.writeNode("feature:_typeName", feature, node); 252 return node; 253 }, 254 "Update": function(feature) { 255 var node = this.createElementNSPlus("wfs:Update", { 256 attributes: { 257 typeName: (this.featureNS ? this.featurePrefix + ":" : "") + 258 this.featureType 259 } 260 }); 261 if(this.featureNS) { 262 node.setAttribute("xmlns:" + this.featurePrefix, this.featureNS); 263 } 264 265 // add in geometry 266 this.writeNode( 267 "Property", {name: this.geometryName, value: feature}, node 268 ); 269 270 // add in attributes 271 for(var key in feature.attributes) { 272 this.writeNode( 273 "Property", {name: key, value: feature.attributes[key]}, node 274 ); 275 } 276 277 // add feature id filter 278 this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({ 279 fids: [feature.fid] 280 }), node); 281 282 return node; 283 }, 284 "Property": function(obj) { 285 var node = this.createElementNSPlus("wfs:Property"); 286 this.writeNode("Name", obj.name, node); 287 this.writeNode("Value", obj.value, node); 288 return node; 289 }, 290 "Name": function(name) { 291 return this.createElementNSPlus("wfs:Name", {value: name}); 292 }, 293 "Value": function(obj) { 294 var node; 295 if(obj instanceof OpenLayers.Feature.Vector) { 296 node = this.createElementNSPlus("wfs:Value"); 297 this.srsName = this.getSrsName(obj); 298 var geom = this.writeNode("feature:_geometry", obj.geometry).firstChild; 299 node.appendChild(geom); 300 } else { 301 node = this.createElementNSPlus("wfs:Value", {value: obj}); 302 } 303 return node; 304 }, 305 "Delete": function(feature) { 306 var node = this.createElementNSPlus("wfs:Delete", { 307 attributes: { 308 typeName: (this.featureNS ? this.featurePrefix + ":" : "") + 309 this.featureType 310 } 311 }); 312 if(this.featureNS) { 313 node.setAttribute("xmlns:" + this.featurePrefix, this.featureNS); 314 } 315 this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({ 316 fids: [feature.fid] 317 }), node); 318 return node; 319 } 320 } 321 }, 322 323 /** 324 * Method: schemaLocationAttr 325 * Generate the xsi:schemaLocation attribute value. 326 * 327 * Returns: 328 * {String} The xsi:schemaLocation attribute or undefined if none. 329 */ 330 schemaLocationAttr: function(options) { 331 options = OpenLayers.Util.extend({ 332 featurePrefix: this.featurePrefix, 333 schema: this.schema 334 }, options); 335 var schemaLocations = OpenLayers.Util.extend({}, this.schemaLocations); 336 if(options.schema) { 337 schemaLocations[options.featurePrefix] = options.schema; 338 } 339 var parts = []; 340 var uri; 341 for(var key in schemaLocations) { 342 uri = this.namespaces[key]; 343 if(uri) { 344 parts.push(uri + " " + schemaLocations[key]); 345 } 346 } 347 var value = parts.join(" ") || undefined; 348 return value; 349 }, 350 351 /** 352 * Method: setFilterProperty 353 * Set the property of each spatial filter. 354 * 355 * Parameters: 356 * filter - {<OpenLayers.Filter>} 357 */ 358 setFilterProperty: function(filter) { 359 if(filter.filters) { 360 for(var i=0, len=filter.filters.length; i<len; ++i) { 361 this.setFilterProperty(filter.filters[i]); 362 } 363 } else { 364 if(filter instanceof OpenLayers.Filter.Spatial) { 365 // got a spatial filter, set its property 366 filter.property = this.geometryName; 367 } 368 } 369 }, 370 371 CLASS_NAME: "OpenLayers.Format.WFST.v1" 372 373 }); -
lib/OpenLayers/Format/WFST.js
old new 1 /** 2 * @requires OpenLayers/Format.js 3 */ 4 5 /** 6 * Function: OpenLayers.Format.WFST 7 * Used to create a versioned WFS protocol. Default version is 1.0.0. 8 * 9 * Returns: 10 * {<OpenLayers.Format>} A WFST format of the given version. 11 */ 12 OpenLayers.Format.WFST = function(options) { 13 options = OpenLayers.Util.applyDefaults( 14 options, OpenLayers.Format.WFST.DEFAULTS 15 ); 16 var cls = OpenLayers.Format.WFST["v"+options.version.replace(/\./g, "_")]; 17 if(!cls) { 18 throw "Unsupported WFST version: " + options.version; 19 } 20 return new cls(options); 21 } 22 23 /** 24 * Constant: OpenLayers.Format.WFST.DEFAULTS 25 * {Object} Default properties for the WFST format. 26 */ 27 OpenLayers.Format.WFST.DEFAULTS = { 28 "version": "1.0.0" 29 }; -
lib/OpenLayers/Protocol/WFS/v1_0_0.js
old new 1 /** 2 * @requires OpenLayers/Protocol/WFS/v1.js 3 * @requires OpenLayers/Format/WFST/v1_0_0.js 4 */ 5 6 /** 7 * Class: OpenLayers.Protocol.WFS.v1_0_0 8 * A WFS v1.0.0 protocol for vector layers. Create a new instance with the 9 * <OpenLayers.Protocol.WFS.v1_0_0> constructor. 10 * 11 * Inherits from: 12 * - <OpenLayers.Protocol.WFS.v1> 13 */ 14 OpenLayers.Protocol.WFS.v1_0_0 = OpenLayers.Class(OpenLayers.Protocol.WFS.v1, { 15 16 /** 17 * Property: version 18 * {String} WFS version number. 19 */ 20 version: "1.0.0", 21 22 /** 23 * Constructor: OpenLayers.Protocol.WFS.v1_0_0 24 * A class for giving layers WFS v1.0.0 protocol. 25 * 26 * Parameters: 27 * options - {Object} Optional object whose properties will be set on the 28 * instance. 29 * 30 * Valid options properties: 31 * featureType - {String} Local (without prefix) feature typeName (required). 32 * featureNS - {String} Feature namespace (optional). 33 * featurePrefix - {String} Feature namespace alias (optional - only used 34 * if featureNS is provided). Default is 'feature'. 35 * geometryName - {String} Name of geometry attribute. Default is 'the_geom'. 36 */ 37 38 CLASS_NAME: "OpenLayers.Protocol.WFS.v1_0_0" 39 }); -
lib/OpenLayers/Protocol/WFS/v1_1_0.js
old new 1 /** 2 * @requires OpenLayers/Protocol/WFS/v1.js 3 * @requires OpenLayers/Format/WFST/v1_1_0.js 4 */ 5 6 /** 7 * Class: OpenLayers.Protocol.WFS.v1_1_0 8 * A WFS v1.1.0 protocol for vector layers. Create a new instance with the 9 * <OpenLayers.Protocol.WFS.v1_1_0> constructor. 10 * 11 * Differences from the v1.0.0 protocol: 12 * - uses Filter Encoding 1.1.0 instead of 1.0.0 13 * - uses GML 3 instead of 2 if no format is provided 14 * 15 * Inherits from: 16 * - <OpenLayers.Protocol.WFS.v1> 17 */ 18 OpenLayers.Protocol.WFS.v1_1_0 = OpenLayers.Class(OpenLayers.Protocol.WFS.v1, { 19 20 /** 21 * Property: version 22 * {String} WFS version number. 23 */ 24 version: "1.1.0", 25 26 /** 27 * Constructor: OpenLayers.Protocol.WFS.v1_1_0 28 * A class for giving layers WFS v1.1.0 protocol. 29 * 30 * Parameters: 31 * options - {Object} Optional object whose properties will be set on the 32 * instance. 33 * 34 * Valid options properties: 35 * featureType - {String} Local (without prefix) feature typeName (required). 36 * featureNS - {String} Feature namespace (optional). 37 * featurePrefix - {String} Feature namespace alias (optional - only used 38 * if featureNS is provided). Default is 'feature'. 39 * geometryName - {String} Name of geometry attribute. Default is 'the_geom'. 40 */ 41 42 CLASS_NAME: "OpenLayers.Protocol.WFS.v1_1_0" 43 }); -
lib/OpenLayers/Protocol/WFS/v1.js
old new 1 /** 2 * @requires OpenLayers/Protocol/WFS.js 3 */ 4 5 /** 6 * Class: OpenLayers.Protocol.WFS.v1 7 * Abstract class for for v1.0.0 and v1.1.0 protocol. 8 * 9 * Inherits from: 10 * - <OpenLayers.Protocol> 11 */ 12 OpenLayers.Protocol.WFS.v1 = new OpenLayers.Class(OpenLayers.Protocol, { 13 14 /** 15 * Property: version 16 * {String} WFS version number. 17 */ 18 version: null, 19 20 /** 21 * Property: srsName 22 * {String} Name of spatial reference system. Default is "EPSG:4326". 23 */ 24 srsName: "EPSG:4326", 25 26 /** 27 * Property: featureType 28 * {String} Local feature typeName. 29 */ 30 featureType: null, 31 32 /** 33 * Property: featureNS 34 * {String} Feature namespace. 35 */ 36 featureNS: null, 37 38 /** 39 * Property: geometryName 40 * {String} Name of the geometry attribute for features. Default is 41 * "the_geom". 42 */ 43 geometryName: "the_geom", 44 45 /** 46 * Property: schema 47 * {String} Optional schema location that will be included in the 48 * schemaLocation attribute value. Note that the feature type schema 49 * is required for a strict XML validator (on transactions with an 50 * insert for example), but is *not* required by the WFS specification 51 * (since the server is supposed to know about feature type schemas). 52 */ 53 schema: null, 54 55 /** 56 * Property: featurePrefix 57 * {String} Namespace alias for feature type. Default is "feature". 58 */ 59 featurePrefix: "feature", 60 61 /** 62 * Property: formatOptions 63 * {Object} Optional options for the format. If a format is not provided, 64 * this property can be used to extend the default format options. 65 */ 66 formatOptions: null, 67 68 /** 69 * Constructor: OpenLayers.Protocol.WFS 70 * A class for giving layers WFS protocol. 71 * 72 * Parameters: 73 * options - {Object} Optional object whose properties will be set on the 74 * instance. 75 * 76 * Valid options properties: 77 * url - {String} URL to send requests to (required). 78 * featureType - {String} Local (without prefix) feature typeName (required). 79 * featureNS - {String} Feature namespace (required, but can be autodetected 80 * for reading if featurePrefix is provided and identical to the prefix 81 * in the server response). 82 * featurePrefix - {String} Feature namespace alias (optional - only used 83 * for writing if featureNS is provided). Default is 'feature'. 84 * geometryName - {String} Name of geometry attribute. Default is 'the_geom'. 85 */ 86 initialize: function(options) { 87 OpenLayers.Protocol.prototype.initialize.apply(this, [options]); 88 if(!options.format) { 89 this.format = OpenLayers.Format.WFST(OpenLayers.Util.extend({ 90 version: this.version, 91 featureType: this.featureType, 92 featureNS: this.featureNS, 93 featurePrefix: this.featurePrefix, 94 geometryName: this.geometryName, 95 srsName: this.srsName, 96 schema: this.schema 97 }, this.formatOptions)); 98 } 99 // featureNS autodetection 100 var readNode = this.format.readNode; 101 this.format.readNode = function(node, obj) { 102 if(!this.featureNS && node.prefix == this.featurePrefix) { 103 this.featureNS = node.namespaceURI; 104 this.setNamespace("feature", this.featureNS); 105 } 106 return readNode.apply(this, arguments); 107 } 108 }, 109 110 /** 111 * APIMethod: destroy 112 * Clean up the protocol. 113 */ 114 destroy: function() { 115 if(this.options && !this.options.format) { 116 this.format.destroy(); 117 } 118 this.format = null; 119 OpenLayers.Protocol.prototype.destroy.apply(this); 120 }, 121 122 /** 123 * Method: createCallback 124 * Returns a function that applies the given public method with resp and 125 * options arguments. 126 * 127 * Parameters: 128 * method - {Function} The method to be applied by the callback. 129 * response - {<OpenLayers.Protocol.Response>} The protocol response object. 130 * options - {Object} Options sent to the protocol method (read, create, 131 * update, or delete). 132 */ 133 createCallback: function(method, response, options) { 134 return OpenLayers.Function.bind(function() { 135 method.apply(this, [response, options]); 136 }, this); 137 }, 138 139 /** 140 * Method: read 141 * Construct a request for reading new features. Since WFS splits the 142 * basic CRUD operations into GetFeature requests (for read) and 143 * Transactions (for all others), this method does not make use of the 144 * format's read method (that is only about reading transaction 145 * responses). 146 */ 147 read: function(options) { 148 options = OpenLayers.Util.extend({}, options); 149 OpenLayers.Util.applyDefaults(options, this.options || {}); 150 var response = new OpenLayers.Protocol.Response({requestType: "read"}); 151 152 var data = OpenLayers.Format.XML.prototype.write.apply( 153 this.format, [this.format.writeNode("wfs:GetFeature", options)] 154 ); 155 156 response.priv = OpenLayers.Request.POST({ 157 url: options.url, 158 callback: this.createCallback(this.handleRead, response, options), 159 params: options.params, 160 headers: options.headers, 161 data: data 162 }); 163 164 return response; 165 }, 166 167 /** 168 * Method: handleRead 169 * Deal with response from the read request. 170 * 171 * Parameters: 172 * response - {<OpenLayers.Protocol.Response>} The response object to pass 173 * to the user callback. 174 * options - {Object} The user options passed to the read call. 175 */ 176 handleRead: function(response, options) { 177 if(options.callback) { 178 var request = response.priv; 179 if(request.status >= 200 && request.status < 300) { 180 // success 181 response.features = this.parseFeatures(request); 182 response.code = OpenLayers.Protocol.Response.SUCCESS; 183 } else { 184 // failure 185 response.code = OpenLayers.Protocol.Response.FAILURE; 186 } 187 options.callback.call(options.scope, response); 188 }; 189 }, 190 191 /** 192 * Method: parseFeatures 193 * Read HTTP response body and return features 194 * 195 * Parameters: 196 * request - {XMLHttpRequest} The request object 197 * 198 * Returns: 199 * {Array({<OpenLayers.Feature.Vector>})} or 200 * {<OpenLayers.Feature.Vector>} Array of features or a single feature. 201 */ 202 parseFeatures: function(request) { 203 var doc = request.responseXML; 204 if(!doc || !doc.documentElement) { 205 doc = request.responseText; 206 } 207 if(!doc || doc.length <= 0) { 208 return null; 209 } 210 return this.format.read(doc); 211 }, 212 213 /** 214 * Method: commit 215 * Given a list of feature, assemble a batch request for update, create, 216 * and delete transactions. A commit call on the prototype amounts 217 * to writing a WFS transaction - so the write method on the format 218 * is used. 219 * 220 * Parameters: 221 * features - {Array(<OpenLayers.Feature.Vector>} 222 * 223 * Returns: 224 * {<OpenLayers.Protocol.Response>} A response object with a features 225 * property containing any insertIds and a priv property referencing 226 * the XMLHttpRequest object. 227 */ 228 commit: function(features, options) { 229 230 options = OpenLayers.Util.extend({}, options); 231 OpenLayers.Util.applyDefaults(options, this.options); 232 233 var response = new OpenLayers.Protocol.Response({ 234 requestType: "commit", 235 reqFeatures: features 236 }); 237 response.priv = OpenLayers.Request.POST({ 238 url: options.url, 239 data: this.format.write(features, options), 240 callback: this.createCallback(this.handleCommit, response, options) 241 }); 242 243 return response; 244 }, 245 246 /** 247 * Method: handleCommit 248 * Called when the commit request returns. 249 * 250 * Parameters: 251 * response - {<OpenLayers.Protocol.Response>} The response object to pass 252 * to the user callback. 253 * options - {Object} The user options passed to the commit call. 254 */ 255 handleCommit: function(response, options) { 256 if(options.callback) { 257 var request = response.priv; 258 259 // ensure that we have an xml doc 260 var data = request.responseXML; 261 if(!data || !data.documentElement) { 262 data = request.responseText; 263 } 264 265 var obj = this.format.read(data) || {}; 266 267 response.insertIds = obj.insertIds || []; 268 response.code = (obj.success) ? 269 OpenLayers.Protocol.Response.SUCCESS : 270 OpenLayers.Protocol.Response.FAILURE; 271 options.callback.call(options.scope, response); 272 } 273 }, 274 275 /** 276 * Method: filterDelete 277 * Send a request that deletes all features by their filter. 278 * 279 * Parameters: 280 * filter - {OpenLayers.Filter} filter 281 */ 282 filterDelete: function(filter, options) { 283 options = OpenLayers.Util.extend({}, options); 284 OpenLayers.Util.applyDefaults(options, this.options); 285 286 var response = new OpenLayers.Protocol.Response({ 287 requestType: "commit" 288 }); 289 290 var root = this.format.createElementNSPlus("wfs:Transaction", { 291 attributes: { 292 service: "WFS", 293 version: this.version 294 } 295 }); 296 297 var deleteNode = this.format.createElementNSPlus("wfs:Delete", { 298 attributes: { 299 typeName: (options.featureNS ? this.featurePrefix + ":" : "") + 300 options.featureType 301 } 302 }); 303 304 if(options.featureNS) { 305 deleteNode.setAttribute("xmlns:" + this.featurePrefix, options.featureNS); 306 } 307 var filterNode = this.format.writeNode("ogc:Filter", filter); 308 309 deleteNode.appendChild(filterNode); 310 311 root.appendChild(deleteNode); 312 313 var data = OpenLayers.Format.XML.prototype.write.apply( 314 this.format, [root] 315 ); 316 317 return OpenLayers.Request.POST({ 318 url: this.url, 319 callback : options.callback || function(){}, 320 data: data 321 }); 322 323 }, 324 325 CLASS_NAME: "OpenLayers.Protocol.WFS.v1" 326 }); -
lib/OpenLayers/Protocol/WFS.js
old new 1 /** 2 * @requires OpenLayers/Protocol.js 3 */ 4 5 /** 6 * Function: OpenLayers.Protocol.WFS 7 * Used to create a versioned WFS protocol. Default version is 1.0.0. 8 * 9 * Returns: 10 * {<OpenLayers.Protocol>} A WFS protocol of the given version. 11 */ 12 OpenLayers.Protocol.WFS = function(options) { 13 options = OpenLayers.Util.applyDefaults( 14 options, OpenLayers.Protocol.WFS.DEFAULTS 15 ); 16 var cls = OpenLayers.Protocol.WFS["v"+options.version.replace(/\./g, "_")]; 17 if(!cls) { 18 throw "Unsupported WFS version: " + options.version; 19 } 20 return new cls(options); 21 } 22 23 /** 24 * Constant: OpenLayers.Protocol.WFS.DEFAULTS 25 */ 26 OpenLayers.Protocol.WFS.DEFAULTS = { 27 "version": "1.0.0" 28 }; -
lib/OpenLayers.js
old new 193 193 "OpenLayers/Protocol/HTTP.js", 194 194 "OpenLayers/Protocol/SQL.js", 195 195 "OpenLayers/Protocol/SQL/Gears.js", 196 "OpenLayers/Protocol/WFS.js", 197 "OpenLayers/Protocol/WFS/v1.js", 198 "OpenLayers/Protocol/WFS/v1_0_0.js", 199 "OpenLayers/Protocol/WFS/v1_1_0.js", 196 200 "OpenLayers/Layer/PointTrack.js", 197 201 "OpenLayers/Layer/GML.js", 198 202 "OpenLayers/Style.js", … … 223 227 "OpenLayers/Format/SLD/v1.js", 224 228 "OpenLayers/Format/SLD/v1_0_0.js", 225 229 "OpenLayers/Format/SLD/v1.js", 230 "OpenLayers/Format/WFST.js", 231 "OpenLayers/Format/WFST/v1.js", 232 "OpenLayers/Format/WFST/v1_0_0.js", 233 "OpenLayers/Format/WFST/v1_1_0.js", 226 234 "OpenLayers/Format/Text.js", 227 235 "OpenLayers/Format/JSON.js", 228 236 "OpenLayers/Format/GeoJSON.js", -
examples/wfs-protocol.html
old new 1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>OpenLayers Vector Behavior Example</title> 4 <link rel="stylesheet" href="../theme/default/style.css" type="text/css" /> 5 <link rel="stylesheet" href="style.css" type="text/css" /> 6 <script src="../lib/Firebug/firebug.js"></script> 7 <script src="../lib/OpenLayers.js"></script> 8 <script type="text/javascript"> 9 var map; 10 11 function init() { 12 OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url="; 13 map = new OpenLayers.Map('map'); 14 var wms = new OpenLayers.Layer.WMS( 15 "OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0", 16 {layers: 'basic'} 17 ); 18 19 var layer = new OpenLayers.Layer.Vector("WFS", { 20 strategies: [new OpenLayers.Strategy.BBOX()], 21 protocol: new OpenLayers.Protocol.WFS({ 22 url: "http://publicus.opengeo.org/geoserver/wfs", 23 featureType: "tasmania_roads", 24 featureNS: "http://www.openplans.org/topp" 25 }), 26 }); 27 28 map.addLayers([wms, layer]); 29 map.setCenter(new OpenLayers.LonLat(146.7, -41.8), 6); 30 } 31 </script> 32 </head> 33 <body onload="init()"> 34 <h1 id="title">Vector Behavior Example</h1> 35 <p id="shortdesc"> 36 Uses a BBOX strategy, WFS protocol, and GML format. 37 </p> 38 <div id="map" class="smallmap"></div> 39 <div id="docs"> 40 <p>The vector layer shown uses the BBOX strategy, the WFS protocol, 41 and the GML format. The BBOX strategy fetches features within a 42 bounding box. When the map bounds invalidate the data bounds, 43 another request is triggered. The WFS protocol gets features 44 through a WFS request. The GML format is used to serialize 45 features.</p> 46 </div> 47 </body> 48 </html> -
examples/wfs-protocol-transactions.html
old new 1 <html> 2 <head> 3 <link rel="stylesheet" href="../theme/default/style.css" type="text/css" /> 4 <link rel="stylesheet" href="style.css" type="text/css" /> 5 <script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAbs-AXzXTiUE-iwvdTFv0TRTJUVlep-V_kcHWKMoAW7P0KYzoHRSbTZ4mBasJApBqjm2Vnrs7dKOYJg'></script> 6 <script src="../lib/OpenLayers.js"></script> 7 <style> 8 .customEditingToolbar { 9 float: right; 10 right: 0px; 11 height: 30px; 12 width: 200px; 13 } 14 .customEditingToolbar div { 15 float: right; 16 margin: 5px; 17 width: 24px; 18 height: 24px; 19 } 20 .olControlNavigationItemActive { 21 background-image: url("../theme/default/img/editing_tool_bar.png"); 22 background-repeat: no-repeat; 23 background-position: -103px -23px; 24 } 25 .olControlNavigationItemInactive { 26 background-image: url("../theme/default/img/editing_tool_bar.png"); 27 background-repeat: no-repeat; 28 background-position: -103px -0px; 29 } 30 .olControlDrawFeaturePolygonItemInactive { 31 background-image: url("../theme/default/img/editing_tool_bar.png"); 32 background-repeat: no-repeat; 33 background-position: -26px 0px; 34 } 35 .olControlDrawFeaturePolygonItemActive { 36 background-image: url("../theme/default/img/editing_tool_bar.png"); 37 background-repeat: no-repeat; 38 background-position: -26px -23px ; 39 } 40 .olControlModifyFeatureItemActive { 41 background-image: url(../theme/default/img/move_feature_on.png); 42 background-repeat: no-repeat; 43 background-position: 0px 1px; 44 } 45 .olControlModifyFeatureItemInactive { 46 background-image: url(../theme/default/img/move_feature_off.png); 47 background-repeat: no-repeat; 48 background-position: 0px 1px; 49 } 50 .olControlDeleteFeatureItemActive { 51 background-image: url(../theme/default/img/remove_point_on.png); 52 background-repeat: no-repeat; 53 background-position: 0px 1px; 54 } 55 .olControlDeleteFeatureItemInactive { 56 background-image: url(../theme/default/img/remove_point_off.png); 57 background-repeat: no-repeat; 58 background-position: 0px 1px; 59 } 60 </style> 61 <script type="text/javascript"> 62 var map, wfs; 63 64 var DeleteFeature = OpenLayers.Class(OpenLayers.Control, { 65 initialize: function(layer, options) { 66 OpenLayers.Control.prototype.initialize.apply(this, [options]); 67 this.layer = layer; 68 this.handler = new OpenLayers.Handler.Feature( 69 this, layer, {click: this.clickFeature} 70 ); 71 }, 72 clickFeature: function(feature) { 73 // if feature doesn't have a fid, destroy it 74 if(feature.fid == undefined) { 75 this.layer.destroyFeatures([feature]); 76 } else { 77 feature.state = OpenLayers.State.DELETE; 78 this.layer.events.triggerEvent("afterfeaturemodified", 79 {feature: feature}); 80 feature.renderIntent = "select"; 81 this.layer.drawFeature(feature); 82 } 83 }, 84 setMap: function(map) { 85 this.handler.setMap(map); 86 OpenLayers.Control.prototype.setMap.apply(this, arguments); 87 }, 88 CLASS_NAME: "OpenLayers.Control.DeleteFeature" 89 }); 90 91 function init() { 92 OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url="; 93 map = new OpenLayers.Map('map', { 94 projection: new OpenLayers.Projection("EPSG:900913"), 95 displayProjection: new OpenLayers.Projection("EPSG:4326"), 96 units: "m", 97 maxResolution: 156543.0339, 98 maxExtent: new OpenLayers.Bounds( 99 -11593508, 5509847, -11505759, 5557774 100 ), 101 controls: [ 102 new OpenLayers.Control.PanZoom() 103 ] 104 }); 105 var gphy = new OpenLayers.Layer.Google( 106 "Google Physical", 107 {type: G_PHYSICAL_MAP, sphericalMercator: true} 108 ); 109 110 var saveStrategy = new OpenLayers.Strategy.Save(); 111 112 wfs = new OpenLayers.Layer.Vector("Editable Features", { 113 strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy], 114 projection: new OpenLayers.Projection("EPSG:4326"), 115 protocol: new OpenLayers.Protocol.WFS({ 116 version: "1.1.0", 117 srsName: "EPSG:4326", 118 url: "http://demo.opengeo.org/geoserver/wfs?strict=true", 119 featureNS : "http://opengeo.org", 120 featureType: "restricted", 121 geometryName: "the_geom", 122 schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=opengeo:restricted" 123 }) 124 }); 125 126 map.addLayers([gphy, wfs]); 127 128 var panel = new OpenLayers.Control.Panel( 129 {'displayClass': 'customEditingToolbar'} 130 ); 131 132 var navigate = new OpenLayers.Control.Navigation({ 133 title: "Pan Map", 134 }); 135 136 var draw = new OpenLayers.Control.DrawFeature( 137 wfs, OpenLayers.Handler.Polygon, 138 { 139 title: "Draw Feature", 140 displayClass: "olControlDrawFeaturePolygon", 141 handlerOptions: {multi: true} 142 } 143 ); 144 145 var edit = new OpenLayers.Control.ModifyFeature(wfs, { 146 title: "Modify Feature", 147 displayClass: "olControlModifyFeature", 148 }); 149 150 var del = new DeleteFeature(wfs, {title: "Delete Feature"}); 151 152 var save = new OpenLayers.Control.Button({ 153 title: "Save Changes", 154 trigger: function() { 155 if(edit.feature) { 156 edit.selectControl.unselectAll(); 157 } 158 saveStrategy.save(); 159 }, 160 displayClass: "olControlSaveFeatures" 161 }); 162 163 panel.addControls([navigate, save, del, edit, draw]); 164 panel.defaultControl = navigate; 165 map.addControl(panel); 166 map.zoomToMaxExtent(); 167 } 168 169 </script> 170 </head> 171 <body onload="init()"> 172 173 <h1 id="title">WFS Transaction Example</h1> 174 175 <div id="tags"> 176 </div> 177 <p id="shortdesc"> 178 Shows the use of the WFS Transactions (WFS-T). 179 </p> 180 181 <div id="map" class="smallmap"></div> 182 183 <div id="docs"> 184 <p>The WFS protocol allows for creation of new features and reading, 185 updating, or deleting of existing features.</p> 186 <p>Use the tools to create, modify, and delete (in order from left 187 to right) features. Use the save tool (picture of a disk) to 188 save your changes. Use the navigation tool (hand) to stop editing 189 and use the mouse for map navigation.</p> 190 </div> 191 192 193 194 </body> 195 </html> 196 197
