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', './HEALPixTiling', './RasterLayer'], 21 function(Utils, HEALPixTiling, RasterLayer) { 22 23 /**************************************************************************************************************/ 24 25 /** @export 26 @constructor 27 HEALPixLayer constructor 28 */ 29 30 var HEALPixLayer = function(options) 31 { 32 RasterLayer.prototype.constructor.call( this, options ); 33 34 this.tilePixelSize = options.tilePixelSize || 512; 35 this.tiling = new HEALPixTiling( options.baseLevel || 3, options ); 36 this.numberOfLevels = options.numberOfLevels || 10; 37 this.type = "ImageryRaster"; 38 this.baseUrl = options['baseUrl']; 39 40 // allsky 41 this.levelZeroImage = new Image(); 42 var self = this; 43 this.levelZeroImage.crossOrigin = ''; 44 this.levelZeroImage.onload = function () 45 { 46 self._ready = true; 47 48 // Call callback if set 49 if (options.onready && options.onready instanceof Function) 50 { 51 options.onready(self); 52 } 53 54 // Request a frame 55 if ( self.globe ) 56 { 57 self.globe.renderContext.requestFrame(); 58 } 59 } 60 this.levelZeroImage.onerror = function(event) { 61 console.log("Cannot load " + self.levelZeroImage.src ); 62 } 63 64 this._ready = false; 65 } 66 67 /**************************************************************************************************************/ 68 69 Utils.inherits(RasterLayer, HEALPixLayer); 70 71 /**************************************************************************************************************/ 72 73 /** 74 Attach the raster layer to the globe 75 */ 76 HEALPixLayer.prototype._attach = function( g ) 77 { 78 RasterLayer.prototype._attach.call( this, g ); 79 80 // Load level zero image now 81 this.levelZeroImage.src = this.baseUrl + "/Norder3/Allsky.jpg"; 82 } 83 84 /**************************************************************************************************************/ 85 86 /** 87 * Get url from a given tile 88 */ 89 HEALPixLayer.prototype.getUrl = function(tile) 90 { 91 var url = this.baseUrl; 92 93 url += "/Norder"; 94 url += tile.order; 95 96 url += "/Dir"; 97 var indexDirectory = Math.floor(tile.pixelIndex/10000) * 10000; 98 url += indexDirectory; 99 100 url += "/Npix"; 101 url += tile.pixelIndex; 102 url += ".jpg"; 103 104 return url; 105 } 106 107 /**************************************************************************************************************/ 108 109 return HEALPixLayer; 110 111 });