Merge pull request #1967 from fredj/tileUrlFunction-this

Don't use 'this' keyword in tileUrlFunction
This commit is contained in:
Frédéric Junod
2014-04-09 10:21:06 +02:00
2 changed files with 23 additions and 15 deletions
+20 -12
View File
@@ -1,3 +1,4 @@
goog.require('ol.Attribution');
goog.require('ol.Map'); goog.require('ol.Map');
goog.require('ol.View2D'); goog.require('ol.View2D');
goog.require('ol.extent'); goog.require('ol.extent');
@@ -8,17 +9,23 @@ goog.require('ol.source.WMTS');
goog.require('ol.tilegrid.WMTS'); goog.require('ol.tilegrid.WMTS');
var projection = ol.proj.get('EPSG:900913'); var projection = ol.proj.get('EPSG:3857');
var projectionExtent = projection.getExtent(); var projectionExtent = projection.getExtent();
var size = ol.extent.getWidth(projectionExtent) / 256; var size = ol.extent.getWidth(projectionExtent) / 256;
var resolutions = new Array(18); var resolutions = new Array(14);
var matrixIds = new Array(18); var matrixIds = new Array(14);
for (var z = 0; z < 18; ++z) { for (var z = 0; z < 14; ++z) {
// generate resolutions and matrixIds arrays for this WMTS // generate resolutions and matrixIds arrays for this WMTS
resolutions[z] = size / Math.pow(2, z); resolutions[z] = size / Math.pow(2, z);
matrixIds[z] = z; matrixIds[z] = z;
} }
var attribution = new ol.Attribution({
html: 'Tiles &copy; <a href="http://services.arcgisonline.com/arcgis/rest/' +
'services/Demographics/USA_Population_Density/MapServer/">ArcGIS</a>'
});
var map = new ol.Map({ var map = new ol.Map({
layers: [ layers: [
new ol.layer.Tile({ new ol.layer.Tile({
@@ -28,25 +35,26 @@ var map = new ol.Map({
new ol.layer.Tile({ new ol.layer.Tile({
opacity: 0.7, opacity: 0.7,
source: new ol.source.WMTS({ source: new ol.source.WMTS({
url: 'http://demo-apollo.geospatial.intergraph.com/erdas-iws/ogc/wmts/', attributions: [attribution],
layer: 'sampleiws_images_geodetic_worldgeodemo.ecw', url: 'http://services.arcgisonline.com/arcgis/rest/' +
matrixSet: 'ogc:1.0:googlemapscompatible', 'services/Demographics/USA_Population_Density/MapServer/WMTS/',
format: 'image/jpeg', layer: '0',
matrixSet: 'EPSG:3857',
format: 'image/png',
projection: projection, projection: projection,
tileGrid: new ol.tilegrid.WMTS({ tileGrid: new ol.tilegrid.WMTS({
origin: ol.extent.getTopLeft(projectionExtent), origin: ol.extent.getTopLeft(projectionExtent),
resolutions: resolutions, resolutions: resolutions,
matrixIds: matrixIds matrixIds: matrixIds
}), }),
extent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34], extent: projectionExtent,
style: 'default' style: 'default'
}) })
}) })
], ],
target: 'map', target: 'map',
view: new ol.View2D({ view: new ol.View2D({
center: [0, 0], center: [-11158582, 4813697],
zoom: 0, zoom: 4
maxResolution: resolutions[1]
}) })
}); });
+3 -3
View File
@@ -76,6 +76,8 @@ ol.source.WMTS = function(options) {
}); });
} }
var dimensions = this.dimensions_;
/** /**
* @param {string} template Template. * @param {string} template Template.
* @return {ol.TileUrlFunctionType} Tile URL function. * @return {ol.TileUrlFunctionType} Tile URL function.
@@ -94,7 +96,6 @@ ol.source.WMTS = function(options) {
return ( return (
/** /**
* @this {ol.source.WMTS}
* @param {ol.TileCoord} tileCoord Tile coordinate. * @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} pixelRatio Pixel ratio. * @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection. * @param {ol.proj.Projection} projection Projection.
@@ -109,7 +110,7 @@ ol.source.WMTS = function(options) {
'TileCol': tileCoord.x, 'TileCol': tileCoord.x,
'TileRow': tileCoord.y 'TileRow': tileCoord.y
}; };
goog.object.extend(localContext, this.dimensions_); goog.object.extend(localContext, dimensions);
var url = template; var url = template;
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) { if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
url = goog.uri.utils.appendParamsFromMap(url, localContext); url = goog.uri.utils.appendParamsFromMap(url, localContext);
@@ -143,7 +144,6 @@ ol.source.WMTS = function(options) {
* @return {ol.TileCoord} Tile coordinate. * @return {ol.TileCoord} Tile coordinate.
*/ */
function(tileCoord, projection, opt_tileCoord) { function(tileCoord, projection, opt_tileCoord) {
var tileGrid = this.getTileGrid();
goog.asserts.assert(!goog.isNull(tileGrid)); goog.asserts.assert(!goog.isNull(tileGrid));
if (tileGrid.getResolutions().length <= tileCoord.z) { if (tileGrid.getResolutions().length <= tileCoord.z) {
return null; return null;