Support tile sources without configured projection

This change adds a lot of flexibility to working with tile
layers: Sources where the server projection or tile grid do not
matter can now be constructed without specifying a projection or
tile grid.

The tileUrlFunction/imageUrlFunction now also creates updated
URLs when the params of the layer change, so things like
mergeNewParams in ol2 will be possible.

A nice side effect of this whole change is that there is no more
duplicated code between tiled and single image WMS layers.

While I was at it, I also fixed a WMS 1.1.1 axis order issue
and incorrect STYLES params (STYLES=& instead of STYLES&).
This commit is contained in:
ahocevar
2013-03-05 00:46:58 +01:00
parent cad215e0cc
commit 586f393492
24 changed files with 320 additions and 206 deletions

View File

@@ -19,8 +19,10 @@ var epsg21781 = new ol.Projection('EPSG:21781', ol.ProjectionUnits.METERS,
new ol.Extent(485869.5728, 76443.1884, 837076.5648, 299941.7864));
ol.projection.addProjection(epsg21781);
// We give the single image source a set of resolutions. This prevents the
// source from requesting images of arbitrary resolutions.
// We could give the single image source a set of resolutions. This prevents the
// source from requesting images of arbitrary resolutions. To try it, uncomment
// the block below and the resolutions option in the SingleImageWMS config.
/*
var projectionExtent = epsg21781.getExtent();
var maxResolution = Math.max(projectionExtent.getWidth(),
projectionExtent.getHeight()) / 256;
@@ -28,6 +30,7 @@ var resolutions = new Array(10);
for (var i = 0; i < 10; ++i) {
resolutions[i] = maxResolution / Math.pow(2.0, i);
}
*/
var extent = new ol.Extent(420000, 30000, 900000, 350000);
var layers = new ol.Collection([
@@ -42,20 +45,18 @@ var layers = new ol.Collection([
'LAYERS': 'ch.swisstopo.pixelkarte-farbe-pk1000.noscale',
'FORMAT': 'image/jpeg'
},
projection: epsg21781,
extent: extent
})
}),
new ol.layer.ImageLayer({
source: new ol.source.SingleImageWMS({
//resolutions: resolutions,
url: 'http://wms.geo.admin.ch/',
attributions: [new ol.Attribution(
'&copy; ' +
'<a href="http://www.geo.admin.ch/internet/geoportal/en/home.html">' +
'National parks / geo.admin.ch</a>')],
params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'},
projection: epsg21781,
resolutions: resolutions
params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'}
})
})
]);