[OpenLayers-Commits] r10932 - in sandbox/bartvde/openls/openlayers: lib/OpenLayers/Format/XLS tests/Format/XLS

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Nov 30 10:17:52 EST 2010


Author: bartvde
Date: 2010-11-30 07:17:52 -0800 (Tue, 30 Nov 2010)
New Revision: 10932

Modified:
   sandbox/bartvde/openls/openlayers/lib/OpenLayers/Format/XLS/v1.js
   sandbox/bartvde/openls/openlayers/tests/Format/XLS/v1_1_0.html
Log:
more work on OpenLS, including tests

Modified: sandbox/bartvde/openls/openlayers/lib/OpenLayers/Format/XLS/v1.js
===================================================================
--- sandbox/bartvde/openls/openlayers/lib/OpenLayers/Format/XLS/v1.js	2010-11-30 10:34:17 UTC (rev 10931)
+++ sandbox/bartvde/openls/openlayers/lib/OpenLayers/Format/XLS/v1.js	2010-11-30 15:17:52 UTC (rev 10932)
@@ -9,7 +9,7 @@
 
 /**
  * Class: OpenLayers.Format.XLS.v1
- * Superclass for XLS version 1 parsers.
+ * Superclass for XLS version 1 parsers. Only supports GeocodeRequest for now.
  *
  * Inherits from:
  *  - <OpenLayers.Format.XML>
@@ -25,6 +25,24 @@
         gml: "http://www.opengis.net/gml",
         xsi: "http://www.w3.org/2001/XMLSchema-instance"
     },
+
+    /**
+     * Property: regExes
+     * Compiled regular expressions for manipulating strings.
+     */
+    regExes: {
+        trimSpace: (/^\s*|\s*$/g),
+        removeSpace: (/\s*/g),
+        splitSpace: (/\s+/),
+        trimComma: (/\s*,\s*/g)
+    },
+
+    /**
+     * APIProperty: xy
+     * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x)
+     * Changing is not recommended, a new Format should be instantiated.
+     */
+    xy: true,
     
     /**
      * Property: defaultPrefix
@@ -77,20 +95,78 @@
      */
     readers: {
         "xls": {
-            "StyledLayerDescriptor": function(node, sld) {
-                sld.version = node.getAttribute("version");
-                this.readChildNodes(node, sld);
+            "XLS": function(node, xls) {
+                xls.version = node.getAttribute("version");
+                this.readChildNodes(node, xls);
             },
-            "Name": function(node, obj) {
-                obj.name = this.getChildValue(node);
+            "Response": function(node, xls) {
+               this.readChildNodes(node, xls);
             },
-            "Title": function(node, obj) {
-                obj.title = this.getChildValue(node);
+            "GeocodeResponse": function(node, xls) {
+               xls.responseLists = [];
+               this.readChildNodes(node, xls);
             },
-            "Abstract": function(node, obj) {
-                obj.description = this.getChildValue(node);
+            "GeocodeResponseList": function(node, xls) {
+                var responseList = {
+                    features: [], 
+                    numberOfGeocodedAddresses: 
+                        parseInt(node.getAttribute("numberOfGeocodedAddresses"))
+                };
+                xls.responseLists.push(responseList);
+                this.readChildNodes(node, responseList);
+            },
+            "GeocodedAddress": function(node, responseList) {
+                var feature = new OpenLayers.Feature.Vector();
+                responseList.features.push(feature);
+                this.readChildNodes(node, feature);
+                // post-process geometry
+                feature.geometry = feature.components[0];
+            },
+            "GeocodeMatchCode": function(node, feature) {
+                feature.attributes.matchCode = {
+                    accuracy: parseFloat(node.getAttribute("accuracy")),
+                    matchType: node.getAttribute("matchType")
+                };
+            },
+            "Address": function(node, feature) {
+                var address = {
+                    countryCode: node.getAttribute("countryCode"),
+                    addressee: node.getAttribute("addressee"),
+                    street: [],
+                    place: []
+                };
+                feature.attributes.address = address;
+                this.readChildNodes(node, address);
+            },
+            "freeFormAddress": function(node, address) {
+                address.freeFormAddress = this.getChildValue(node);
+            },
+            "StreetAddress": function(node, address) {
+                this.readChildNodes(node, address);
+            },
+            "Building": function(node, address) {
+                address.building = {
+                    'number': node.getAttribute("number"),
+                    subdivision: node.getAttribute("subdivision"),
+                    buildingName: node.getAttribute("buildingName")
+                };
+            },
+            "Street": function(node, address) {
+                // only support the built-in primitive type for now
+                address.street.push(this.getChildValue(node));
+            },
+            "Place": function(node, address) {
+                // type is one of CountrySubdivision, 
+                // CountrySecondarySubdivision, Municipality or
+                // MunicipalitySubdivision
+                address.place[node.getAttribute("type")] = 
+                    this.getChildValue(node);
+            },
+            "PostalCode": function(node, address) {
+                address.postalCode = this.getChildValue(node);
             }
-        }
+        },
+        "gml": OpenLayers.Format.GML.v3.prototype.readers.gml
     },
     
     /**

Modified: sandbox/bartvde/openls/openlayers/tests/Format/XLS/v1_1_0.html
===================================================================
--- sandbox/bartvde/openls/openlayers/tests/Format/XLS/v1_1_0.html	2010-11-30 10:34:17 UTC (rev 10931)
+++ sandbox/bartvde/openls/openlayers/tests/Format/XLS/v1_1_0.html	2010-11-30 15:17:52 UTC (rev 10932)
@@ -2,6 +2,77 @@
 <head>
     <script src="../../../lib/OpenLayers.js"></script>
     <script type="text/javascript">
+    function test_read(t) {
+        t.plan(16);
+        var response = '<xls:GeocodeResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/xls http://schemas.opengis.net/ols/1.1.0/LocationUtilityService.xsd" xmlns:xls="http://www.opengis.net/xls" xmlns:gml="http://www.opengis.net/gml"><xls:GeocodeResponseList numberOfGeocodedAddresses="1"><xls:GeocodedAddress><gml:Point srsName="EPSG:28992"><gml:pos dimension="2">122650 483904</gml:pos></gml:Point><xls:Address countryCode="NL"><xls:StreetAddress><xls:Building number="1"/><xls:Street>president kennedylaan</xls:Street></xls:StreetAddress><xls:Place type="MunicipalitySubdivision">amsterdam</xls:Place><xls:Place type="Municipality">amsterdam</xls:Place><xls:Place type="CountrySubdivision">noord holland</xls:Place><xls:PostalCode>1079MB</xls:PostalCode></xls:Address></xls:GeocodedAddress></xls:GeocodeResponseList></xls:GeocodeResponse>';
+        var format = new OpenLayers.Format.XLS();
+        var output = format.read(response);
+        t.eq(output.responseLists.length, 1, "Output contains 1 responseList");
+        var responseList = output.responseLists[0];
+        t.eq(responseList.numberOfGeocodedAddresses, 1, "Responselist contains 1 geocoded address");
+        t.eq(responseList.features.length, 1, "1 feature parsed");
+        var feature = responseList.features[0];
+        var address = feature.attributes.address;
+        t.eq(address.building["number"], "1", "Building number correctly parsed");
+        t.eq(address.countryCode, "NL", "Country code correctly parsed");
+        t.eq(address.place.CountrySubdivision, "noord holland", "CountrySubDivision correctly parsed");
+        t.eq(address.place.Municipality, "amsterdam", "Municipality correctly parsed");
+        t.eq(address.place.MunicipalitySubdivision, "amsterdam", "MunicipalitySubdivision correctly parsed");
+        t.eq(address.postalCode, "1079MB", "Postalcode correctly parsed");
+        t.eq(address.street[0], "president kennedylaan", "Street correctly parsed");
+        t.eq(feature.geometry.x, 122650, "Geometry [x] correctly parsed");
+        t.eq(feature.geometry.y, 483904, "Geometry [y] correctly parsed");
+
+        var responseList = [];
+        responseList.push('<?xml version="1.0" encoding="UTF-8" ?>',
+'<XLS xmlns="http://www.opengis.net/xls" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/xls LocationUtilityService.xsd" version="1.1">',
+'	<ResponseHeader/>',
+'	<Response version="1.1" requestID="">',
+'		<GeocodeResponse>',
+'			<GeocodeResponseList numberOfGeocodedAddresses="2">',
+'				<GeocodedAddress>',
+'					<gml:Point>',
+'						<gml:pos>-71.4589837781615 41.8317239069808</gml:pos>',
+'					</gml:Point>',
+'					<Address countryCode="">',
+'						<StreetAddress>',
+'							<Street></Street>',
+'							<Street/>',
+'						</StreetAddress>',
+'						<Place type="Municipality"></Place>',
+'						<Place type="CountrySubdivision"></Place>',
+'						<PostalCode></PostalCode>',
+'					</Address>',
+'					<GeocodeMatchCode accuracy="100.0"/>',
+'				</GeocodedAddress>',
+'				<GeocodedAddress>',
+'					<gml:Point>',
+'						<gml:pos>-71.4087296631643 41.8269575002255</gml:pos>',
+'					</gml:Point>',
+'					<Address countryCode="">',
+'						<StreetAddress>',
+'							<Street></Street>',
+'							<Street/>',
+'						</StreetAddress>',
+'						<Place type="Municipality"></Place>',
+'						<Place type="CountrySubdivision"></Place>',
+'						<PostalCode></PostalCode>',
+'					</Address>',
+'					<GeocodeMatchCode accuracy="100.0"/>',
+'				</GeocodedAddress>',
+'			</GeocodeResponseList>',
+'		</GeocodeResponse>',
+'	</Response>',
+'</XLS>');
+        response = responseList.join("");
+        output = format.read(response);
+        t.eq(output.version, "1.1", "Version correctly parsed");
+        var responseList = output.responseLists[0];
+        t.eq(responseList.numberOfGeocodedAddresses, 2, "2 addresses parsed");
+        t.eq(responseList.features.length, 2, "2 features parsed");
+        t.eq(responseList.features[0].attributes.matchCode.accuracy, 100.0, "Accuracy correctly parsed");
+    }
+
     function test_write(t) {
         t.plan(1);
 



More information about the Commits mailing list