This commit is contained in:
Tom Payne
2013-03-11 16:47:39 +01:00
parent f150259eee
commit 9b734a3335
150 changed files with 8832 additions and 4380 deletions
+4 -1
View File
@@ -1,2 +1,5 @@
@exportSymbol ol.Coordinate
@exportProperty ol.Coordinate.toStringHDMS
@exportSymbol ol.Coordinate.createStringXY
@exportSymbol ol.Coordinate.toStringHDMS
@exportSymbol ol.Coordinate.toStringXY
@exportSymbol ol.Coordinate.fromProjectedArray
+8
View File
@@ -1,3 +1,11 @@
@exportSymbol ol.Extent
@exportProperty ol.Extent.prototype.getCenter
@exportProperty ol.Extent.prototype.getHeight
@exportProperty ol.Extent.prototype.getWidth
@exportProperty ol.Extent.prototype.containsCoordinate
@exportProperty ol.Extent.prototype.containsExtent
@exportProperty ol.Extent.prototype.getBottomLeft
@exportProperty ol.Extent.prototype.getBottomRight
@exportProperty ol.Extent.prototype.getTopLeft
@exportProperty ol.Extent.prototype.getTopRight
@exportProperty ol.Extent.prototype.transform
+29
View File
@@ -45,6 +45,35 @@ ol.Extent.boundingExtent = function(var_args) {
};
/**
* @param {ol.Coordinate} center Center.
* @param {number} resolution Resolution.
* @param {number} rotation Rotation.
* @param {ol.Size} size Size.
* @return {ol.Extent} Extent.
*/
ol.Extent.getForView2DAndSize = function(center, resolution, rotation, size) {
var dx = resolution * size.width / 2;
var dy = resolution * size.height / 2;
var cosRotation = Math.cos(rotation);
var sinRotation = Math.sin(rotation);
var xs = [-dx, -dx, dx, dx];
var ys = [-dy, dy, -dy, dy];
var i, x, y;
for (i = 0; i < 4; ++i) {
x = xs[i];
y = ys[i];
xs[i] = center.x + x * cosRotation - y * sinRotation;
ys[i] = center.y + x * sinRotation + y * cosRotation;
}
var minX = Math.min.apply(null, xs);
var minY = Math.min.apply(null, ys);
var maxX = Math.max.apply(null, xs);
var maxY = Math.max.apply(null, ys);
return new ol.Extent(minX, minY, maxX, maxY);
};
/**
* Checks if the passed coordinate is contained or on the edge
* of the extent.
+2 -18
View File
@@ -728,24 +728,8 @@ ol.Map.prototype.renderFrame_ = function(time) {
if (!goog.isNull(frameState)) {
// FIXME works for View2D only
var center = view2DState.center;
var resolution = view2DState.resolution;
var rotation = view2DState.rotation;
var x = resolution * size.width / 2;
var y = resolution * size.height / 2;
var corners = [
new ol.Coordinate(-x, -y),
new ol.Coordinate(-x, y),
new ol.Coordinate(x, -y),
new ol.Coordinate(x, y)
];
var corner;
for (i = 0; i < 4; ++i) {
corner = corners[i];
corner.rotate(rotation);
corner.add(center);
}
frameState.extent = ol.Extent.boundingExtent.apply(null, corners);
frameState.extent = ol.Extent.getForView2DAndSize(view2DState.center,
view2DState.resolution, view2DState.rotation, frameState.size);
}
this.frameState_ = frameState;
@@ -67,7 +67,7 @@ ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() {
},
'TileMatrix': function(node, obj) {
var tileMatrix = {
'supportedCRS': obj.supportedCRS
'supportedCRS': obj['supportedCRS']
};
this.readChildNodes(node, tileMatrix);
obj['matrixIds'].push(tileMatrix);
@@ -6,6 +6,7 @@ goog.provide('ol.renderer.canvas.TileLayer');
goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.vec.Mat4');
goog.require('ol.Extent');
goog.require('ol.Size');
goog.require('ol.Tile');
goog.require('ol.TileCoord');
@@ -103,8 +104,17 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
var z = tileGrid.getZForResolution(view2DState.resolution);
var tileSize = tileGrid.getTileSize(z);
var tileResolution = tileGrid.getResolution(z);
var center = view2DState.center;
var extent;
if (tileResolution == view2DState.resolution) {
center = this.snapCenterToPixel(center, tileResolution, frameState.size);
extent = ol.Extent.getForView2DAndSize(
center, tileResolution, view2DState.rotation, frameState.size);
} else {
extent = frameState.extent;
}
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
frameState.extent, tileResolution);
extent, tileResolution);
var tileRangeWidth = tileRange.getWidth();
var tileRangeHeight = tileRange.getHeight();
@@ -238,7 +248,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
}
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
tileSource.useLowResolutionTiles(z, extent, tileGrid);
this.scheduleExpireCache(frameState, tileSource);
var transform = this.transform_;
@@ -253,8 +263,8 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
1);
goog.vec.Mat4.translate(
transform,
(origin.x - view2DState.center.x) / tileResolution,
(view2DState.center.y - origin.y) / tileResolution,
(origin.x - center.x) / tileResolution,
(center.y - origin.y) / tileResolution,
0);
};
@@ -90,8 +90,17 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
}
var z = tileGrid.getZForResolution(view2DState.resolution);
var tileResolution = tileGrid.getResolution(z);
var center = view2DState.center;
var extent;
if (tileResolution == view2DState.resolution) {
center = this.snapCenterToPixel(center, tileResolution, frameState.size);
extent = ol.Extent.getForView2DAndSize(
center, tileResolution, view2DState.rotation, frameState.size);
} else {
extent = frameState.extent;
}
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
frameState.extent, tileResolution);
extent, tileResolution);
/** @type {Object.<number, Object.<string, ol.Tile>>} */
var tilesToDrawByZ = {};
@@ -146,7 +155,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
tileLayerZ = this.tileLayerZs_[tileLayerZKey];
} else {
tileCoordOrigin =
tileGrid.getTileCoordForCoordAndZ(view2DState.center, tileLayerZKey);
tileGrid.getTileCoordForCoordAndZ(center, tileLayerZKey);
tileLayerZ = new ol.renderer.dom.TileLayerZ_(tileGrid, tileCoordOrigin);
newTileLayerZKeys[tileLayerZKey] = true;
this.tileLayerZs_[tileLayerZKey] = tileLayerZ;
@@ -183,8 +192,8 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
resolution / view2DState.resolution, 1);
goog.vec.Mat4.translate(
transform,
(origin.x - view2DState.center.x) / resolution,
(view2DState.center.y - origin.y) / resolution,
(origin.x - center.x) / resolution,
(center.y - origin.y) / resolution,
0);
tileLayerZ.setTransform(transform);
if (tileLayerZKey in newTileLayerZKeys) {
@@ -201,7 +210,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
} else {
if (!frameState.viewHints[ol.ViewHint.ANIMATING] &&
!frameState.viewHints[ol.ViewHint.INTERACTING]) {
tileLayerZ.removeTilesOutsideExtent(frameState.extent);
tileLayerZ.removeTilesOutsideExtent(extent);
}
}
}
@@ -217,7 +226,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
}
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
tileSource.useLowResolutionTiles(z, extent, tileGrid);
this.scheduleExpireCache(frameState, tileSource);
};
+16
View File
@@ -3,6 +3,7 @@ goog.provide('ol.renderer.Layer');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.Attribution');
goog.require('ol.Coordinate');
goog.require('ol.FrameState');
goog.require('ol.Image');
goog.require('ol.ImageState');
@@ -299,3 +300,18 @@ ol.renderer.Layer.prototype.createGetTileIfLoadedFunction =
return isLoadedFunction(tile) ? tile : null;
};
};
/**
* @param {ol.Coordinate} center Center.
* @param {number} resolution Resolution.
* @param {ol.Size} size Size.
* @return {ol.Coordinate} Snapped center.
* @protected
*/
ol.renderer.Layer.prototype.snapCenterToPixel =
function(center, resolution, size) {
return new ol.Coordinate(
resolution * (Math.round(center.x / resolution) + (size.width % 2) / 2),
resolution * (Math.round(center.y / resolution) + (size.height % 2) / 2));
};
@@ -282,7 +282,6 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
var view2DState = frameState.view2DState;
var projection = view2DState.projection;
var center = view2DState.center;
var tileLayer = this.getTileLayer();
var tileSource = tileLayer.getTileSource();
@@ -293,8 +292,17 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
}
var z = tileGrid.getZForResolution(view2DState.resolution);
var tileResolution = tileGrid.getResolution(z);
var center = view2DState.center;
var extent;
if (tileResolution == view2DState.resolution) {
center = this.snapCenterToPixel(center, tileResolution, frameState.size);
extent = ol.Extent.getForView2DAndSize(
center, tileResolution, view2DState.rotation, frameState.size);
} else {
extent = frameState.extent;
}
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
frameState.extent, tileResolution);
extent, tileResolution);
var framebufferExtent;
if (!goog.isNull(this.renderedTileRange_) &&
@@ -460,14 +468,14 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
}
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
tileSource.useLowResolutionTiles(z, extent, tileGrid);
this.scheduleExpireCache(frameState, tileSource);
goog.vec.Mat4.makeIdentity(this.texCoordMatrix_);
goog.vec.Mat4.translate(this.texCoordMatrix_,
(view2DState.center.x - framebufferExtent.minX) /
(center.x - framebufferExtent.minX) /
(framebufferExtent.maxX - framebufferExtent.minX),
(view2DState.center.y - framebufferExtent.minY) /
(center.y - framebufferExtent.minY) /
(framebufferExtent.maxY - framebufferExtent.minY),
0);
goog.vec.Mat4.rotateZ(this.texCoordMatrix_, view2DState.rotation);
+2
View File
@@ -0,0 +1,2 @@
@exportClass ol.source.WMTS ol.source.WMTSOptions
@exportSymbol ol.source.WMTS.optionsFromCapabilities
+260
View File
@@ -0,0 +1,260 @@
goog.provide('ol.source.WMTS');
goog.provide('ol.source.WMTSRequestEncoding');
goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.TileUrlFunctionType');
goog.require('ol.projection');
goog.require('ol.source.ImageTileSource');
goog.require('ol.tilegrid.WMTS');
/**
* @enum {string}
*/
ol.source.WMTSRequestEncoding = {
KVP: 'KVP', // see spec §8
REST: 'REST' // see spec §10
};
/**
* @constructor
* @extends {ol.source.ImageTileSource}
* @param {ol.source.WMTSOptions} wmtsOptions WMTS options.
*/
ol.source.WMTS = function(wmtsOptions) {
// TODO: add support for TileMatrixLimits
var version = goog.isDef(wmtsOptions.version) ?
wmtsOptions.version : '1.0.0';
var format = goog.isDef(wmtsOptions.format) ?
wmtsOptions.format : 'image/jpeg';
var dimensions = wmtsOptions.dimensions || {};
// FIXME: should we guess this requestEncoding from wmtsOptions.url(s)
// structure? that would mean KVP only if a template is not provided.
var requestEncoding = goog.isDef(wmtsOptions.requestEncoding) ?
wmtsOptions.requestEncoding : ol.source.WMTSRequestEncoding.KVP;
// FIXME: should we create a default tileGrid?
// we could issue a getCapabilities xhr to retrieve missing configuration
var tileGrid = wmtsOptions.tileGrid;
var context = {
'Layer': wmtsOptions.layer,
'style': wmtsOptions.style,
'TileMatrixSet': wmtsOptions.matrixSet
};
goog.object.extend(context, dimensions);
var kvpParams;
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
kvpParams = {
'Service': 'WMTS',
'Request': 'GetTile',
'Version': version,
'Format': format,
'TileMatrix': '{TileMatrix}',
'TileRow': '{TileRow}',
'TileCol': '{TileCol}'
};
goog.object.extend(kvpParams, context);
}
// TODO: factorize the code below so that it is usable by all sources
var urls = wmtsOptions.urls;
if (!goog.isDef(urls)) {
urls = [];
var url = wmtsOptions.url;
goog.asserts.assert(goog.isDef(url));
var match = /\{(\d)-(\d)\}/.exec(url) || /\{([a-z])-([a-z])\}/.exec(url);
if (match) {
var startCharCode = match[1].charCodeAt(0);
var stopCharCode = match[2].charCodeAt(0);
var charCode;
for (charCode = startCharCode; charCode <= stopCharCode; ++charCode) {
urls.push(url.replace(match[0], String.fromCharCode(charCode)));
}
} else {
urls.push(url);
}
}
/**
* @param {string} template Template.
* @return {ol.TileUrlFunctionType} Tile URL function.
*/
function createFromWMTSTemplate(template) {
return function(tileCoord) {
if (goog.isNull(tileCoord)) {
return undefined;
} else {
var localContext = {
'TileMatrix': tileGrid.getMatrixId(tileCoord.z),
'TileCol': tileCoord.x,
'TileRow': tileCoord.y
};
if (requestEncoding != ol.source.WMTSRequestEncoding.KVP) {
goog.object.extend(localContext, context);
}
var url = template;
for (var key in localContext) {
// FIXME: should we filter properties with hasOwnProperty?
url = url.replace('{' + key + '}', localContext[key])
.replace('%7B' + key + '%7D', localContext[key]);
}
return url;
}
};
}
var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
goog.array.map(urls, function(url) {
if (goog.isDef(kvpParams)) {
// TODO: we may want to create our own appendParams function
// so that params order conforms to wmts spec guidance,
// and so that we can avoid to escape special template params
url = goog.uri.utils.appendParamsFromMap(url, kvpParams);
}
return createFromWMTSTemplate(url);
}));
tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
function(tileCoord, tileGrid, projection) {
if (tileGrid.getResolutions().length <= tileCoord.z) {
return null;
}
var x = tileCoord.x;
var y = -tileCoord.y - 1;
var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
var projectionExtent = projection.getExtent();
var extent = goog.isDef(wmtsOptions.extent) ?
wmtsOptions.extent : projectionExtent;
if (!goog.isNull(extent) && projection.isGlobal() &&
extent.minX === projectionExtent.minX &&
extent.maxX === projectionExtent.maxX) {
var numCols = Math.ceil(
(extent.maxX - extent.minX) /
(tileExtent.maxX - tileExtent.minX));
x = goog.math.modulo(x, numCols);
tileExtent = tileGrid.getTileCoordExtent(
new ol.TileCoord(tileCoord.z, x, tileCoord.y));
}
if (!tileExtent.intersects(extent)) {
return null;
}
return new ol.TileCoord(tileCoord.z, x, y);
},
tileUrlFunction);
goog.base(this, {
attributions: wmtsOptions.attributions,
crossOrigin: wmtsOptions.crossOrigin,
extent: wmtsOptions.extent,
projection: wmtsOptions.projection,
tileGrid: tileGrid,
tileUrlFunction: tileUrlFunction
});
};
goog.inherits(ol.source.WMTS, ol.source.ImageTileSource);
/**
* @param {Object} wmtsCap An object representing the capabilities document.
* @param {string} layer The layer identifier.
* @return {ol.source.WMTSOptions} WMTS source options object.
*/
ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, layer) {
// TODO: add support for TileMatrixLimits
var layers = wmtsCap['contents']['layers'];
var l = goog.array.find(layers, function(elt, index, array) {
return elt['identifier'] == layer;
});
goog.asserts.assert(!goog.isNull(l));
goog.asserts.assert(l['tileMatrixSetLinks'].length > 0);
var matrixSet = /** @type {string} */
(l['tileMatrixSetLinks'][0]['tileMatrixSet']);
var format = /** @type {string} */ (l['formats'][0]);
var idx = goog.array.findIndex(l['styles'], function(elt, index, array) {
return elt['isDefault'];
});
if (idx < 0) {
idx = 0;
}
var style = /** @type {string} */ (l['styles'][idx]['identifier']);
var dimensions = {};
goog.array.forEach(l['dimensions'], function(elt, index, array) {
var key = elt['identifier'];
var value = elt['default'];
if (goog.isDef(value)) {
goog.asserts.assert(goog.array.indexOf(elt['values'], value) >= 0);
} else {
value = elt['values'][0];
}
goog.asserts.assert(goog.isDef(value));
dimensions[key] = value;
});
var matrixSets = wmtsCap['contents']['tileMatrixSets'];
goog.asserts.assert(matrixSet in matrixSets);
var matrixSetObj = matrixSets[matrixSet];
var tileGrid = ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet(
matrixSetObj);
var projection = ol.projection.get(matrixSetObj['supportedCRS']);
var gets = wmtsCap['operationsMetadata']['GetTile']['dcp']['http']['get'];
var encodings = goog.object.getKeys(
gets[0]['constraints']['GetEncoding']['allowedValues']);
goog.asserts.assert(encodings.length > 0);
var requestEncoding = /** @type {ol.source.WMTSRequestEncoding} */
(encodings[0]);
// TODO: arcgis support, quote from ol2:
// The OGC documentation is not clear if we should use REST or RESTful,
// ArcGis use RESTful, and OpenLayers use REST.
var urls;
switch (requestEncoding) {
case ol.source.WMTSRequestEncoding.REST:
goog.asserts.assert(l['resourceUrls'].hasOwnProperty('tile'));
goog.asserts.assert(l['resourceUrls']['tile'].hasOwnProperty(format));
urls = /** @type {Array.<string>} */
(l['resourceUrls']['tile'][format]);
break;
case ol.source.WMTSRequestEncoding.KVP:
urls = [];
goog.array.forEach(gets, function(elt, index, array) {
if (elt['constraints']['GetEncoding']['allowedValues'].hasOwnProperty(
ol.source.WMTSRequestEncoding.KVP)) {
urls.push(/** @type {string} */ (elt['url']));
}
});
goog.asserts.assert(urls.length > 0);
break;
default:
goog.asserts.assert(false);
}
return {
urls: urls,
layer: layer,
matrixSet: matrixSet,
format: format,
projection: projection,
requestEncoding: requestEncoding,
tileGrid: tileGrid,
style: style,
dimensions: dimensions
};
};
@@ -0,0 +1 @@
@exportClass ol.tilegrid.WMTS ol.tilegrid.WMTSOptions
+83
View File
@@ -0,0 +1,83 @@
goog.provide('ol.tilegrid.WMTS');
goog.require('ol.Size');
goog.require('ol.projection');
goog.require('ol.tilegrid.TileGrid');
/**
* @constructor
* @extends {ol.tilegrid.TileGrid}
* @param {ol.tilegrid.WMTSOptions} wmtsOptions WMTS options.
*/
ol.tilegrid.WMTS = function(wmtsOptions) {
goog.asserts.assert(
wmtsOptions.resolutions.length == wmtsOptions.matrixIds.length);
/**
* @private
* @type {!Array.<string>}
*/
this.matrixIds_ = wmtsOptions.matrixIds;
// FIXME: should the matrixIds become optionnal?
goog.base(this, {
origin: wmtsOptions.origin,
origins: wmtsOptions.origins,
resolutions: wmtsOptions.resolutions,
tileSize: wmtsOptions.tileSize,
tileSizes: wmtsOptions.tileSizes
});
};
goog.inherits(ol.tilegrid.WMTS, ol.tilegrid.TileGrid);
/**
* @param {number} z Z.
* @return {string} MatrixId..
*/
ol.tilegrid.WMTS.prototype.getMatrixId = function(z) {
goog.asserts.assert(0 <= z && z < this.matrixIds_.length);
return this.matrixIds_[z];
};
/**
* @return {Array.<string>} MatrixIds.
*/
ol.tilegrid.WMTS.prototype.getMatrixIds = function() {
return this.matrixIds_;
};
/**
* @param {Object} matrixSet An object representing a matrixSet in the
* capabilities document.
* @return {ol.tilegrid.WMTS} WMTS tileGrid instance.
*/
ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
function(matrixSet) {
var resolutions = [];
var matrixIds = [];
var origins = [];
var tileSizes = [];
var projection = ol.projection.get(matrixSet['supportedCRS']);
var metersPerUnit = projection.getMetersPerUnit();
goog.array.forEach(matrixSet['matrixIds'], function(elt, index, array) {
matrixIds.push(elt['identifier']);
origins.push(elt['topLeftCorner']);
resolutions.push(elt['scaleDenominator'] * 0.28E-3 / metersPerUnit);
tileSizes.push(new ol.Size(elt['tileWidth'], elt['tileHeight']));
});
return new ol.tilegrid.WMTS({
origins: origins,
resolutions: resolutions,
matrixIds: matrixIds,
tileSizes: tileSizes
});
};
+3
View File
@@ -60,6 +60,9 @@ ol.TileUrlFunction.createFromTemplates = function(templates) {
* @return {ol.TileUrlFunctionType} Tile URL function.
*/
ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
if (tileUrlFunctions.length === 1) {
return tileUrlFunctions[0];
}
return function(tileCoord, tileGrid, projection) {
if (goog.isNull(tileCoord)) {
return undefined;