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 /** @name WMSLayer 27 @class 28 A layer to display WMS (Web Map Service) data. 29 @augments RasterLayer 30 @param options Configuration properties for the WMSLayer. See {@link RasterLayer} for base properties : 31 <ul> 32 <li>baseUrl : the base Url to access the WMS server</li> 33 <li>layers : the list of layers to request (WMS parameter)</li> 34 <li>srs : the spatial system reference to use, default is EPSG:4326 (WMS parameter)</li> 35 <li>format : the file format to request, default is image/jpeg (WMS parameter)</li> 36 </ul> 37 */ 38 var WMSLayer = function( options ) 39 { 40 RasterLayer.prototype.constructor.call( this, options ); 41 42 this.baseUrl = options['baseUrl']; 43 this.tilePixelSize = options['tilePixelSize'] || 256; 44 this.tiling = new GeoTiling( 4, 2 ); 45 this.numberOfLevels = options['numberOfLevels'] || 21; 46 47 // Build the base GetMap URL 48 var url = this.baseUrl; 49 if ( url.indexOf('?',0) == -1 ) 50 { 51 url += '?service=wms'; 52 } 53 else 54 { 55 url += '&service=wms'; 56 } 57 url += "&version=" 58 url += options.hasOwnProperty('version') ? options['version'] : '1.1.1'; 59 url += "&request=GetMap"; 60 url += "&srs="; 61 url += options.hasOwnProperty('srs') ? options['srs'] : 'EPSG:4326'; 62 url += "&layers=" + options['layers']; 63 if ( options.hasOwnProperty('styles') ) 64 { 65 url += "&styles=" + options.styles; 66 } 67 url += "&format="; 68 url += options.hasOwnProperty('format') ? options['format'] : 'image/jpeg'; 69 if ( options.hasOwnProperty('transparent') ) 70 { 71 url += "&transparent=" + options.transparent; 72 } 73 url += "&width="; 74 url += this.tilePixelSize; 75 url += "&height="; 76 url += this.tilePixelSize; 77 if ( options.hasOwnProperty('time') ) 78 { 79 url += "&time=" + options.time; 80 } 81 82 this.getMapBaseUrl = url; 83 } 84 85 /**************************************************************************************************************/ 86 87 Utils.inherits(RasterLayer,WMSLayer); 88 89 /**************************************************************************************************************/ 90 91 /** 92 Get an url for the given tile 93 */ 94 WMSLayer.prototype.getUrl = function(tile) 95 { 96 // Just add the bounding box to the GetMap URL 97 var geoBound = tile.geoBound; 98 var url = this.getMapBaseUrl; 99 url += "&bbox="; 100 101 url += geoBound.west; 102 url += ","; 103 url += geoBound.south; 104 url += ","; 105 url += geoBound.east; 106 url += ","; 107 url += geoBound.north; 108 109 // console.log(url); 110 111 return url; 112 } 113 114 /**************************************************************************************************************/ 115 116 return WMSLayer; 117 118 }); 119 120