diff --git a/src/js/HpxImageSurvey.js b/src/js/HpxImageSurvey.js index 00d01c1f..3ecec545 100644 --- a/src/js/HpxImageSurvey.js +++ b/src/js/HpxImageSurvey.js @@ -448,14 +448,56 @@ HpxImageSurvey = (function() { }; HpxImageSurvey.prototype.drawHighres = function(ctx, cornersXYViewMap, norder, view) { - var hpxKeys = []; - var tSize = this.tileSize || 512; +////////////////////////////// + var parentTilesToDraw = []; + var parentTilesToDrawIndex = {}; + var parentTilesMissingIndex = {}; for (var k=0; k=3 && parentOrder >= norder-MAX_UPPER_LEVELS ; parentOrder--) { + var parentIpix = ~~(ipix / Math.pow(4, norder - parentOrder)); + var key = parentOrder + '-' + parentIpix; + if (parentTilesToDrawIndex[key]===true || parentTilesMissingIndex===true) { + break; + } + var parentTileURL = this.getTileURL(parentOrder, parentIpix); + var parentTile = this.tileBuffer.getTile(parentTileURL); + var parentTileAvailable = parentTile && Tile.isImageOk(parentTile.img); + if (parentTileAvailable) { + parentTilesToDraw.push({ipix: parentIpix, order: parentOrder}); + parentTilesToDrawIndex[key] = true; + + break; + } + else { + parentTilesMissingIndex[key] = true; + } + } + } } - - for (var k=0; k").appendTo(this.aladinDiv)[0]; @@ -184,43 +184,42 @@ View = (function() { this.catalogCanvas = $("").appendTo(this.aladinDiv)[0]; // canvas to draw the reticle this.reticleCanvas = $("").appendTo(this.aladinDiv)[0]; - }; - - - // called at startup and when window is resized - View.prototype.fixLayoutDimensions = function() { + }; + + + // called at startup and when window is resized + View.prototype.fixLayoutDimensions = function() { Utils.cssScale = undefined; - - var computedWidth = $(this.aladinDiv).width(); - var computedHeight = $(this.aladinDiv).height(); - - this.width = Math.max(computedWidth, 1); - this.height = Math.max(computedHeight, 1); // this prevents many problems when div size is equal to 0 - - this.cx = this.width/2; - this.cy = this.height/2; - - this.largestDim = Math.max(this.width, this.height); - this.smallestDim = Math.min(this.width, this.height); - this.ratio = this.largestDim/this.smallestDim; + var computedWidth = $(this.aladinDiv).width(); + var computedHeight = $(this.aladinDiv).height(); - - this.mouseMoveIncrement = 160/this.largestDim; + this.width = Math.max(computedWidth, 1); + this.height = Math.max(computedHeight, 1); // this prevents many problems when div size is equal to 0 + + + this.cx = this.width/2; + this.cy = this.height/2; + + this.largestDim = Math.max(this.width, this.height); + this.smallestDim = Math.min(this.width, this.height); + this.ratio = this.largestDim/this.smallestDim; - - // reinitialize 2D context - this.imageCtx = this.imageCanvas.getContext("2d"); - this.catalogCtx = this.catalogCanvas.getContext("2d"); - this.reticleCtx = this.reticleCanvas.getContext("2d"); - - this.imageCtx.canvas.width = this.width; - this.catalogCtx.canvas.width = this.width; + + this.mouseMoveIncrement = 160/this.largestDim; + + // reinitialize 2D context + this.imageCtx = this.imageCanvas.getContext("2d"); + this.catalogCtx = this.catalogCanvas.getContext("2d"); + this.reticleCtx = this.reticleCanvas.getContext("2d"); + + this.imageCtx.canvas.width = this.width; + this.catalogCtx.canvas.width = this.width; this.reticleCtx.canvas.width = this.width; - - this.imageCtx.canvas.height = this.height; - this.catalogCtx.canvas.height = this.height; + + this.imageCtx.canvas.height = this.height; + this.catalogCtx.canvas.height = this.height; this.reticleCtx.canvas.height = this.height; pixelateCanvasContext(this.imageCtx); @@ -243,7 +242,7 @@ View = (function() { this.computeNorder(); this.requestRedraw(); - }; + }; var pixelateCanvasContext = function(ctx) { ctx.imageSmoothingEnabled = false; @@ -254,39 +253,39 @@ View = (function() { } - View.prototype.setMode = function(mode) { - this.mode = mode; - if (this.mode==View.SELECT) { - this.setCursor('crosshair'); - } + View.prototype.setMode = function(mode) { + this.mode = mode; + if (this.mode==View.SELECT) { + this.setCursor('crosshair'); + } else if (this.mode==View.TOOL_SIMBAD_POINTER) { this.popup.hide(); - this.reticleCanvas.style.cursor = ''; + this.reticleCanvas.style.cursor = ''; $(this.reticleCanvas).addClass('aladin-sp-cursor'); } - else { - this.setCursor('default'); - } - }; - - View.prototype.setCursor = function(cursor) { + else { + this.setCursor('default'); + } + }; + + View.prototype.setCursor = function(cursor) { if (this.reticleCanvas.style.cursor==cursor) { return; } if (this.mode==View.TOOL_SIMBAD_POINTER) { return; } - this.reticleCanvas.style.cursor = cursor; - }; + this.reticleCanvas.style.cursor = cursor; + }; - - - /** - * return dataURL string corresponding to the current view - */ - View.prototype.getCanvasDataURL = function(imgType, width, height) { + + + /** + * return dataURL string corresponding to the current view + */ + View.prototype.getCanvasDataURL = function(imgType, width, height) { imgType = imgType || "image/png"; - var c = document.createElement('canvas'); + var c = document.createElement('canvas'); width = width || this.width; height = height || this.height; c.width = width; @@ -296,28 +295,28 @@ View = (function() { ctx.drawImage(this.catalogCanvas, 0, 0, c.width, c.height); ctx.drawImage(this.reticleCanvas, 0, 0, c.width, c.height); - return c.toDataURL(imgType); - //return c.toDataURL("image/jpeg", 0.01); // setting quality only works for JPEG (?) - }; + return c.toDataURL(imgType); + //return c.toDataURL("image/jpeg", 0.01); // setting quality only works for JPEG (?) + }; - /** - * Compute the FoV in degrees of the view and update mouseMoveIncrement - * - * @param view - * @returns FoV (array of 2 elements : width and height) in degrees - */ - computeFov = function(view) { - var fov = doComputeFov(view, view.zoomFactor); - - - view.mouseMoveIncrement = fov/view.imageCanvas.width; - - return fov; - }; - - doComputeFov = function(view, zoomFactor) { - // if zoom factor < 1, we view 180° + /** + * Compute the FoV in degrees of the view and update mouseMoveIncrement + * + * @param view + * @returns FoV (array of 2 elements : width and height) in degrees + */ + computeFov = function(view) { + var fov = doComputeFov(view, view.zoomFactor); + + + view.mouseMoveIncrement = fov/view.imageCanvas.width; + + return fov; + }; + + doComputeFov = function(view, zoomFactor) { + // if zoom factor < 1, we view 180° var fov; if (view.zoomFactor<1) { fov = 180; @@ -336,13 +335,13 @@ View = (function() { } return fov; - }; - - updateFovDiv = function(view) { - if (isNaN(view.fov)) { - view.fovDiv.html("FoV:"); - return; - } + }; + + updateFovDiv = function(view) { + if (isNaN(view.fov)) { + view.fovDiv.html("FoV:"); + return; + } // update FoV value var fovStr; if (view.fov>1) { @@ -355,10 +354,10 @@ View = (function() { fovStr = Math.round(view.fov*3600*100)/100 + '"'; } view.fovDiv.html("FoV: " + fovStr); - }; - - - createListeners = function(view) { + }; + + + createListeners = function(view) { var hasTouchEvents = false; if ('ontouchstart' in window) { hasTouchEvents = true; @@ -731,13 +730,13 @@ View = (function() { return false; }); - }; - - var init = function(view) { + }; + + var init = function(view) { var stats = new Stats(); stats.domElement.style.top = '50px'; if ($('#aladin-statsDiv').length>0) { - $('#aladin-statsDiv')[0].appendChild( stats.domElement ); + $('#aladin-statsDiv')[0].appendChild( stats.domElement ); } view.stats = stats; @@ -782,18 +781,18 @@ View = (function() { view.displayCatalog = false; view.displayReticle = true; - // initial draw - view.fov = computeFov(view); - updateFovDiv(view); - - view.redraw(); - }; + // initial draw + view.fov = computeFov(view); + updateFovDiv(view); + + view.redraw(); + }; - function updateLocation(view, x, y, isViewCenterPosition) { - if (!view.projection) { - return; - } - var xy = AladinUtils.viewToXy(x, y, view.width, view.height, view.largestDim, view.zoomFactor); + function updateLocation(view, x, y, isViewCenterPosition) { + if (!view.projection) { + return; + } + var xy = AladinUtils.viewToXy(x, y, view.width, view.height, view.largestDim, view.zoomFactor); var lonlat; try { lonlat = view.projection.unproject(xy.x, xy.y); @@ -803,11 +802,11 @@ View = (function() { if (lonlat) { view.location.update(lonlat.ra, lonlat.dec, view.cooFrame, isViewCenterPosition); } - } - - View.prototype.requestRedrawAtDate = function(date) { - this.dateRequestDraw = date; - }; + } + + View.prototype.requestRedrawAtDate = function(date) { + this.dateRequestDraw = date; + }; /** * Return the color of the lowest intensity pixel @@ -845,42 +844,44 @@ View = (function() { height: this.height }; }; - - + + - /** - * redraw the whole view - */ - View.prototype.redraw = function() { - var saveNeedRedraw = this.needRedraw; - requestAnimFrame(this.redraw.bind(this)); + /** + * redraw the whole view + */ + View.prototype.redraw = function() { + var saveNeedRedraw = this.needRedraw; + requestAnimFrame(this.redraw.bind(this)); - var now = new Date().getTime(); - - if (this.dateRequestDraw && now>this.dateRequestDraw) { - this.dateRequestDraw = null; - } - else if (! this.needRedraw) { + var now = new Date().getTime(); + + if (this.dateRequestDraw && now>this.dateRequestDraw) { + this.dateRequestDraw = null; + } + else if (! this.needRedraw) { if ( ! this.flagForceRedraw) { - return; + return; } else { this.flagForceRedraw = false; } - } - this.stats.update(); + } + this.stats.update(); - var imageCtx = this.imageCtx; - //////// 1. Draw images //////// - - //// clear canvas //// - // TODO : do not need to clear if fov small enough ? - imageCtx.clearRect(0, 0, this.imageCanvas.width, this.imageCanvas.height); - //////////////////////// - - var bkgdColor = this.getBackgroundColor(); - // fill with background of the same color than the first color map value (lowest intensity) + var imageCtx = this.imageCtx; + //////// 1. Draw images //////// + if (imageCtx.start2D) { + imageCtx.start2D(); + } + //// clear canvas //// + // TODO : do not need to clear if fov small enough ? + imageCtx.clearRect(0, 0, this.imageCanvas.width, this.imageCanvas.height); + //////////////////////// + + var bkgdColor = this.getBackgroundColor(); + // fill with background of the same color than the first color map value (lowest intensity) if (this.projectionMethod==ProjectionEnum.SIN) { if (this.fov>=60) { imageCtx.fillStyle = bkgdColor; @@ -903,18 +904,21 @@ View = (function() { imageCtx.fill(); } } + if (imageCtx.finish2D) { + imageCtx.finish2D(); + } - this.projection.setCenter(this.viewCenter.lon, this.viewCenter.lat); + this.projection.setCenter(this.viewCenter.lon, this.viewCenter.lat); // do we have to redo that every time? Probably not - this.projection.setProjection(this.projectionMethod); - + this.projection.setProjection(this.projectionMethod); + - // ************* Draw allsky tiles (low resolution) ***************** + // ************* Draw allsky tiles (low resolution) ***************** var cornersXYViewMapHighres = null; // Pour traitement des DEFORMATIONS --> TEMPORAIRE, draw deviendra la methode utilisee systematiquement - if (this.imageSurvey && this.imageSurvey.isReady && this.displaySurvey) { + if (this.imageSurvey && this.imageSurvey.isReady && this.displaySurvey) { if (this.aladin.reduceDeformations==null) { this.imageSurvey.draw(imageCtx, this, !this.dragging, this.curNorder); } @@ -925,35 +929,35 @@ View = (function() { } /* else { - var cornersXYViewMapAllsky = this.getVisibleCells(3); - var cornersXYViewMapHighres = null; - if (this.curNorder>=3) { - if (this.curNorder==3) { - cornersXYViewMapHighres = cornersXYViewMapAllsky; - } - else { - cornersXYViewMapHighres = this.getVisibleCells(this.curNorder); - } - } + var cornersXYViewMapAllsky = this.getVisibleCells(3); + var cornersXYViewMapHighres = null; + if (this.curNorder>=3) { + if (this.curNorder==3) { + cornersXYViewMapHighres = cornersXYViewMapAllsky; + } + else { + cornersXYViewMapHighres = this.getVisibleCells(this.curNorder); + } + } - // redraw image survey - if (this.imageSurvey && this.imageSurvey.isReady && this.displaySurvey) { - // TODO : a t on besoin de dessiner le allsky si norder>=3 ? - // TODO refactoring : should be a method of HpxImageSurvey - this.imageSurvey.redrawAllsky(imageCtx, cornersXYViewMapAllsky, this.fov, this.curNorder); + // redraw image survey + if (this.imageSurvey && this.imageSurvey.isReady && this.displaySurvey) { + // TODO : a t on besoin de dessiner le allsky si norder>=3 ? + // TODO refactoring : should be a method of HpxImageSurvey + this.imageSurvey.redrawAllsky(imageCtx, cornersXYViewMapAllsky, this.fov, this.curNorder); if (this.curNorder>=3) { this.imageSurvey.redrawHighres(imageCtx, cornersXYViewMapHighres, this.curNorder); } - } + } } */ - + // redraw overlay image survey - // TODO : does not work if different frames + // TODO : does not work if different frames // TODO: use HpxImageSurvey.draw method !! - if (this.overlayImageSurvey && this.overlayImageSurvey.isReady) { - imageCtx.globalAlpha = this.overlayImageSurvey.getAlpha(); + if (this.overlayImageSurvey && this.overlayImageSurvey.isReady) { + imageCtx.globalAlpha = this.overlayImageSurvey.getAlpha(); if (this.aladin.reduceDeformations==null) { this.overlayImageSurvey.draw(imageCtx, this, !this.dragging, this.curOverlayNorder); @@ -963,40 +967,40 @@ View = (function() { this.overlayImageSurvey.draw(imageCtx, this, this.aladin.reduceDeformations, this.curOverlayNorder); } /* - if (this.fov>50) { - this.overlayImageSurvey.redrawAllsky(imageCtx, cornersXYViewMapAllsky, this.fov, this.curOverlayNorder); - } - if (this.curOverlayNorder>=3) { + if (this.fov>50) { + this.overlayImageSurvey.redrawAllsky(imageCtx, cornersXYViewMapAllsky, this.fov, this.curOverlayNorder); + } + if (this.curOverlayNorder>=3) { var norderOverlay = Math.min(this.curOverlayNorder, this.overlayImageSurvey.maxOrder); if ( cornersXYViewMapHighres==null || norderOverlay != this.curNorder ) { - cornersXYViewMapHighres = this.getVisibleCells(norderOverlay); + cornersXYViewMapHighres = this.getVisibleCells(norderOverlay); } - this.overlayImageSurvey.redrawHighres(imageCtx, cornersXYViewMapHighres, norderOverlay); - } + this.overlayImageSurvey.redrawHighres(imageCtx, cornersXYViewMapHighres, norderOverlay); + } */ imageCtx.globalAlpha = 1.0; - } - - - // redraw HEALPix grid + } + + + // redraw HEALPix grid if( this.displayHpxGrid) { - var cornersXYViewMapAllsky = this.getVisibleCells(3); - var cornersXYViewMapHighres = null; - if (this.curNorder>=3) { - if (this.curNorder==3) { - cornersXYViewMapHighres = cornersXYViewMapAllsky; - } - else { - cornersXYViewMapHighres = this.getVisibleCells(this.curNorder); - } - } - if (cornersXYViewMapHighres && this.curNorder>3) { - this.healpixGrid.redraw(imageCtx, cornersXYViewMapHighres, this.fov, this.curNorder); - } + var cornersXYViewMapAllsky = this.getVisibleCells(3); + var cornersXYViewMapHighres = null; + if (this.curNorder>=3) { + if (this.curNorder==3) { + cornersXYViewMapHighres = cornersXYViewMapAllsky; + } + else { + cornersXYViewMapHighres = this.getVisibleCells(this.curNorder); + } + } + if (cornersXYViewMapHighres && this.curNorder>3) { + this.healpixGrid.redraw(imageCtx, cornersXYViewMapHighres, this.fov, this.curNorder); + } else { - this.healpixGrid.redraw(imageCtx, cornersXYViewMapAllsky, this.fov, 3); + this.healpixGrid.redraw(imageCtx, cornersXYViewMapAllsky, this.fov, 3); } } @@ -1008,107 +1012,107 @@ View = (function() { this.cooGrid.redraw(imageCtx, this.projection, this.cooFrame, this.width, this.height, this.largestDim, this.zoomFactor, this.fov); } - + - ////// 2. Draw catalogues//////// - var catalogCtx = this.catalogCtx; + ////// 2. Draw catalogues//////// + var catalogCtx = this.catalogCtx; - var catalogCanvasCleared = false; + var catalogCanvasCleared = false; if (this.mustClearCatalog) { catalogCtx.clearRect(0, 0, this.width, this.height); catalogCanvasCleared = true; this.mustClearCatalog = false; } - if (this.catalogs && this.catalogs.length>0 && this.displayCatalog && (! this.dragging || View.DRAW_SOURCES_WHILE_DRAGGING)) { - // TODO : do not clear every time - //// clear canvas //// - if (! catalogCanvasCleared) { - catalogCtx.clearRect(0, 0, this.width, this.height); + if (this.catalogs && this.catalogs.length>0 && this.displayCatalog && (! this.dragging || View.DRAW_SOURCES_WHILE_DRAGGING)) { + // TODO : do not clear every time + //// clear canvas //// + if (! catalogCanvasCleared) { + catalogCtx.clearRect(0, 0, this.width, this.height); catalogCanvasCleared = true; - } - for (var i=0; i0) { if (! catalogCanvasCleared) { - catalogCtx.clearRect(0, 0, this.width, this.height); + catalogCtx.clearRect(0, 0, this.width, this.height); catalogCanvasCleared = true; } this.catalogForPopup.draw(catalogCtx, this.projection, this.cooFrame, this.width, this.height, this.largestDim, this.zoomFactor); } - ////// 3. Draw overlays//////// + ////// 3. Draw overlays//////// var overlayCtx = this.catalogCtx; - if (this.overlays && this.overlays.length>0 && (! this.dragging || View.DRAW_SOURCES_WHILE_DRAGGING)) { - if (! catalogCanvasCleared) { - catalogCtx.clearRect(0, 0, this.width, this.height); + if (this.overlays && this.overlays.length>0 && (! this.dragging || View.DRAW_SOURCES_WHILE_DRAGGING)) { + if (! catalogCanvasCleared) { + catalogCtx.clearRect(0, 0, this.width, this.height); catalogCanvasCleared = true; - } - for (var i=0; i0 && (! this.dragging || View.DRAW_MOCS_WHILE_DRAGGING)) { - if (! catalogCanvasCleared) { - catalogCtx.clearRect(0, 0, this.width, this.height); + if (this.mocs && this.mocs.length>0 && (! this.dragging || View.DRAW_MOCS_WHILE_DRAGGING)) { + if (! catalogCanvasCleared) { + catalogCtx.clearRect(0, 0, this.width, this.height); catalogCanvasCleared = true; - } + } for (var i=0; i=60 && this.aladin.options['showAllskyRing'] === true) { @@ -1121,21 +1125,21 @@ View = (function() { imageCtx.stroke(); } - - // draw selection box - if (this.mode==View.SELECT && this.dragging) { - reticleCtx.fillStyle = "rgba(100, 240, 110, 0.25)"; - var w = this.dragx - this.selectStartCoo.x; - var h = this.dragy - this.selectStartCoo.y; - - reticleCtx.fillRect(this.selectStartCoo.x, this.selectStartCoo.y, w, h); - } + + // draw selection box + if (this.mode==View.SELECT && this.dragging) { + reticleCtx.fillStyle = "rgba(100, 240, 110, 0.25)"; + var w = this.dragx - this.selectStartCoo.x; + var h = this.dragy - this.selectStartCoo.y; + + reticleCtx.fillRect(this.selectStartCoo.x, this.selectStartCoo.y, w, h); + } - // TODO : is this the right way? - if (saveNeedRedraw==this.needRedraw) { - this.needRedraw = false; - } + // TODO : is this the right way? + if (saveNeedRedraw==this.needRedraw) { + this.needRedraw = false; + } // objects lookup @@ -1146,7 +1150,7 @@ View = (function() { // execute 'positionChanged' and 'zoomChanged' callbacks this.executeCallbacksThrottled(); - }; + }; View.prototype.forceRedraw = function() { this.flagForceRedraw = true; @@ -1167,7 +1171,7 @@ View = (function() { var nside = Math.pow(2, norder); var pixList; - var npix = HealpixIndex.nside2Npix(nside); + var npix = HealpixIndex.nside2Npix(nside); if (this.fov>80) { pixList = []; for (var ipix=0; ipix80) { - pixList = []; - for (var ipix=0; ipix80) { + pixList = []; + for (var ipix=0; ipix60) { + radius *= 1.6; + } + else if (this.fov>12) { + radius *=1.45; } - var radius = this.fov*0.5*this.ratio; - // we need to extend the radius - if (this.fov>60) { - radius *= 1.6; - } - else if (this.fov>12) { - radius *=1.45; - } else { radius *= 1.1; } - - - - pixList = hpxIdx.queryDisc(spatialVector, radius*Math.PI/180.0, true, true); - // add central pixel at index 0 - var polar = Utils.radecToPolar(lonlat[0], lonlat[1]); - ipixCenter = hpxIdx.ang2pix_nest(polar.theta, polar.phi); - pixList.unshift(ipixCenter); - } - - - var ipix; - var lon, lat; - for (var ipixIdx=0, len=pixList.length; ipixIdx0) { - continue; - } - var cornersXYView = []; - corners = HealpixCache.corners_nest(ipix, nside); + + + + pixList = hpxIdx.queryDisc(spatialVector, radius*Math.PI/180.0, true, true); + // add central pixel at index 0 + var polar = Utils.radecToPolar(lonlat[0], lonlat[1]); + ipixCenter = hpxIdx.ang2pix_nest(polar.theta, polar.phi); + pixList.unshift(ipixCenter); + } + + + var ipix; + var lon, lat; + for (var ipixIdx=0, len=pixList.length; ipixIdx0) { + continue; + } + var cornersXYView = []; + corners = HealpixCache.corners_nest(ipix, nside); - for (var k=0; k<4; k++) { - spVec.setXYZ(corners[k].x, corners[k].y, corners[k].z); - - // need for frame transformation ? - if (frameSurvey && frameSurvey.system != this.cooFrame.system) { - if (frameSurvey.system == CooFrameEnum.SYSTEMS.J2000) { - var radec = CooConversion.J2000ToGalactic([spVec.ra(), spVec.dec()]); - lon = radec[0]; - lat = radec[1]; - } - else if (frameSurvey.system == CooFrameEnum.SYSTEMS.GAL) { - var radec = CooConversion.GalacticToJ2000([spVec.ra(), spVec.dec()]); - lon = radec[0]; - lat = radec[1]; - } - } - else { - lon = spVec.ra(); - lat = spVec.dec(); - } - - cornersXY[k] = this.projection.project(lon, lat); - } + for (var k=0; k<4; k++) { + spVec.setXYZ(corners[k].x, corners[k].y, corners[k].z); + + // need for frame transformation ? + if (frameSurvey && frameSurvey.system != this.cooFrame.system) { + if (frameSurvey.system == CooFrameEnum.SYSTEMS.J2000) { + var radec = CooConversion.J2000ToGalactic([spVec.ra(), spVec.dec()]); + lon = radec[0]; + lat = radec[1]; + } + else if (frameSurvey.system == CooFrameEnum.SYSTEMS.GAL) { + var radec = CooConversion.GalacticToJ2000([spVec.ra(), spVec.dec()]); + lon = radec[0]; + lat = radec[1]; + } + } + else { + lon = spVec.ra(); + lat = spVec.dec(); + } + + cornersXY[k] = this.projection.project(lon, lat); + } - if (cornersXY[0] == null || cornersXY[1] == null || cornersXY[2] == null || cornersXY[3] == null ) { - continue; - } + if (cornersXY[0] == null || cornersXY[1] == null || cornersXY[2] == null || cornersXY[3] == null ) { + continue; + } - for (var k=0; k<4; k++) { - cornersXYView[k] = AladinUtils.xyToView(cornersXY[k].X, cornersXY[k].Y, this.width, this.height, this.largestDim, this.zoomFactor); - } + for (var k=0; k<4; k++) { + cornersXYView[k] = AladinUtils.xyToView(cornersXY[k].X, cornersXY[k].Y, this.width, this.height, this.largestDim, this.zoomFactor); + } var indulge = 10; // detect pixels outside view. Could be improved ! @@ -1354,108 +1358,108 @@ View = (function() { } - // check if pixel is visible -// if (this.fov<160) { // don't bother checking if fov is large enough -// if ( ! AladinUtils.isHpxPixVisible(cornersXYView, this.width, this.height) ) { -// continue; -// } -// } - // check if we have a pixel at the edge of the view in AITOFF --> TO BE MODIFIED - if (this.projection.PROJECTION==ProjectionEnum.AITOFF) { - var xdiff = cornersXYView[0].vx-cornersXYView[2].vx; - var ydiff = cornersXYView[0].vy-cornersXYView[2].vy; - var distDiag = Math.sqrt(xdiff*xdiff + ydiff*ydiff); - if (distDiag>this.largestDim/5) { - continue; - } - xdiff = cornersXYView[1].vx-cornersXYView[3].vx; - ydiff = cornersXYView[1].vy-cornersXYView[3].vy; - distDiag = Math.sqrt(xdiff*xdiff + ydiff*ydiff); - if (distDiag>this.largestDim/5) { - continue; - } - } - - cornersXYView.ipix = ipix; - cells.push(cornersXYView); - } - - return cells; - }; - - - - // get position in view for a given HEALPix cell - View.prototype.getPositionsInView = function(ipix, norder) { - var cornersXY = []; - var lon, lat; - var spVec = new SpatialVector(); - var nside = Math.pow(2, norder); // TODO : to be modified - - - var cornersXYView = []; // will be returned - var corners = HealpixCache.corners_nest(ipix, nside); + // check if pixel is visible +// if (this.fov<160) { // don't bother checking if fov is large enough +// if ( ! AladinUtils.isHpxPixVisible(cornersXYView, this.width, this.height) ) { +// continue; +// } +// } + // check if we have a pixel at the edge of the view in AITOFF --> TO BE MODIFIED + if (this.projection.PROJECTION==ProjectionEnum.AITOFF) { + var xdiff = cornersXYView[0].vx-cornersXYView[2].vx; + var ydiff = cornersXYView[0].vy-cornersXYView[2].vy; + var distDiag = Math.sqrt(xdiff*xdiff + ydiff*ydiff); + if (distDiag>this.largestDim/5) { + continue; + } + xdiff = cornersXYView[1].vx-cornersXYView[3].vx; + ydiff = cornersXYView[1].vy-cornersXYView[3].vy; + distDiag = Math.sqrt(xdiff*xdiff + ydiff*ydiff); + if (distDiag>this.largestDim/5) { + continue; + } + } + + cornersXYView.ipix = ipix; + cells.push(cornersXYView); + } + + return cells; + }; + + + + // get position in view for a given HEALPix cell + View.prototype.getPositionsInView = function(ipix, norder) { + var cornersXY = []; + var lon, lat; + var spVec = new SpatialVector(); + var nside = Math.pow(2, norder); // TODO : to be modified + + + var cornersXYView = []; // will be returned + var corners = HealpixCache.corners_nest(ipix, nside); - for (var k=0; k<4; k++) { - spVec.setXYZ(corners[k].x, corners[k].y, corners[k].z); - - // need for frame transformation ? - if (this.imageSurvey && this.imageSurvey.cooFrame.system != this.cooFrame.system) { - if (this.imageSurvey.cooFrame.system == CooFrameEnum.SYSTEMS.J2000) { - var radec = CooConversion.J2000ToGalactic([spVec.ra(), spVec.dec()]); - lon = radec[0]; - lat = radec[1]; - } - else if (this.imageSurvey.cooFrame.system == CooFrameEnum.SYSTEMS.GAL) { - var radec = CooConversion.GalacticToJ2000([spVec.ra(), spVec.dec()]); - lon = radec[0]; - lat = radec[1]; - } - } - else { - lon = spVec.ra(); - lat = spVec.dec(); - } - - cornersXY[k] = this.projection.project(lon, lat); - } - - if (cornersXY[0] == null || cornersXY[1] == null || cornersXY[2] == null || cornersXY[3] == null ) { + for (var k=0; k<4; k++) { + spVec.setXYZ(corners[k].x, corners[k].y, corners[k].z); + + // need for frame transformation ? + if (this.imageSurvey && this.imageSurvey.cooFrame.system != this.cooFrame.system) { + if (this.imageSurvey.cooFrame.system == CooFrameEnum.SYSTEMS.J2000) { + var radec = CooConversion.J2000ToGalactic([spVec.ra(), spVec.dec()]); + lon = radec[0]; + lat = radec[1]; + } + else if (this.imageSurvey.cooFrame.system == CooFrameEnum.SYSTEMS.GAL) { + var radec = CooConversion.GalacticToJ2000([spVec.ra(), spVec.dec()]); + lon = radec[0]; + lat = radec[1]; + } + } + else { + lon = spVec.ra(); + lat = spVec.dec(); + } + + cornersXY[k] = this.projection.project(lon, lat); + } + + if (cornersXY[0] == null || cornersXY[1] == null || cornersXY[2] == null || cornersXY[3] == null ) { return null; } - for (var k=0; k<4; k++) { - cornersXYView[k] = AladinUtils.xyToView(cornersXY[k].X, cornersXY[k].Y, this.width, this.height, this.largestDim, this.zoomFactor); - } + for (var k=0; k<4; k++) { + cornersXYView[k] = AladinUtils.xyToView(cornersXY[k].X, cornersXY[k].Y, this.width, this.height, this.largestDim, this.zoomFactor); + } - return cornersXYView; - }; - - - View.prototype.computeZoomFactor = function(level) { - if (level>0) { - return AladinUtils.getZoomFactorForAngle(180/Math.pow(1.15, level), this.projectionMethod); - } - else { - return 1 + 0.1*level; - } - }; - - View.prototype.setZoom = function(fovDegrees) { - if (fovDegrees<0 || fovDegrees>180) { - return; - } - var zoomLevel = Math.log(180/fovDegrees)/Math.log(1.15); - this.setZoomLevel(zoomLevel); - }; - - View.prototype.setShowGrid = function(showGrid) { - this.showGrid = showGrid; - this.requestRedraw(); - }; + return cornersXYView; + }; + + + View.prototype.computeZoomFactor = function(level) { + if (level>0) { + return AladinUtils.getZoomFactorForAngle(180/Math.pow(1.15, level), this.projectionMethod); + } + else { + return 1 + 0.1*level; + } + }; + + View.prototype.setZoom = function(fovDegrees) { + if (fovDegrees<0 || fovDegrees>180) { + return; + } + var zoomLevel = Math.log(180/fovDegrees)/Math.log(1.15); + this.setZoomLevel(zoomLevel); + }; + + View.prototype.setShowGrid = function(showGrid) { + this.showGrid = showGrid; + this.requestRedraw(); + }; - + View.prototype.setZoomLevel = function(level) { if (this.minFOV || this.maxFOV) { var newFov = doComputeFov(this, this.computeZoomFactor(Math.max(-2, level))); @@ -1494,15 +1498,15 @@ View = (function() { this.computeNorder(); this.forceRedraw(); - this.requestRedraw(); - + this.requestRedraw(); + // on avertit les catalogues progressifs if (! this.debounceProgCatOnZoom) { var self = this; this.debounceProgCatOnZoom = Utils.debounce(function() {self.refreshProgressiveCats();}, 300); } this.debounceProgCatOnZoom(); - + }; /** @@ -1546,7 +1550,7 @@ View = (function() { this.curNorder = norder; this.curOverlayNorder = overlayNorder; }; - + View.prototype.untaintCanvases = function() { this.createCanvases(); createListeners(this); @@ -1602,43 +1606,43 @@ View = (function() { var unknownSurveyId = undefined; // @param imageSurvey : HpxImageSurvey object or image survey identifier - View.prototype.setImageSurvey = function(imageSurvey, callback) { - if (! imageSurvey) { - return; - } - - // reset canvas to "untaint" canvas if needed - // we test if the previous base image layer was using CORS or not - if ($.support.cors && this.imageSurvey && ! this.imageSurvey.useCors) { - this.untaintCanvases(); - } - - var newImageSurvey; - if (typeof imageSurvey == "string") { - newImageSurvey = HpxImageSurvey.getSurveyFromId(imageSurvey); - if ( ! newImageSurvey) { - newImageSurvey = HpxImageSurvey.getSurveyFromId(HpxImageSurvey.DEFAULT_SURVEY_ID); + View.prototype.setImageSurvey = function(imageSurvey, callback) { + if (! imageSurvey) { + return; + } + + // reset canvas to "untaint" canvas if needed + // we test if the previous base image layer was using CORS or not + if ($.support.cors && this.imageSurvey && ! this.imageSurvey.useCors) { + this.untaintCanvases(); + } + + var newImageSurvey; + if (typeof imageSurvey == "string") { + newImageSurvey = HpxImageSurvey.getSurveyFromId(imageSurvey); + if ( ! newImageSurvey) { + newImageSurvey = HpxImageSurvey.getSurveyFromId(HpxImageSurvey.DEFAULT_SURVEY_ID); unknownSurveyId = imageSurvey; - } - } - else { - newImageSurvey = imageSurvey; - } - - // do not touch the tileBuffer if we load the exact same HiPS (in that case, should we stop here??) + } + } + else { + newImageSurvey = imageSurvey; + } + + // do not touch the tileBuffer if we load the exact same HiPS (in that case, should we stop here??) if (newImageSurvey && this.imageSurvey && newImageSurvey.hasOwnProperty('id') && this.imageSurvey.hasOwnProperty('id') && newImageSurvey.id==this.imageSurvey.id) { // do nothing } else { - // buffer reset - this.tileBuffer = new TileBuffer(); + // buffer reset + this.tileBuffer = new TileBuffer(); } - newImageSurvey.isReady = false; - this.imageSurvey = newImageSurvey; + newImageSurvey.isReady = false; + this.imageSurvey = newImageSurvey; this.projection.reverseLongitude(this.imageSurvey.longitudeReversed); - + var self = this; newImageSurvey.init(this, function() { //self.imageSurvey = newImageSurvey; @@ -1651,20 +1655,20 @@ View = (function() { callback(); } }); - }; - - View.prototype.requestRedraw = function() { - this.needRedraw = true; - }; - - View.prototype.changeProjection = function(projectionMethod) { - this.projectionMethod = projectionMethod; - this.requestRedraw(); - }; + }; + + View.prototype.requestRedraw = function() { + this.needRedraw = true; + }; + + View.prototype.changeProjection = function(projectionMethod) { + this.projectionMethod = projectionMethod; + this.requestRedraw(); + }; - View.prototype.changeFrame = function(cooFrame) { + View.prototype.changeFrame = function(cooFrame) { var oldCooFrame = this.cooFrame; - this.cooFrame = cooFrame; + this.cooFrame = cooFrame; // recompute viewCenter if (this.cooFrame.system == CooFrameEnum.SYSTEMS.GAL && this.cooFrame.system != oldCooFrame.system) { var lb = CooConversion.J2000ToGalactic([this.viewCenter.lon, this.viewCenter.lat]); @@ -1679,8 +1683,8 @@ View = (function() { this.location.update(this.viewCenter.lon, this.viewCenter.lat, this.cooFrame, true); - this.requestRedraw(); - }; + this.requestRedraw(); + }; View.prototype.showHealpixGrid = function(show) { this.displayHpxGrid = show; @@ -1716,13 +1720,13 @@ View = (function() { return; } if (this.cooFrame.system==CooFrameEnum.SYSTEMS.J2000) { - this.viewCenter.lon = ra; - this.viewCenter.lat = dec; + this.viewCenter.lon = ra; + this.viewCenter.lat = dec; } else if (this.cooFrame.system==CooFrameEnum.SYSTEMS.GAL) { var lb = CooConversion.J2000ToGalactic([ra, dec]); - this.viewCenter.lon = lb[0]; - this.viewCenter.lat = lb[1]; + this.viewCenter.lon = lb[0]; + this.viewCenter.lat = lb[1]; } this.location.update(this.viewCenter.lon, this.viewCenter.lat, this.cooFrame, true);