add support for OpenLS (Location Utility Service), thanks cmoullet for the great example, p=me,r=cmoullet,erilem,fredj (closes #2953)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11781 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -329,6 +329,9 @@
|
||||
"OpenLayers/Format/OWSContext/v0_3_1.js",
|
||||
"OpenLayers/Format/WMTSCapabilities.js",
|
||||
"OpenLayers/Format/WMTSCapabilities/v1_0_0.js",
|
||||
"OpenLayers/Format/XLS.js",
|
||||
"OpenLayers/Format/XLS/v1.js",
|
||||
"OpenLayers/Format/XLS/v1_1_0.js",
|
||||
"OpenLayers/Layer/WFS.js",
|
||||
"OpenLayers/Control/GetFeature.js",
|
||||
"OpenLayers/Control/MouseToolbar.js",
|
||||
|
||||
118
lib/OpenLayers/Format/XLS.js
Normal file
118
lib/OpenLayers/Format/XLS.js
Normal file
@@ -0,0 +1,118 @@
|
||||
/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for
|
||||
* full list of contributors). Published under the Clear BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||
* full text of the license. */
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Format/XML.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.XLS
|
||||
* Read/Wite XLS (OpenLS). Create a new instance with the <OpenLayers.Format.XLS>
|
||||
* constructor. Currently only implemented for Location Utility Services, more
|
||||
* specifically only for Geocoding. No support for Reverse Geocoding as yet.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML>
|
||||
*/
|
||||
OpenLayers.Format.XLS = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
|
||||
/**
|
||||
* APIProperty: defaultVersion
|
||||
* {String} Version number to assume if none found. Default is "1.1.0".
|
||||
*/
|
||||
defaultVersion: "1.1.0",
|
||||
|
||||
/**
|
||||
* APIProperty: version
|
||||
* {String} Specify a version string if one is known.
|
||||
*/
|
||||
version: null,
|
||||
|
||||
/**
|
||||
* Property: parser
|
||||
* {Object} Instance of the versioned parser. Cached for multiple read and
|
||||
* write calls of the same version.
|
||||
*/
|
||||
parser: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.XLS
|
||||
* Create a new parser for XLS.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object whose properties will be set on
|
||||
* this instance.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: write
|
||||
* Write out an XLS request.
|
||||
*
|
||||
* Parameters:
|
||||
* request - {Object} An object representing the LUS request.
|
||||
* options - {Object} Optional configuration object.
|
||||
*
|
||||
* Returns:
|
||||
* {String} An XLS document string.
|
||||
*/
|
||||
write: function(request, options) {
|
||||
var version = (options && options.version) ||
|
||||
this.version || this.defaultVersion;
|
||||
if(!this.parser || this.parser.VERSION != version) {
|
||||
var format = OpenLayers.Format.XLS[
|
||||
"v" + version.replace(/\./g, "_")
|
||||
];
|
||||
if(!format) {
|
||||
throw "Can't find an XLS parser for version " +
|
||||
version;
|
||||
}
|
||||
this.parser = new format(this.options);
|
||||
}
|
||||
var root = this.parser.write(request);
|
||||
return OpenLayers.Format.XML.prototype.write.apply(this, [root]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: read
|
||||
* Read an XLS doc and return an object representing the result.
|
||||
*
|
||||
* Parameters:
|
||||
* data - {String | DOMElement} Data to read.
|
||||
* options - {Object} Options for the reader.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} An object representing the GeocodeResponse.
|
||||
*/
|
||||
read: function(data, options) {
|
||||
if(typeof data == "string") {
|
||||
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||
}
|
||||
var root = data.documentElement;
|
||||
var version = this.version;
|
||||
if(!version) {
|
||||
version = root.getAttribute("version");
|
||||
if(!version) {
|
||||
version = this.defaultVersion;
|
||||
}
|
||||
}
|
||||
if(!this.parser || this.parser.VERSION != version) {
|
||||
var format = OpenLayers.Format.XLS[
|
||||
"v" + version.replace(/\./g, "_")
|
||||
];
|
||||
if(!format) {
|
||||
throw "Can't find an XLS parser for version " +
|
||||
version;
|
||||
}
|
||||
this.parser = new format(this.options);
|
||||
}
|
||||
var xls = this.parser.read(data, options);
|
||||
return xls;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.XLS"
|
||||
});
|
||||
307
lib/OpenLayers/Format/XLS/v1.js
Normal file
307
lib/OpenLayers/Format/XLS/v1.js
Normal file
@@ -0,0 +1,307 @@
|
||||
/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for
|
||||
* full list of contributors). Published under the Clear BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||
* full text of the license. */
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Format/XLS.js
|
||||
* @requires OpenLayers/Format/GML/v3.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.XLS.v1
|
||||
* Superclass for XLS version 1 parsers. Only supports GeocodeRequest for now.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML>
|
||||
*/
|
||||
OpenLayers.Format.XLS.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
|
||||
/**
|
||||
* Property: namespaces
|
||||
* {Object} Mapping of namespace aliases to namespace URIs.
|
||||
*/
|
||||
namespaces: {
|
||||
xls: "http://www.opengis.net/xls",
|
||||
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
|
||||
*/
|
||||
defaultPrefix: "xls",
|
||||
|
||||
/**
|
||||
* Property: schemaLocation
|
||||
* {String} Schema location for a particular minor version.
|
||||
*/
|
||||
schemaLocation: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.XLS.v1
|
||||
* Instances of this class are not created directly. Use the
|
||||
* <OpenLayers.Format.XLS> constructor instead.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object whose properties will be set on
|
||||
* this instance.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: read
|
||||
*
|
||||
* Parameters:
|
||||
* data - {DOMElement} An XLS document element.
|
||||
* options - {Object} Options for the reader.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} An object representing the XLSResponse.
|
||||
*/
|
||||
read: function(data, options) {
|
||||
options = OpenLayers.Util.applyDefaults(options, this.options);
|
||||
var xls = {};
|
||||
this.readChildNodes(data, xls);
|
||||
return xls;
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: readers
|
||||
* Contains public functions, grouped by namespace prefix, that will
|
||||
* be applied when a namespaced node is found matching the function
|
||||
* name. The function will be applied in the scope of this parser
|
||||
* with two arguments: the node being read and a context object passed
|
||||
* from the parent.
|
||||
*/
|
||||
readers: {
|
||||
"xls": {
|
||||
"XLS": function(node, xls) {
|
||||
xls.version = node.getAttribute("version");
|
||||
this.readChildNodes(node, xls);
|
||||
},
|
||||
"Response": function(node, xls) {
|
||||
this.readChildNodes(node, xls);
|
||||
},
|
||||
"GeocodeResponse": function(node, xls) {
|
||||
xls.responseLists = [];
|
||||
this.readChildNodes(node, xls);
|
||||
},
|
||||
"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
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: write
|
||||
*
|
||||
* Parameters:
|
||||
* request - {Object} An object representing the geocode request.
|
||||
*
|
||||
* Returns:
|
||||
* {DOMElement} The root of an XLS document.
|
||||
*/
|
||||
write: function(request) {
|
||||
return this.writers.xls.XLS.apply(this, [request]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: writers
|
||||
* As a compliment to the readers property, this structure contains public
|
||||
* writing functions grouped by namespace alias and named like the
|
||||
* node names they produce.
|
||||
*/
|
||||
writers: {
|
||||
"xls": {
|
||||
"XLS": function(request) {
|
||||
var root = this.createElementNSPlus(
|
||||
"xls:XLS",
|
||||
{attributes: {
|
||||
"version": this.VERSION,
|
||||
"xsi:schemaLocation": this.schemaLocation
|
||||
}}
|
||||
);
|
||||
this.writeNode("RequestHeader", request.header, root);
|
||||
this.writeNode("Request", request, root);
|
||||
return root;
|
||||
},
|
||||
"RequestHeader": function(header) {
|
||||
return this.createElementNSPlus("xls:RequestHeader");
|
||||
},
|
||||
"Request": function(request) {
|
||||
var node = this.createElementNSPlus("xls:Request", {
|
||||
attributes: {
|
||||
methodName: "GeocodeRequest",
|
||||
requestID: request.requestID || "",
|
||||
version: this.VERSION
|
||||
}
|
||||
});
|
||||
this.writeNode("GeocodeRequest", request.addresses, node);
|
||||
return node;
|
||||
},
|
||||
"GeocodeRequest": function(addresses) {
|
||||
var node = this.createElementNSPlus("xls:GeocodeRequest");
|
||||
for (var i=0, len=addresses.length; i<len; i++) {
|
||||
this.writeNode("Address", addresses[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"Address": function(address) {
|
||||
var node = this.createElementNSPlus("xls:Address", {
|
||||
attributes: {
|
||||
countryCode: address.countryCode
|
||||
}
|
||||
});
|
||||
if (address.freeFormAddress) {
|
||||
this.writeNode("freeFormAddess", address.freeFormAddress, node);
|
||||
} else {
|
||||
if (address.street) {
|
||||
this.writeNode("StreetAddress", address, node);
|
||||
}
|
||||
if (address.municipality) {
|
||||
this.writeNode("Municipality", address.municipality, node);
|
||||
}
|
||||
if (address.countrySubdivision) {
|
||||
this.writeNode("CountrySubdivision", address.countrySubdivision, node);
|
||||
}
|
||||
if (address.postalCode) {
|
||||
this.writeNode("PostalCode", address.postalCode, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"freeFormAddress": function(freeFormAddress) {
|
||||
return this.createElementNSPlus("freeFormAddress",
|
||||
{value: freeFormAddress});
|
||||
},
|
||||
"StreetAddress": function(address) {
|
||||
var node = this.createElementNSPlus("xls:StreetAddress");
|
||||
if (address.building) {
|
||||
this.writeNode(node, "Building", address.building);
|
||||
}
|
||||
var street = address.street;
|
||||
if (!(street instanceof Array)) {
|
||||
street = [street];
|
||||
}
|
||||
for (var i=0, len=street.length; i < len; i++) {
|
||||
this.writeNode("Street", street[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"Building": function(building) {
|
||||
return this.createElementNSPlus("xls:Building", {
|
||||
attributes: {
|
||||
"number": building["number"],
|
||||
"subdivision": building.subdivision,
|
||||
"buildingName": building.buildingName
|
||||
}
|
||||
});
|
||||
},
|
||||
"Street": function(street) {
|
||||
return this.createElementNSPlus("xls:Street", {value: street});
|
||||
},
|
||||
"Municipality": function(municipality) {
|
||||
return this.createElementNSPlus("xls:Place", {
|
||||
attributes: {
|
||||
type: "Municipality"
|
||||
},
|
||||
value: municipality
|
||||
});
|
||||
},
|
||||
"CountrySubdivision": function(countrySubdivision) {
|
||||
return this.createElementNSPlus("xls:Place", {
|
||||
attributes: {
|
||||
type: "CountrySubdivision"
|
||||
},
|
||||
value: countrySubdivision
|
||||
});
|
||||
},
|
||||
"PostalCode": function(postalCode) {
|
||||
return this.createElementNSPlus("xls:PostalCode", {
|
||||
value: postalCode
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.XLS.v1"
|
||||
|
||||
});
|
||||
53
lib/OpenLayers/Format/XLS/v1_1_0.js
Normal file
53
lib/OpenLayers/Format/XLS/v1_1_0.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for
|
||||
* full list of contributors). Published under the Clear BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||
* full text of the license. */
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Format/XLS/v1.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.XLS.v1_1_0
|
||||
* Read / write XLS version 1.1.0.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XLS.v1>
|
||||
*/
|
||||
OpenLayers.Format.XLS.v1_1_0 = OpenLayers.Class(
|
||||
OpenLayers.Format.XLS.v1, {
|
||||
|
||||
/**
|
||||
* Constant: VERSION
|
||||
* {String} 1.1
|
||||
*/
|
||||
VERSION: "1.1",
|
||||
|
||||
/**
|
||||
* Property: schemaLocation
|
||||
* {String} http://www.opengis.net/xls
|
||||
* http://schemas.opengis.net/ols/1.1.0/LocationUtilityService.xsd
|
||||
*/
|
||||
schemaLocation: "http://www.opengis.net/xls http://schemas.opengis.net/ols/1.1.0/LocationUtilityService.xsd",
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.XLS.v1_1_0
|
||||
* Instances of this class are not created directly. Use the
|
||||
* <OpenLayers.Format.XLS> constructor instead.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object whose properties will be set on
|
||||
* this instance.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Format.XLS.v1.prototype.initialize.apply(
|
||||
this, [options]
|
||||
);
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.XLS.v1_1_0"
|
||||
|
||||
});
|
||||
|
||||
// Support non standard implementation
|
||||
OpenLayers.Format.XLS.v1_1 = OpenLayers.Format.XLS.v1_1_0;
|
||||
Reference in New Issue
Block a user