Merge branch 'master' of github.com:openlayers/ol3 into vector

This commit is contained in:
Tim Schaub
2013-03-05 10:58:27 +01:00
46 changed files with 541 additions and 358 deletions

View File

@@ -23,6 +23,7 @@ goog.require('ol.tilegrid.XYZ');
ol.source.BingMaps = function(bingMapsOptions) {
goog.base(this, {
opaque: true,
projection: ol.projection.getFromCode('EPSG:3857')
});

View File

@@ -90,6 +90,7 @@ ol.source.DebugTileSource = function(options) {
goog.base(this, {
extent: options.extent,
opaque: false,
projection: options.projection,
tileGrid: options.tileGrid
});

View File

@@ -76,12 +76,13 @@ goog.inherits(ol.source.ImageSource, ol.source.Source);
* @param {ol.Extent} extent Extent.
* @param {number} resolution Resolution.
* @param {ol.Size} size Size.
* @param {ol.Projection} projection Projection.
* @return {ol.Image} Single image.
*/
ol.source.ImageSource.prototype.createImage =
function(extent, resolution, size) {
function(extent, resolution, size, projection) {
var image = null;
var imageUrl = this.imageUrlFunction(extent, size);
var imageUrl = this.imageUrlFunction(extent, size, projection);
if (goog.isDef(imageUrl)) {
image = new ol.Image(
extent, resolution, imageUrl, this.crossOrigin_,
@@ -109,6 +110,7 @@ ol.source.ImageSource.prototype.findNearestResolution =
/**
* @param {ol.Extent} extent Extent.
* @param {number} resolution Resolution.
* @param {ol.Projection} projection Projection.
* @return {ol.Image} Single image.
*/
ol.source.ImageSource.prototype.getImage = goog.abstractMethod;

View File

@@ -7,7 +7,6 @@ goog.require('ol.ImageTile');
goog.require('ol.Projection');
goog.require('ol.Tile');
goog.require('ol.TileCache');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.TileUrlFunctionType');
goog.require('ol.source.TileSource');
@@ -18,6 +17,7 @@ goog.require('ol.tilegrid.TileGrid');
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
* crossOrigin: (null|string|undefined),
* extent: (ol.Extent|undefined),
* opaque: (boolean|undefined),
* projection: (ol.Projection|undefined),
* tileGrid: (ol.tilegrid.TileGrid|undefined),
* tileUrlFunction: (ol.TileUrlFunctionType|undefined)}}
@@ -36,6 +36,7 @@ ol.source.ImageTileSource = function(options) {
goog.base(this, {
attributions: options.attributions,
extent: options.extent,
opaque: options.opaque,
projection: options.projection,
tileGrid: options.tileGrid
});
@@ -84,12 +85,15 @@ ol.source.ImageTileSource.prototype.expireCache = function(usedTiles) {
/**
* @inheritDoc
*/
ol.source.ImageTileSource.prototype.getTile = function(tileCoord) {
ol.source.ImageTileSource.prototype.getTile =
function(tileCoord, tileGrid, projection) {
var key = tileCoord.toString();
if (this.tileCache_.containsKey(key)) {
return /** @type {ol.Tile} */ (this.tileCache_.get(key));
} else {
var tileUrl = this.getTileCoordUrl(tileCoord);
goog.asserts.assert(tileGrid);
goog.asserts.assert(projection);
var tileUrl = this.tileUrlFunction(tileCoord, tileGrid, projection);
var tile;
if (goog.isDef(tileUrl)) {
tile = new ol.ImageTile(tileCoord, tileUrl, this.crossOrigin_);
@@ -102,15 +106,6 @@ ol.source.ImageTileSource.prototype.getTile = function(tileCoord) {
};
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @return {string|undefined} Tile URL.
*/
ol.source.ImageTileSource.prototype.getTileCoordUrl = function(tileCoord) {
return this.tileUrlFunction(tileCoord);
};
/**
* @inheritDoc
*/

View File

@@ -26,6 +26,7 @@ ol.source.MapQuestOSM = function() {
goog.base(this, {
attributions: attributions,
opaque: true,
maxZoom: 28,
url: 'http://otile{1-4}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg'
});
@@ -54,6 +55,7 @@ ol.source.MapQuestOpenAerial = function() {
goog.base(this, {
attributions: attributions,
maxZoom: 18,
opaque: true,
url: 'http://oatile{1-4}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg'
});

View File

@@ -18,6 +18,7 @@ ol.source.OpenStreetMap = function() {
goog.base(this, {
attributions: [attribution],
opaque: true,
maxZoom: 18,
url: 'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
});

View File

@@ -1,11 +1,9 @@
goog.provide('ol.source.SingleImageWMS');
goog.require('goog.uri.utils');
goog.require('ol.Extent');
goog.require('ol.Image');
goog.require('ol.ImageUrlFunction');
goog.require('ol.Size');
goog.require('ol.projection');
goog.require('ol.source.ImageSource');
@@ -16,45 +14,16 @@ goog.require('ol.source.ImageSource');
* @param {ol.source.SingleImageWMSOptions} options Options.
*/
ol.source.SingleImageWMS = function(options) {
var projection = ol.projection.createProjection(
options.projection, 'EPSG:3857');
var projectionExtent = projection.getExtent();
var extent = goog.isDef(options.extent) ?
options.extent : projectionExtent;
var version = goog.isDef(options.version) ?
options.version : '1.3';
var baseParams = {
'SERVICE': 'WMS',
'VERSION': version,
'REQUEST': 'GetMap',
'STYLES': '',
'FORMAT': 'image/png',
'TRANSPARENT': true
};
baseParams[version >= '1.3' ? 'CRS' : 'SRS'] = projection.getCode();
goog.object.extend(baseParams, options.params);
var axisOrientation = projection.getAxisOrientation();
var imageUrlFunction;
if (options.url) {
var url = goog.uri.utils.appendParamsFromMap(
options.url, baseParams);
imageUrlFunction =
ol.ImageUrlFunction.createBboxParam(url, axisOrientation);
} else {
imageUrlFunction =
ol.ImageUrlFunction.nullImageUrlFunction;
}
var imageUrlFunction = goog.isDef(options.url) ?
ol.ImageUrlFunction.createWMSParams(
options.url, options.params, options.version) :
ol.ImageUrlFunction.nullImageUrlFunction;
goog.base(this, {
attributions: options.attributions,
crossOrigin: options.crossOrigin,
extent: extent,
projection: projection,
extent: options.extent,
projection: options.projection,
resolutions: options.resolutions,
imageUrlFunction: imageUrlFunction
});
@@ -80,7 +49,7 @@ goog.inherits(ol.source.SingleImageWMS, ol.source.ImageSource);
* @inheritDoc
*/
ol.source.SingleImageWMS.prototype.getImage =
function(extent, resolution) {
function(extent, resolution, projection) {
resolution = this.findNearestResolution(resolution);
var image = this.image_;
@@ -97,6 +66,6 @@ ol.source.SingleImageWMS.prototype.getImage =
var height = extent.getHeight() / resolution;
var size = new ol.Size(width, height);
this.image_ = this.createImage(extent, resolution, size);
this.image_ = this.createImage(extent, resolution, size, projection);
return this.image_;
};

View File

@@ -38,7 +38,8 @@ ol.source.Source = function(sourceOptions) {
* @type {ol.Extent}
*/
this.extent_ = goog.isDef(sourceOptions.extent) ?
sourceOptions.extent : sourceOptions.projection.getExtent();
sourceOptions.extent : goog.isDef(sourceOptions.projection) ?
sourceOptions.projection.getExtent() : null;
/**
* @private

View File

@@ -85,6 +85,7 @@ ol.source.Stamen = function(stamenOptions) {
goog.base(this, {
attributions: [attribution],
maxZoom: config.maxZoom,
opaque: false,
url: 'http://{a-d}.tile.stamen.com/' + layer + '/{z}/{x}/{y}.' + config.type
});

View File

@@ -19,6 +19,7 @@ ol.source.StaticImage = function(options) {
var imageExtent = options.imageExtent;
var imageSize = options.imageSize;
var imageResolution = imageExtent.getHeight() / imageSize.height;
var projection = goog.isDef(options.projection) ? options.projection : null;
goog.base(this, {
attributions: options.attributions,
@@ -33,7 +34,8 @@ ol.source.StaticImage = function(options) {
* @private
* @type {ol.Image}
*/
this.image_ = this.createImage(imageExtent, imageResolution, imageSize);
this.image_ = this.createImage(
imageExtent, imageResolution, imageSize, projection);
};
goog.inherits(ol.source.StaticImage, ol.source.ImageSource);
@@ -42,7 +44,8 @@ goog.inherits(ol.source.StaticImage, ol.source.ImageSource);
/**
* @inheritDoc
*/
ol.source.StaticImage.prototype.getImage = function(extent, resolution) {
ol.source.StaticImage.prototype.getImage =
function(extent, resolution, projection) {
if (extent.intersects(this.image_.getExtent())) {
return this.image_;
}
@@ -55,7 +58,7 @@ ol.source.StaticImage.prototype.getImage = function(extent, resolution) {
* @return {ol.ImageUrlFunctionType} Function.
*/
ol.source.StaticImage.createImageFunction = function(url) {
return function(extent, size) {
return function(extent, size, projection) {
return url;
};
};

View File

@@ -4,12 +4,9 @@ goog.provide('ol.source.TiledWMS');
goog.require('goog.array');
goog.require('goog.object');
goog.require('goog.uri.utils');
goog.require('ol.Extent');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.projection');
goog.require('ol.source.ImageTileSource');
@@ -20,61 +17,40 @@ goog.require('ol.source.ImageTileSource');
* @param {ol.source.TiledWMSOptions} tiledWMSOptions options.
*/
ol.source.TiledWMS = function(tiledWMSOptions) {
var projection = ol.projection.createProjection(
tiledWMSOptions.projection, 'EPSG:3857');
var projectionExtent = projection.getExtent();
var extent = goog.isDef(tiledWMSOptions.extent) ?
tiledWMSOptions.extent : projectionExtent;
var version = goog.isDef(tiledWMSOptions.version) ?
tiledWMSOptions.version : '1.3';
var tileGrid;
if (goog.isDef(tiledWMSOptions.tileGrid)) {
tileGrid = tiledWMSOptions.tileGrid;
} else {
tileGrid = ol.tilegrid.createForProjection(projection,
tiledWMSOptions.maxZoom);
}
var version = tiledWMSOptions.version;
var baseParams = {
'SERVICE': 'WMS',
'VERSION': version,
'REQUEST': 'GetMap',
'STYLES': '',
'FORMAT': 'image/png',
'TRANSPARENT': true
};
baseParams[version >= '1.3' ? 'CRS' : 'SRS'] = projection.getCode();
goog.object.extend(baseParams, tiledWMSOptions.params);
var axisOrientation = projection.getAxisOrientation();
var tileUrlFunction;
if (tiledWMSOptions.urls) {
var tileUrlFunctions = goog.array.map(
tiledWMSOptions.urls, function(url) {
url = goog.uri.utils.appendParamsFromMap(url, baseParams);
return ol.TileUrlFunction.createBboxParam(
url, tileGrid, axisOrientation);
return ol.TileUrlFunction.createWMSParams(
url, tiledWMSOptions.params, version);
});
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
tileUrlFunctions);
} else if (tiledWMSOptions.url) {
var url = goog.uri.utils.appendParamsFromMap(
tiledWMSOptions.url, baseParams);
tileUrlFunction =
ol.TileUrlFunction.createBboxParam(url, tileGrid, axisOrientation);
tileUrlFunction = ol.TileUrlFunction.createWMSParams(
tiledWMSOptions.url, tiledWMSOptions.params, version);
} else {
tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
}
var transparent = goog.isDef(tiledWMSOptions.transparent) ?
tiledWMSOptions.transparent : true;
var extent = tiledWMSOptions.extent;
var tileCoordTransform = function(tileCoord) {
var tileCoordTransform = function(tileCoord, tileGrid, projection) {
if (tileGrid.getResolutions().length <= tileCoord.z) {
return null;
}
var x = tileCoord.x;
var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
var projectionExtent = projection.getExtent();
var extent = goog.isDef(tiledWMSOptions.extent) ?
tiledWMSOptions.extent : projectionExtent;
// FIXME do we want a wrapDateLine param? The code below will break maps
// with projections that do not span the whole world width.
if (extent.minX === projectionExtent.minX &&
@@ -96,8 +72,9 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
attributions: tiledWMSOptions.attributions,
crossOrigin: tiledWMSOptions.crossOrigin,
extent: extent,
tileGrid: tileGrid,
projection: projection,
tileGrid: tiledWMSOptions.tileGrid,
opaque: !transparent,
projection: tiledWMSOptions.projection,
tileUrlFunction: ol.TileUrlFunction.withTileCoordTransform(
tileCoordTransform, tileUrlFunction)
});

View File

@@ -15,6 +15,7 @@ goog.require('ol.tilegrid.TileGrid');
/**
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
* extent: (ol.Extent|undefined),
* opaque: (boolean|undefined),
* projection: (ol.Projection|undefined),
* tileGrid: (ol.tilegrid.TileGrid|undefined)}}
*/
@@ -35,6 +36,13 @@ ol.source.TileSource = function(tileSourceOptions) {
projection: tileSourceOptions.projection
});
/**
* @private
* @type {boolean}
*/
this.opaque_ = goog.isDef(tileSourceOptions.opaque) ?
tileSourceOptions.opaque : false;
/**
* @protected
* @type {ol.tilegrid.TileGrid}
@@ -65,14 +73,14 @@ ol.source.TileSource.prototype.expireCache = goog.abstractMethod;
*
* @param {Object.<number, Object.<string, ol.Tile>>} loadedTilesByZ A lookup of
* loaded tiles by zoom level.
* @param {function(ol.Tile): boolean} isLoaded A function to determine if a
* tile is fully loaded.
* @param {function(ol.TileCoord): ol.Tile} getTileIfLoaded A function that
* returns the tile only if it is fully loaded.
* @param {number} z Zoom level.
* @param {ol.TileRange} tileRange Tile range.
* @return {boolean} The tile range is fully covered with loaded tiles.
*/
ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ,
isLoaded, z, tileRange) {
getTileIfLoaded, z, tileRange) {
// FIXME this could be more efficient about filling partial holes
var fullyCovered = true;
var tile, tileCoord, tileCoordKey, x, y;
@@ -83,8 +91,8 @@ ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ,
if (loadedTilesByZ[z] && loadedTilesByZ[z][tileCoordKey]) {
continue;
}
tile = this.getTile(tileCoord);
if (isLoaded(tile)) {
tile = getTileIfLoaded(tileCoord);
if (!goog.isNull(tile)) {
if (!loadedTilesByZ[z]) {
loadedTilesByZ[z] = {};
}
@@ -98,6 +106,14 @@ ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ,
};
/**
* @return {boolean} Opaque.
*/
ol.source.TileSource.prototype.getOpaque = function() {
return this.opaque_;
};
/**
* @inheritDoc
*/
@@ -108,6 +124,8 @@ ol.source.TileSource.prototype.getResolutions = function() {
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.tilegrid.TileGrid=} opt_tileGrid Tile grid.
* @param {ol.Projection=} opt_projection Projection.
* @return {ol.Tile} Tile.
*/
ol.source.TileSource.prototype.getTile = goog.abstractMethod;
@@ -124,9 +142,10 @@ ol.source.TileSource.prototype.getTileGrid = function() {
/**
* @param {number} z Z.
* @param {ol.Extent} extent Extent.
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
*/
ol.source.TileSource.prototype.useLowResolutionTiles = function(z, extent) {
var tileGrid = this.getTileGrid();
ol.source.TileSource.prototype.useLowResolutionTiles =
function(z, extent, tileGrid) {
var tileRange, x, y, zKey;
// FIXME this should loop up to tileGrid's minZ when implemented
for (; z >= 0; --z) {

37
src/ol/source/wms.js Normal file
View File

@@ -0,0 +1,37 @@
goog.provide('ol.source.wms');
/**
* @param {string} baseUrl WMS base url.
* @param {Object.<string, string|number>} params Request parameters.
* @param {ol.Extent} extent Extent.
* @param {ol.Size} size Size.
* @param {ol.Projection} projection Projection.
* @param {string=} opt_version WMS version. Default is '1.3.0'.
* @return {string} WMS GetMap request URL.
*/
ol.source.wms.getUrl =
function(baseUrl, params, extent, size, projection, opt_version) {
var version = goog.isDef(opt_version) ? opt_version : '1.3.0';
var wms13 = version >= '1.3';
var axisOrientation = projection.getAxisOrientation();
var bboxValues = (wms13 && axisOrientation.substr(0, 2) == 'ne') ?
[extent.minY, extent.minX, extent.maxY, extent.maxX] :
[extent.minX, extent.minY, extent.maxX, extent.maxY];
var baseParams = {
'SERVICE': 'WMS',
'VERSION': version,
'REQUEST': 'GetMap',
'FORMAT': 'image/png',
'TRANSPARENT': true,
'WIDTH': size.width,
'HEIGHT': size.height,
'BBOX': bboxValues.join(',')
};
goog.object.extend(baseParams, params);
baseParams[wms13 ? 'CRS' : 'SRS'] = projection.getCode();
//TODO: Provide our own appendParams function to avoid this empty string hack
var stylesParam = 'STYLES';
baseParams[stylesParam] = params[stylesParam] || new String('');
return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams);
};