OpenLayers OpenLayers

Changeset 2195

Show
Ignore:
Timestamp:
02/02/07 08:48:21 (2 years ago)
Author:
emanuel
Message:

create animatedzooming dir
running features:
-simple scale all layers
-zoomout only with white frame

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/PanZoomBar.js

    r1721 r2195  
    2424    zoomStopHeight: 11, 
    2525 
     26 
     27/*** emanuel (31.1.07) ***/ 
     28 
     29    /** @type int */ 
     30    zoomlevel_startScale: null,   
     31     
     32    /** @type int */ 
     33    zoomlevel_scale: null,    
     34      
     35    /** @type OpenLayers.Size */ 
     36    tileSize_startScale: null,  
     37     
     38    /** @type OpenLayers.Size */ 
     39    tileSize_scale: null, 
     40 
     41/***/ 
     42 
    2643    initialize: function() { 
    2744        OpenLayers.Control.PanZoom.prototype.initialize.apply(this, arguments); 
    2845        this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoomBar.X, 
    2946                                             OpenLayers.Control.PanZoomBar.Y); 
     47/*** emanuel (31.1.07) ***/ 
     48        this.tileSize_scale = new OpenLayers.Size(); 
     49/***/                                              
    3050    }, 
    3151 
     
    169189        this.div.style.cursor = "move"; 
    170190        OpenLayers.Event.stop(evt); 
     191 
     192/*** emanuel (31.1.07) ***/ 
     193 
     194    //get current zoomlevel 
     195    this.zoomlevel_startScale = this.map.zoom; 
     196 
     197    //get original tile size 
     198    this.tileSize_startScale = this.map.getTileSize(); 
     199 
     200    //find tile, which contains the center of the viewport 
     201    this.map.findCenterTile(); 
     202 
     203    /*    
     204    //set all active overlays temporarily invisible 
     205    for (var i = 0; i < this.map.layers.length; i++) { 
     206        var layer = this.map.layers[i]; 
     207        if (!layer.isBaseLayer) { 
     208            this.map.layers[i].div.style.display = "none"; 
     209        } 
     210    } 
     211    */ 
     212/***/         
     213 
    171214    }, 
    172215     
     
    188231            this.mouseDragStart = evt.xy.clone(); 
    189232            OpenLayers.Event.stop(evt); 
     233 
     234 
     235/*** emanuel (31.1.07) ***/ 
     236 
     237            //convert current sliderposition to new zoomlevel 
     238            var deltaY_zoomlevel = this.zoomStart.y - evt.xy.y 
     239            this.zoomlevel_scale=this.zoomlevel_startScale +  
     240              deltaY_zoomlevel/this.zoomStopHeight; 
     241            
     242            //check the zoomlevel validity   
     243            if (this.zoomlevel_scale < 0){ 
     244                this.zoomlevel_scale = 0;  
     245            }  
     246            if (this.zoomlevel_scale >= this.map.getNumZoomLevels()){  
     247                this.zoomlevel_scale = this.map.getNumZoomLevels() - 1;  
     248            } 
     249             
     250            //calculate the new tile size for the scale... 
     251            //...zoomIn 
     252            if (this.zoomlevel_startScale < this.zoomlevel_scale) { 
     253                this.tileSize_scale.w =  
     254                  Math.pow(2,(this.zoomlevel_scale - 
     255                  this.zoomlevel_startScale)) * this.tileSize_startScale.w; 
     256                this.tileSize_scale.h =  
     257                  Math.pow(2,(this.zoomlevel_scale - 
     258                  this.zoomlevel_startScale)) * this.tileSize_startScale.h; 
     259            } 
     260            //...zoomOut / no zoomchanges 
     261            if (this.zoomlevel_startScale >= this.zoomlevel_scale) {              
     262                this.tileSize_scale.w = 
     263                  1/(Math.pow(2,(this.zoomlevel_startScale - 
     264                  this.zoomlevel_scale))) * this.tileSize_startScale.w; 
     265                this.tileSize_scale.h = 
     266                  1/(Math.pow(2,(this.zoomlevel_startScale -  
     267                  this.zoomlevel_scale))) * this.tileSize_startScale.h; 
     268            } 
     269 
     270            // set new scaled tile size  
     271            this.map.scaleTileTo(this.tileSize_scale); 
     272                         
     273/***/ 
     274             
    190275        } 
    191276    }, 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js

    r2091 r2195  
    2323    /** @type Integer */ 
    2424    buffer: 2, 
     25 
     26 
     27/*** emanuel (31.1.07) ***/ 
     28     
     29    /** @type OpenLayers.Tile */ 
     30    centerTile: null, 
     31 
     32    /** @type Integer */ 
     33    centerRow: null, 
     34 
     35    /** @type Integer */ 
     36    centerCol: null, 
     37 
     38    /** @type OpenLayers.Pixel */    
     39    centerTileStartScalePos: null, 
     40 
     41/***/ 
     42 
    2543 
    2644    /** 
     
    140158    }, 
    141159     
     160 
     161/*** emanuel (31.1.07) ***/ 
     162 
     163    /** finds and sets the tile, which contains the center  
     164     *  of the viewport 
     165     * 
     166     */ 
     167    findCenterTile:function() { 
     168         
     169        //get the center of the map (viewport) 
     170        var center = this.map.getCenter(); 
     171 
     172        //find tile, which contains the center of the viewport 
     173        this.centerTile = null; 
     174        if (this.grid) { 
     175            for (var iRow=0; iRow < this.grid.length; iRow++) { 
     176                for (var iCol=0; iCol < this.grid[iRow].length; iCol++) { 
     177                    var tileBounds = this.grid[iRow][iCol].bounds; 
     178                    if (tileBounds.containsLonLat(center, true)) { 
     179                        this.centerTile = this.grid[iRow][iCol]; 
     180                        this.centerRow = iRow; 
     181                        this.centerCol = iCol; 
     182                        break;  
     183                    } 
     184                } 
     185                if (this.centerTile) 
     186                    break; 
     187            } 
     188        } 
     189         
     190        //define real position of the center tile before scaling 
     191        //(It is tricky if you pan the map before scaling. Then the 
     192        //layerContainerDiv is only slided and you have to add this 
     193        //difference to the tile position) 
     194        var x = parseInt(this.centerTile.imgDiv.style.left) + 
     195          parseInt(this.map.layerContainerDiv.style.left); 
     196        var y = parseInt(this.centerTile.imgDiv.style.top) + 
     197          parseInt(this.map.layerContainerDiv.style.top); 
     198 
     199        this.centerTileStartScalePos = new OpenLayers.Pixel(x,y); 
     200    }, 
     201 
     202 
     203    /** scales all tiles to the new size (changes size  
     204     *  and position of every tile) 
     205     *  
     206     * @param {OpenLayers.Size} 
     207     */ 
     208    scaleTileTo:function(newTileSize) { 
     209         
     210        //convert the current center of the map in pixel 
     211        var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 
     212 
     213        //reposition the center tile  
     214        if (this.centerTile ) { 
     215            //set new left position 
     216            var leftOffset = newTileSize.w / this.centerTile.size.w * 
     217              (centerPx.x - this.centerTileStartScalePos.x); 
     218            leftOffset = Math.round(leftOffset); 
     219            var newLeftPos = centerPx.x - leftOffset 
     220              - parseInt(this.map.layerContainerDiv.style.left); 
     221            this.centerTile.imgDiv.style.left = newLeftPos + "px"; 
     222 
     223            //set new top position 
     224            var topOffset = newTileSize.h / this.centerTile.size.h * 
     225              (centerPx.y - this.centerTileStartScalePos.y); 
     226            topOffset = Math.round(topOffset); 
     227            var newTopPos = centerPx.y - topOffset  
     228              - parseInt(this.map.layerContainerDiv.style.top); 
     229            this.centerTile.imgDiv.style.top = newTopPos + "px"; 
     230        } 
     231         
     232        //reposition and resize all tiles of all active layers 
     233        var baseLayerGrid = this.grid; 
     234        for (var i = 0; i < this.map.layers.length; i++) { 
     235            var layerGrid = this.map.layers[i].grid; 
     236            //go through the whole grid of every layer 
     237            for (var iRow=0; iRow < layerGrid.length; iRow++) { 
     238                for (var iCol=0; iCol < layerGrid[iRow].length; iCol++) {  
     239                    if (layerGrid[iRow][iCol].imgDiv) { 
     240                        //define the factors for rows and columns (relates to the center tile) 
     241                        var deltaRow = iRow - this.centerRow; 
     242                        var deltaCol = iCol - this.centerCol; 
     243                         
     244                        //set new left position 
     245                        var newLeftPos = parseInt(this.centerTile.imgDiv.style.left) 
     246                          + deltaCol * newTileSize.w ; 
     247                        layerGrid[iRow][iCol].imgDiv.style.left = newLeftPos + "px"; 
     248 
     249                        //set new top position 
     250                        var newTopPos = parseInt(this.centerTile.imgDiv.style.top) 
     251                          + deltaRow * newTileSize.h ; 
     252                        layerGrid[iRow][iCol].imgDiv.style.top = newTopPos + "px"; 
     253 
     254                        //set new width and height 
     255                        layerGrid[iRow][iCol].imgDiv.style.width = newTileSize.w + "px"; 
     256                        layerGrid[iRow][iCol].imgDiv.style.height = newTileSize.h + "px"; 
     257                    } 
     258                } 
     259            } 
     260        } 
     261    }, 
     262 
     263/***/ 
     264 
     265 
     266     
    142267    /** 
    143268     * @private 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js

    r2167 r2195  
    709709        } 
    710710         
    711         var zoomChanged = (this.isValidZoomLevel(zoom)) &&  
    712                           (zoom != this.getZoom()); 
     711        var zoomChanged; 
     712        //if zoomlevel not changed -> is at least one overlay active? 
     713        //The active (temporarily invisible) overlays will not 
     714        //reposition after scaling to the _same_ zoomlevel.  
     715        //So, it it is necessary to redraw the grid by calling this  
     716        //setCenter function. 
     717        if (zoom == this.getZoom()) 
     718        { 
     719            for (var i = 0; i < this.layers.length; i++) { 
     720                var layer = this.layers[i]; 
     721                if (!layer.isBaseLayer) { 
     722                    if (layer.getVisibility()) 
     723                        zoomChanged = true; 
     724                } 
     725            } 
     726        } 
     727        else { //zoomlevel changed 
     728            zoomChanged = true; 
     729        } 
     730         
     731        zoomChanged = (this.isValidZoomLevel(zoom) && zoomChanged); 
    713732 
    714733        var centerChanged = (this.isValidLonLat(lonlat)) &&  
     
    835854    }, 
    836855 
     856 
     857/*** emanuel (31.1.07) ***/ 
     858 
     859    /** finds and sets the tile, which contains the center  
     860     *  of the viewport 
     861     * 
     862     */ 
     863    findCenterTile: function () { 
     864        this.baseLayer.findCenterTile(); 
     865    }, 
     866 
     867    /** scales all tiles to the new size (changes size  
     868     *  and position of every tile) 
     869     *  
     870     * @param {OpenLayers.Size} 
     871     */    
     872    scaleTileTo: function (newTileSize) { 
     873       this.baseLayer.scaleTileTo(newTileSize); 
     874    }, 
     875 
     876/***/ 
     877 
     878 
    837879  /********************************************************/ 
    838880  /*                                                      */