Fixes for the WMTS layer to properly update matrix related properties. Determining the best matrix in the set based on current map resolution. Properly parsing TopLeftCorner coordinates and providing a way to specify identifiers for backwards CRS. r=ahocevar (closes #2677)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10570 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-08-03 15:21:06 +00:00
parent f89fb1f226
commit 31afaf1fca
7 changed files with 217 additions and 81 deletions
@@ -51,6 +51,9 @@ OpenLayers.Format.OWSCommon.v1_1_0 = OpenLayers.Class(OpenLayers.Format.OWSCommo
},
"Identifier": function(node, obj) {
obj.identifier = this.getChildValue(node);
},
"SupportedCRS": function(node, obj) {
obj.supportedCRS = this.getChildValue(node);
}
}, OpenLayers.Format.OWSCommon.v1.prototype.readers["ows"])
},
+16 -3
View File
@@ -31,7 +31,20 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML, {
* Property: parser
* {<OpenLayers.Format>} A cached versioned format used for reading.
*/
parser: null,
parser: null,
/**
* APIProperty: yx
* {Object} Members in the yx object are used to determine if a CRS URN
* corresponds to a CRS with y,x axis order. Member names are CRS URNs
* and values are boolean. By default, the following CRS URN are
* assumed to correspond to a CRS with y,x axis order:
*
* * urn:ogc:def:crs:EPSG::4326
*/
yx: {
"urn:ogc:def:crs:EPSG::4326": true
},
/**
* Constructor: OpenLayers.Format.WMTSCapabilities
@@ -70,9 +83,9 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML, {
if (!constr) {
throw new Error("Can't find a WMTS capabilities parser for version " + version);
}
var parser = new constr(this.options);
this.parser = new constr(this.options);
}
return parser.read(data);
return this.parser.read(data);
},
/**
@@ -33,6 +33,15 @@ OpenLayers.Format.WMTSCapabilities.v1_0_0 = OpenLayers.Class(
xlink: "http://www.w3.org/1999/xlink"
},
/**
* Property: yx
* {Object} Members in the yx object are used to determine if a CRS URN
* corresponds to a CRS with y,x axis order. Member names are CRS URNs
* and values are boolean. Defaults come from the
* <OpenLayers.Format.WMTSCapabilities> prototype.
*/
yx: null,
/**
* Property: defaultPrefix
* {String} The default namespace alias for creating element nodes.
@@ -50,6 +59,10 @@ OpenLayers.Format.WMTSCapabilities.v1_0_0 = OpenLayers.Class(
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
this.options = options;
var yx = OpenLayers.Util.extend(
{}, OpenLayers.Format.WMTSCapabilities.prototype.yx
);
this.yx = OpenLayers.Util.extend(yx, this.yx);
},
/**
@@ -123,8 +136,9 @@ OpenLayers.Format.WMTSCapabilities.v1_0_0 = OpenLayers.Class(
// duck type wmts:Contents by looking for layers
if (obj.layers) {
// TileMatrixSet as object type in schema
var tileMatrixSet = {};
tileMatrixSet.matrixIds = [];
var tileMatrixSet = {
matrixIds: []
};
this.readChildNodes(node, tileMatrixSet);
obj.tileMatrixSets[tileMatrixSet.identifier] = tileMatrixSet;
} else {
@@ -133,7 +147,9 @@ OpenLayers.Format.WMTSCapabilities.v1_0_0 = OpenLayers.Class(
}
},
"TileMatrix": function(node, obj) {
var tileMatrix = {};
var tileMatrix = {
supportedCRS: obj.supportedCRS
};
this.readChildNodes(node, tileMatrix);
obj.matrixIds.push(tileMatrix);
},
@@ -143,7 +159,25 @@ OpenLayers.Format.WMTSCapabilities.v1_0_0 = OpenLayers.Class(
"TopLeftCorner": function(node, obj) {
var topLeftCorner = this.getChildValue(node);
var coords = topLeftCorner.split(" ");
obj.topLeftCorner = new OpenLayers.LonLat(parseFloat(coords[1]), parseFloat(coords[0]));
// decide on axis order for the given CRS
var yx;
if (obj.supportedCRS) {
// extract out version from URN
var crs = obj.supportedCRS.replace(
/urn:ogc:def:crs:(\w+):.+:(\w+)$/,
"urn:ogc:def:crs:$1::$2"
);
yx = !!this.yx[crs];
}
if (yx) {
obj.topLeftCorner = new OpenLayers.LonLat(
coords[1], coords[0]
);
} else {
obj.topLeftCorner = new OpenLayers.LonLat(
coords[0], coords[1]
);
}
},
"TileWidth": function(node, obj) {
obj.tileWidth = parseInt(this.getChildValue(node));