1 /*************************************** 2 * Copyright 2011, 2012 GlobWeb contributors. 3 * 4 * This file is part of GlobWeb. 5 * 6 * GlobWeb is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * GlobWeb is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with GlobWeb. If not, see <http://www.gnu.org/licenses/>. 18 ***************************************/ 19 20 define(['./Utils', './RasterLayer', './GeoTiling'], 21 function(Utils, RasterLayer, GeoTiling) { 22 23 /**************************************************************************************************************/ 24 25 26 /** @export 27 @constructor 28 WMTSLayer constructor 29 */ 30 var WMTSLayer = function( options ) 31 { 32 RasterLayer.prototype.constructor.call( this, options ); 33 34 this.baseUrl = options['baseUrl']; 35 this.tilePixelSize = options['tilePixelSize'] || 256; 36 this.tiling = new GeoTiling( 4, 2 ); 37 this.numberOfLevels = options['numberOfLevels'] || 21; 38 this.type = "ImageryRaster"; 39 this.startLevel = options['startLevel'] || 1; 40 41 // Build the base GetTile URL 42 var url = this.baseUrl; 43 if ( url.indexOf('?',0) == -1 ) 44 { 45 url += '?service=wmts'; 46 } 47 else 48 { 49 url += '&service=wmts'; 50 } 51 url += "&version=" 52 url += options['version'] || '1.0.0'; 53 url += "&request=GetTile"; 54 url += "&layer=" + options['layer']; 55 url += "&tilematrixset=" + options['matrixSet']; 56 if ( options['style'] ) 57 { 58 url += "&style=" + options.style; 59 } 60 url += "&format="; 61 url += options['format'] || 'image/png'; 62 if ( options['time'] ) 63 { 64 url += "&time=" + options.time; 65 } 66 67 this.getTileBaseUrl = url; 68 } 69 70 /**************************************************************************************************************/ 71 72 Utils.inherits(RasterLayer,WMTSLayer); 73 74 /**************************************************************************************************************/ 75 76 /** 77 Get an url for the given tile 78 */ 79 WMTSLayer.prototype.getUrl = function(tile) 80 { 81 var url = this.getTileBaseUrl; 82 url += "&tilematrix="; 83 url += tile.level + this.startLevel; 84 url += "&tilecol=" + tile.x; 85 url += "&tilerow=" + tile.y; 86 87 return url; 88 } 89 90 /**************************************************************************************************************/ 91 92 return WMTSLayer; 93 94 }); 95 96