Skip to content

Commit

Permalink
Merge pull request openlayers#3826 from klokantech/xyzsource-tilegrid
Browse files Browse the repository at this point in the history
Allow custom tileGrid in ol.source.XYZ
  • Loading branch information
ahocevar committed Jun 20, 2015
2 parents 5c5364b + 5993b45 commit 039b54d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
9 changes: 9 additions & 0 deletions externs/olx.js
Original file line number Diff line number Diff line change
Expand Up @@ -5358,6 +5358,7 @@ olx.source.WMTSOptions.prototype.wrapX;
* projection: ol.proj.ProjectionLike,
* maxZoom: (number|undefined),
* minZoom: (number|undefined),
* tileGrid: (ol.tilegrid.TileGrid|undefined),
* tileLoadFunction: (ol.TileLoadFunctionType|undefined),
* tilePixelRatio: (number|undefined),
* tileSize: (number|ol.Size|undefined),
Expand Down Expand Up @@ -5422,6 +5423,14 @@ olx.source.XYZOptions.prototype.maxZoom;
olx.source.XYZOptions.prototype.minZoom;


/**
* Tile grid.
* @type {ol.tilegrid.TileGrid}
* @api
*/
olx.source.XYZOptions.prototype.tileGrid;


/**
* Optional function to load a tile given a URL.
* @type {ol.TileLoadFunctionType|undefined}
Expand Down
11 changes: 6 additions & 5 deletions src/ol/source/xyzsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ ol.source.XYZ = function(options) {
var projection = goog.isDef(options.projection) ?
options.projection : 'EPSG:3857';

var tileGrid = ol.tilegrid.createXYZ({
extent: ol.tilegrid.extentFromProjection(projection),
maxZoom: options.maxZoom,
tileSize: options.tileSize
});
var tileGrid = goog.isDef(options.tileGrid) ? options.tileGrid :
ol.tilegrid.createXYZ({
extent: ol.tilegrid.extentFromProjection(projection),
maxZoom: options.maxZoom,
tileSize: options.tileSize
});

goog.base(this, {
attributions: options.attributions,
Expand Down
8 changes: 8 additions & 0 deletions test/spec/ol/source/xyzsource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ describe('ol.source.XYZ', function() {

describe('constructor', function() {

it('can be constructed with a custom tile grid', function() {
var tileGrid = ol.tilegrid.createXYZ();
var tileSource = new ol.source.XYZ({
tileGrid: tileGrid
});
expect(tileSource.getTileGrid()).to.be(tileGrid);
});

it('can be constructed with a custom tile size', function() {
var tileSource = new ol.source.XYZ({
tileSize: 512
Expand Down

0 comments on commit 039b54d

Please sign in to comment.