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( ['./RasterLayer', './Utils', './GeoTiling' ],
 21 		function(RasterLayer, KeyboardNavigationHandler, GeoTiling) {
 22 
 23 /**************************************************************************************************************/
 24 
 25 /** @export
 26 	@constructor
 27 	BasicElevationLayer constructor
 28  */
 29 var BasicElevationLayer = function( options )
 30 {
 31 	RasterLayer.prototype.constructor.call( this, options );
 32 	this.tilePixelSize = options['tilePixelSize'] || 33;
 33 	this.tiling = new GeoTiling( 4, 2 );
 34 	this.numberOfLevels = options['numberOfLevels'] || 21;
 35 	this.type = "ElevationRaster";
 36 	this.baseUrl = options['baseUrl'];
 37 }
 38 
 39 Utils.inherits(RasterLayer, BasicElevationLayer);
 40 
 41 /**************************************************************************************************************/
 42 
 43 /**
 44 	Get an url for the given tile
 45  */
 46 BasicElevationLayer.prototype.getUrl = function(tile)
 47 {
 48 	var geoBound = tile.geoBound;
 49 	var url = this.baseUrl;
 50 	url += "?extent=";
 51 /*
 52 	var deltaLon = (extent[1] - extent[0]) / size;
 53 	var deltaLat = (extent[2] - extent[3]) / size;
 54 
 55 	url += extent[0] - 0.5 * deltaLon;
 56 	url += ",";
 57 	url += extent[3] - 0.5 * deltaLat;
 58 	url += ",";
 59 	url += extent[1] + 0.5 * deltaLon;
 60 	url += ",";
 61 	url += extent[2] + 0.5 * deltaLat;*/
 62 
 63 	url += geoBound.west;
 64 	url += ",";
 65 	url += geoBound.south;
 66 	url += ",";
 67 	url += geoBound.east;
 68 	url += ",";
 69 	url += geoBound.north;
 70 
 71 	url += "&size="
 72 	url += this.tilePixelSize;
 73 	url += ","
 74 	url += this.tilePixelSize;
 75 	
 76 	return url;
 77 }
 78 
 79 /**************************************************************************************************************/
 80 
 81 /**
 82 	Parse a elevation response
 83  */
 84 BasicElevationLayer.prototype.parseElevations = function(text)
 85 {
 86 	var elevations = JSON.parse( text );
 87 	
 88 	// Remove invalid elevations
 89 	for ( var i = 0; i < elevations.length; i++ )
 90 	{
 91 		if ( elevations[i] < 0.0 )
 92 		{
 93 			elevations[i] = 0.0;
 94 		}
 95 	}
 96 	
 97 	return elevations;
 98 }
 99 
100 /**************************************************************************************************************/
101 
102 return BasicElevationLayer;
103 
104 });
105