Skip to content

Commit

Permalink
Merge pull request #333 from fredj/swisstopo_source
Browse files Browse the repository at this point in the history
Add new gmf.source.Swisstopo
  • Loading branch information
fredj committed Nov 24, 2015
2 parents 0d7c655 + f1d44f7 commit 1edffe7
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contribs/gmf/exports/source/swisstoposource.js
@@ -0,0 +1,4 @@
goog.require('gmf.source.Swisstopo');


goog.exportSymbol('gmf.source.Swisstopo', gmf.source.Swisstopo);
31 changes: 31 additions & 0 deletions contribs/gmf/externs/gmfx.js
Expand Up @@ -105,6 +105,37 @@ gmfx.source.AsitVDOptions;
gmfx.source.AsitVDOptions.prototype.layer;


/**
* @typedef {{
* layer: string,
* format: (string|undefined),
* timestamp: string
* }}
*/
gmfx.source.SwisstopoOptions;


/**
* Layer name.
* @type {string}
*/
gmfx.source.SwisstopoOptions.prototype.layer;


/**
* Image format. Default is `png`.
* @type {string}
*/
gmfx.source.SwisstopoOptions.prototype.format;


/**
* The `Time` dimension of the source.
* @type {string}
*/
gmfx.source.SwisstopoOptions.prototype.timestamp;


/**
* Configuration object for the locationchooser component.
* @typedef {{
Expand Down
71 changes: 71 additions & 0 deletions contribs/gmf/src/source/swisstoposource.js
@@ -0,0 +1,71 @@
goog.provide('gmf.source.Swisstopo');

goog.require('ol.Attribution');
goog.require('ol.source.WMTS');
goog.require('ol.tilegrid.WMTS');


/**
* @const {!Array.<number>}
* @private
*/
gmf.source.SwisstopoResolutions_ = [
4000, 3750, 3500, 3250, 3000, 2750, 2500, 2250, 2000, 1750, 1500, 1250,
1000, 750, 650, 500, 250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5
];


/**
* @const {ol.tilegrid.WMTS}
* @private
*/
gmf.source.SwisstopoTileGrid_ = new ol.tilegrid.WMTS({
extent: [420000, 30000, 900000, 350000],
resolutions: gmf.source.SwisstopoResolutions_,
matrixIds: gmf.source.SwisstopoResolutions_.map(function(value, index) {
return String(index);
})
});



/**
* Layer source for the Swisstopo tile server.
* WARNING: This tile server is not publicly available: you have to be
* registered by Swisstopo to use the service.
* @see https://api3.geo.admin.ch/services/sdiservices.html#wmts
*
* @constructor
* @extends {ol.source.WMTS}
* @param {gmfx.source.SwisstopoOptions} options WMTS options.
*/
gmf.source.Swisstopo = function(options) {

var format = options.format ? options.format : 'png';

goog.base(this, {
attributions: [gmf.source.Swisstopo.ATTRIBUTION_],
url: 'https://wmts{5-9}.geo.admin.ch/1.0.0/{Layer}/default/{Time}' +
'/21781/{TileMatrix}/{TileRow}/{TileCol}.' + format,
dimensions: {
'Time': options.timestamp
},
projection: 'EPSG:21781',
requestEncoding: 'REST',
layer: options.layer,
style: 'default',
matrixSet: '21781',
format: 'image/' + format,
tileGrid: gmf.source.SwisstopoTileGrid_
});
};
goog.inherits(gmf.source.Swisstopo, ol.source.WMTS);


/**
* @const {ol.Attribution}
* @private
*/
gmf.source.Swisstopo.ATTRIBUTION_ = new ol.Attribution({
html: '&copy; <a href="http://www.swisstopo.admin.ch">swisstopo</a>'
});

0 comments on commit 1edffe7

Please sign in to comment.