OpenLayers OpenLayers

Changeset 2292

Show
Ignore:
Timestamp:
03/01/07 11:57:42 (2 years ago)
Author:
emanuel
Message:

animated zooming 1.4

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/emanuel/animatedZooming/demo.html

    r2275 r2292  
    44        #map { 
    55            width: 100%; 
    6             height: 512px; 
     6            height: 511px; 
    77            border: 1px solid black; 
    88        } 
     
    1010    <title>Animated Zooming Demo</title> 
    1111     
    12     <!-- this gmaps key generated for http://openlayers.org/dev/ --> 
    13  <!--   <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>--> 
    14  
    1512    <script src="./lib/OpenLayers.js"></script> 
    1613    <script type="text/javascript"> 
     
    2320                map.addControl(new OpenLayers.Control.PanZoomBar()); 
    2421                map.addControl(new OpenLayers.Control.MouseToolbar()); 
     22                map.addControl(new OpenLayers.Control.KeyboardDefaults()); 
    2523                map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); 
    2624                map.addControl(new OpenLayers.Control.MousePosition()); 
     
    4341                new OpenLayers.Size(580, 288), 
    4442                {maxResolution: 'auto', numZoomLevels: 5});  
    45             /*             
    46             var satellite_google = new OpenLayers.Layer.Google(  
    47                 "Google Satellite",  
    48                 {type: G_SATELLITE_MAP, 'maxZoomLevel':18} );*/ 
    49  
     43      
    5044            var dm_wms = new OpenLayers.Layer.WMS( "DM Solutions Demo", 
    5145                "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap", 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Control.js

    r1721 r2292  
    7171        } 
    7272        this.moveTo(this.position);         
     73 
    7374        return this.div; 
    7475    }, 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/KeyboardDefaults.js

    r1721 r2292  
    1414 
    1515    /** @type int */ 
    16     slideFactor: 50, 
     16    slideFactor: 100, 
    1717 
    1818    /** 
     
    2727     */ 
    2828    draw: function() { 
     29//keypress 
    2930        OpenLayers.Event.observe(document,  
    3031                      'keypress',  
    31                       this.defaultKeyDown.bind(this)); 
     32                      this.defaultKeyDown.bindAsEventListener(this)); 
     33        OpenLayers.Event.observe(document,  
     34                      'keyup',  
     35                      this.defaultKeyUp.bindAsEventListener(this)); 
    3236    }, 
    3337     
     
    3842        switch(evt.keyCode) { 
    3943            case OpenLayers.Event.KEY_LEFT: 
    40                 this.map.pan(-50, 0); 
     44                this.map.pan(-75, 0); 
    4145                break; 
    4246            case OpenLayers.Event.KEY_RIGHT:  
    43                 this.map.pan(50, 0); 
     47                this.map.pan(75, 0); 
    4448                break; 
    4549            case OpenLayers.Event.KEY_UP: 
    46                 this.map.pan(0, -50); 
     50                this.map.pan(0, -75); 
    4751                break; 
    4852            case OpenLayers.Event.KEY_DOWN: 
    49                 this.map.pan(0, 50); 
     53                this.map.pan(0, 75); 
    5054                break; 
     55            case 33: // Page Up   
     56                var size = this.map.getSize(); 
     57                this.map.pan(0, -0.75*size.h); 
     58                break; 
     59            case 34: // Page Down   
     60                var size = this.map.getSize(); 
     61                this.map.pan(0, 0.75*size.h); 
     62                break;  
     63            case 35: // End   
     64                var size = this.map.getSize(); 
     65                this.map.pan(0.75*size.w, 0); 
     66                break;  
     67            case 36: // Pos1   
     68                var size = this.map.getSize(); 
     69                this.map.pan(-0.75*size.w, 0); 
     70                break;  
    5171        } 
     72        switch(evt.charCode) {  
     73            case 43: // +  
     74                // get and set some settings for zoom animation  
     75                this.map.prepareZoomAnimation(); 
     76                this.map.zoomlevel_scale += 0.2; 
     77                // run zoom animation -> scale tile(s) 
     78                this.map.runZoomAnimation(); 
     79                break;  
     80            case 45: // -  
     81                // get and set some settings for zoom animation  
     82                this.map.prepareZoomAnimation(); 
     83                this.map.zoomlevel_scale -= 0.2; 
     84                // run zoom animation -> scale tile(s) 
     85                this.map.runZoomAnimation(); 
     86                break;  
     87        }      
    5288    }, 
    5389     
     90    defaultKeyUp: function (evt) { 
     91        switch(evt.keyCode) { 
     92            case 107: 
     93                if((this.map.zoomlevel_scale-this.map.zoomlevel_startScale) < 1) 
     94                { 
     95                    //this.map.zoomlevel_scale = Math.ceil(this.map.zoomlevel_scale); 
     96                    //this.map.runZoomAnimation(); 
     97                    this.map.zoomTo(this.map.zoomlevel_startScale+1); 
     98                } 
     99                //this.map.finishZoomAnimation(Math.round(this.map.zoomlevel_scale)); 
     100 
     101            case 109: 
     102                if((this.map.zoomlevel_scale-this.map.zoomlevel_startScale) < 1) 
     103                { 
     104                    Math.floor(this.map.zoomlevel_scale); 
     105                    this.map.runZoomAnimation(); 
     106                } 
     107                // finish zoom animation 
     108                this.map.finishZoomAnimation(Math.round(this.map.zoomlevel_scale)); 
     109                break; 
     110 
     111        } 
     112 
     113 
     114 
     115    }, 
     116 
     117 
    54118    /** @final @type String */ 
    55119    CLASS_NAME: "OpenLayers.Control.KeyboardDefaults" 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseDefaults.js

    r2102 r2292  
    6969    */ 
    7070    defaultDblClick: function (evt) { 
     71        //var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );  
     72        //this.map.setCenter(newCenter, this.map.zoom + 1); 
     73 
     74        // convert the (old) center of the map in pixel 
     75        var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 
     76         
     77        // pan to new center    
     78        var deltaX = evt.xy.x - centerPx.x;  
     79        var deltaY = evt.xy.y - centerPx.y;  
     80        // some problems if you pan AND zoom in the same time... TODO 
     81        this.map.pan(deltaX, deltaY,true); 
     82 
     83        // 1. jump to new center (no pan animation!) 
    7184        var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );  
    72         this.map.setCenter(newCenter, this.map.zoom + 1); 
     85        //this.map.setCenter(newCenter, this.map.zoom); 
     86                
     87        // 2. zoom to new level  
     88        this.map.zoomIn();  
     89 
    7390        OpenLayers.Event.stop(evt); 
    7491        return false; 
     
    171188    defaultWheelUp: function(evt) { 
    172189        if (this.map.getZoom() <= this.map.getNumZoomLevels()) { 
    173             this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), 
    174                                this.map.getZoom() + 1); 
     190            if (!this.map.zoomanimationActive) { 
     191                // convert the current center of the map in pixel 
     192                var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 
     193 
     194                // determine lonlat from target (mouse position) 
     195                var targetLonLat = this.map.getLonLatFromViewPortPx( evt.xy );  
     196 
     197                // determine offset target-center in pixel 
     198                var offset = new OpenLayers.Pixel(); 
     199                offset.x = evt.xy.x - centerPx.x; 
     200                offset.y = evt.xy.y - centerPx.y; 
     201 
     202                // convert offset of zoomlevel n to zoomlevel n+1 
     203                offset.x = offset.x / 2; 
     204                offset.y = offset.y / 2; 
     205 
     206                // pan to new center    
     207                this.map.pan(offset.x, offset.y, true); 
     208 
     209                // zoom to new level  
     210                this.map.zoomIn(); 
     211            } 
    175212        } 
    176213    }, 
     
    181218    defaultWheelDown: function(evt) { 
    182219        if (this.map.getZoom() > 0) { 
    183             this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), 
    184                                this.map.getZoom() - 1); 
     220            if (!this.map.zoomanimationActive) { 
     221                // convert the current center of the map in pixel 
     222                var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 
     223 
     224                // determine lonlat from target (mouse position) 
     225                var targetLonLat = this.map.getLonLatFromViewPortPx( evt.xy );  
     226 
     227                // determine offset target-center in pixel... 
     228                var offset = new OpenLayers.Pixel(); 
     229                offset.x = evt.xy.x - centerPx.x; 
     230                offset.y = evt.xy.y - centerPx.y; 
     231 
     232                // convert offset of zoomlevel n to zoomlevel n-1 
     233                offset.x = -offset.x; 
     234                offset.y = -offset.y; 
     235 
     236                // pan to new center    
     237                this.map.pan(offset.x, offset.y, true); 
     238 
     239                // zoom to new level  
     240                this.map.zoomOut(); 
     241            } 
    185242        } 
    186243    }, 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseToolbar.js

    r2102 r2292  
    4949        centered = centered.add((this.direction == "vertical" ? 0 : sz.w), (this.direction == "vertical" ? sz.h : 0)); 
    5050        this.switchModeTo("pan"); 
    51  
    52         this.registerWheelEvents(); 
     51         
     52        // already registered in MouseDefaults 
     53        //this.registerWheelEvents(); 
    5354 
    5455        return this.div; 
     
    111112        this.switchModeTo("pan"); 
    112113        this.performedDrag = false; 
     114 
     115        // convert the (old) center of the map in pixel 
     116        var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 
     117         
     118        // pan to new center    
     119        var deltaX = evt.xy.x - centerPx.x;  
     120        var deltaY = evt.xy.y - centerPx.y;  
     121        // some problems if you pan AND zoom in the same time... TODO 
     122        this.map.pan(deltaX, deltaY,true); 
     123 
     124        // jump to new center (no pan animation!) 
    113125        var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );  
    114         this.map.setCenter(newCenter, this.map.zoom + 1); 
     126        //this.map.setCenter(newCenter, this.map.zoom); 
     127 
     128        // get tile below mouseposition 
     129        var targetTile = evt.target; 
     130        // 2. zoom to new level  
     131        this.map.zoomIn(targetTile);         
     132 
    115133        OpenLayers.Event.stop(evt); 
    116134        return false; 
     
    240258    */ 
    241259    defaultMouseMove: function (evt) { 
     260        // record the mouse position, used in onWheelEvent 
     261        this.mousePosition = evt.xy.clone(); 
     262 
    242263        if (this.mouseDragStart != null) { 
    243264            switch (this.mode) { 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/PanZoom.js

    r2224 r2292  
    1616 
    1717    /** @type int */ 
    18     slideFactor: 50, 
     18    slideFactor: 100, 
    1919 
    2020    /** @type Array of Button Divs */ 
     
    115115        switch (this.action) { 
    116116            case "panup":  
    117                 this.map.pan(0, -50); 
     117                this.map.pan(0, -this.slideFactor); 
    118118                break; 
    119119            case "pandown":  
    120                 this.map.pan(0, 50); 
     120                this.map.pan(0, this.slideFactor); 
    121121                break; 
    122122            case "panleft":  
    123                 this.map.pan(-50, 0); 
     123                this.map.pan(-this.slideFactor, 0); 
    124124                break; 
    125125            case "panright":  
    126                 this.map.pan(50, 0); 
     126                this.map.pan(this.slideFactor, 0); 
    127127                break; 
    128128            case "zoomin":  
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/PanZoomBar.js

    r2275 r2292  
    2424    zoomStopHeight: 11, 
    2525 
    26     /** @type int */ 
    27     zoomlevel_startScale: null,   
    28      
    29     /** @type float */ 
    30     zoomlevel_scale: null,    
    31       
    32     /** @type OpenLayers.Size */ 
    33     tileSize_startScale: null,  
    34      
    35     /** @type OpenLayers.Size */ 
    36     tileSize_scale: null, 
    37   
    38     /** @type OpenLayers.Tile */ 
    39     centerTile: null, 
    40      
    41     /** @type float */ 
    42     resolution_scale: null, 
    4326 
    4427    initialize: function() { 
     
    4629        this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoomBar.X, 
    4730                                             OpenLayers.Control.PanZoomBar.Y); 
    48         this.tileSize_scale = new OpenLayers.Size(); 
    4931    }, 
    5032 
     
    172154        var top = OpenLayers.Util.pagePosition(evt.object)[1]; 
    173155        var levels = Math.floor((y - top)/this.zoomStopHeight); 
    174         this.map.zoomTo((this.map.getNumZoomLevels() -1) -  levels); 
    175         OpenLayers.Event.stop(evt); 
    176     }, 
    177      
    178     /*  
    179      * @param evt 
    180      * event listener for clicks on the slider 
    181      */ 
    182     zoomBarDown:function(evt) { 
    183         if (!OpenLayers.Event.isLeftClick(evt)) return; 
    184         this.map.events.register("mousemove", this, this.passEventToSlider); 
    185         this.map.events.register("mouseup", this, this.passEventToSlider); 
    186         this.mouseDragStart = evt.xy.clone(); 
    187         this.zoomStart = evt.xy.clone(); 
    188         this.div.style.cursor = "move"; 
    189          
     156 
    190157        // get current zoomlevel 
    191         this.zoomlevel_startScale = this.map.zoom; 
     158        this.map.zoomlevel_startScale = this.map.zoom; 
    192159 
    193160        // get current tile size (it's the base for scaling) 
    194         this.tileSize_startScale = this.map.baseLayer.getTileSize(); 
     161        this.map.tileSize_startScale = this.map.baseLayer.getTileSize(); 
    195162       
    196163        // get tile, which contains the center of the viewport 
    197         this.centerTile = this.map.baseLayer.getCenterTile();    
     164        this.map.centerTile = this.map.baseLayer.getCenterTile();    
    198165 
    199166        //set all active overlays temporarily invisible 
     
    204171            } 
    205172        }         
     173 
     174 
     175        this.map.zoomTo((this.map.getNumZoomLevels() -1) -  levels); 
     176        //this.moveZoomBar((this.map.getNumZoomLevels() -1) -  levels); 
     177        OpenLayers.Event.stop(evt); 
     178    }, 
     179     
     180    /*  
     181     * @param evt 
     182     * event listener for clicks on the slider 
     183     */ 
     184    zoomBarDown:function(evt) { 
     185        if (!OpenLayers.Event.isLeftClick(evt)) return; 
     186        this.map.events.register("mousemove", this, this.passEventToSlider); 
     187        this.map.events.register("mouseup", this, this.passEventToSlider); 
     188        this.mouseDragStart = evt.xy.clone(); 
     189        this.map.zoomStart = evt.xy.clone(); 
     190        this.div.style.cursor = "move"; 
     191        
     192        // get and set some settings for zoom animation  
     193        this.map.prepareZoomAnimation(); 
    206194         
    207195        OpenLayers.Event.stop(evt); 
     
    224212            } 
    225213            this.mouseDragStart = evt.xy.clone(); 
    226              
    227              
    228             // scale baselayer if tileSize and centerTile is set 
    229             if ( this.tileSize_startScale && this.centerTile ) { 
    230  
    231                 // determine zoomlevel 
    232                 this.calculateNewZoomlevel(evt); 
    233                 
    234                 // determine tile size and map resolution 
    235                 this.calculateNewTileSize(); 
    236  
    237                 // scale (center) tile to new scaled size    
    238                 this.map.baseLayer.scaleTileTo(this.centerTile,  
    239                                                         this.tileSize_scale); 
    240                  
    241                 // scale all tiles to new scaled size (if there 
    242                 // are more than one tile) 
    243                 this.map.baseLayer.scaleTilesOfGrid(this.centerTile,  
    244                                                         this.tileSize_scale); 
    245  
    246                 // scale zoomOut tile (to prevent a white frame during zoomOut) 
    247                 this.map.baseLayer.scaleZoomOutTile(this.tileSize_scale, 
    248                                                         this.zoomlevel_scale,  
    249                                                         this.resolution_scale); 
    250  
    251                 // set new scaled map resolution (important for overviewmap) 
    252                 this.map.setScaleResolution(this.resolution_scale); 
    253             } 
    254  
     214            
     215            // set current slider position 
     216            var sliderPosition = new OpenLayers.Pixel(evt.xy.x, evt.xy.y);  
     217 
     218            // run zoom animation -> scale tile(s) 
     219            this.map.runZoomAnimation(this.zoomStopHeight, sliderPosition); 
     220       
    255221            OpenLayers.Event.stop(evt); 
    256222        } 
     
    264230    zoomBarUp:function(evt) { 
    265231        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    266         if (this.zoomStart) { 
     232        if (this.map.zoomStart) { 
    267233            this.div.style.cursor="default"; 
    268234            this.map.events.unregister("mouseup", this, this.passEventToSlider); 
    269235            this.map.events.unregister("mousemove", this, this.passEventToSlider); 
    270             var deltaY = this.zoomStart.y - evt.xy.y 
    271    
    272             // clone layerContainer for "smooth tile update" without blank map 
    273             this.map.baseLayer.cloneLayerContainer(); 
    274  
     236            var deltaY = this.map.zoomStart.y - evt.xy.y 
     237  
    275238            // zoom map to new zoomlevel 
    276             this.map.zoomTo(this.map.zoom + Math.round(deltaY/this.zoomStopHeight)); 
     239            var finalZoomlevel = this.map.zoom + Math.round(deltaY/this.zoomStopHeight); 
     240 
     241            // finish zoom animation 
     242            this.map.finishZoomAnimation(finalZoomlevel); 
     243 
    277244            this.moveZoomBar(); 
    278245            this.mouseDragStart = null; 
     
    282249     
    283250     
    284     /** 
    285      * Calculates new zoomlevel of current zoomslider position. 
    286      * 
    287      */ 
    288     calculateNewZoomlevel:function(evt) { 
    289         // convert current sliderposition to new zoomlevel 
    290         var deltaY_zoomlevel = this.zoomStart.y - evt.xy.y; 
    291         this.zoomlevel_scale = this.zoomlevel_startScale +  
    292           deltaY_zoomlevel/this.zoomStopHeight; 
    293         
    294         // check zoomlevel validity  
    295         if (this.zoomlevel_scale < 0) { 
    296             this.zoomlevel_scale = 0;  
    297         }  
    298         if (this.zoomlevel_scale > (this.map.getNumZoomLevels()-1)) {  
    299             this.zoomlevel_scale = this.map.getNumZoomLevels() - 1;  
    300         } 
    301     }, 
    302  
    303  
    304     /** 
    305      * Calculates new tile size and map resolution of current zoomlevel. 
    306      * 
    307      */ 
    308     calculateNewTileSize:function() { 
    309         // calculate new tile size for... 
    310         // ...zoomIn 
    311         if (this.zoomlevel_startScale < this.zoomlevel_scale) { 
    312             this.tileSize_scale.w = Math.pow(2,(this.zoomlevel_scale - 
    313               this.zoomlevel_startScale)) * this.tileSize_startScale.w; 
    314             this.tileSize_scale.h = Math.pow(2,(this.zoomlevel_scale - 
    315               this.zoomlevel_startScale)) * this.tileSize_startScale.h; 
    316  
    317             // set new map resolution 
    318             this.resolution_scale = 1/(Math.pow(2,(this.zoomlevel_scale -  
    319               this.zoomlevel_startScale))) *  this.map.getResolution();     
    320         } 
    321         // ...zoomOut / no zoom changes 
    322         if (this.zoomlevel_startScale >= this.zoomlevel_scale) {              
    323             this.tileSize_scale.w = 1/(Math.pow(2,(this.zoomlevel_startScale - 
    324               this.zoomlevel_scale))) * this.tileSize_startScale.w; 
    325             this.tileSize_scale.h = 1/(Math.pow(2,(this.zoomlevel_startScale -  
    326               this.zoomlevel_scale))) * this.tileSize_startScale.h; 
    327  
    328             // set new map resolution 
    329             this.resolution_scale = Math.pow(2,(this.zoomlevel_startScale -  
    330               this.zoomlevel_scale)) * this.map.getResolution();  
    331         } 
    332     }, 
    333251 
    334252 
    335253    /*  
    336254    * Change the location of the slider to match the current zoom level. 
     255    * 
     256    * @param {float} zoomlevel 
    337257    */ 
    338     moveZoomBar:function() { 
    339         var newTop =  
    340             ((this.map.getNumZoomLevels()-1) - this.map.getZoom()) *  
     258    moveZoomBar:function(zoomlevel) { 
     259        // check if zoomlevel is not a number 
     260        if (isNaN(zoomlevel)) { 
     261            zoomlevel = this.map.getZoom(); 
     262        } 
     263 
     264        // set new top position 
     265        var newTop = ((this.map.getNumZoomLevels()-1) - zoomlevel) * 
    341266            this.zoomStopHeight + this.startTop + 1; 
    342267        this.slider.style.top = newTop + "px"; 
    343268    },     
    344      
     269 
     270 
    345271    CLASS_NAME: "OpenLayers.Control.PanZoomBar" 
    346272}); 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer.js

    r2280 r2292  
    529529            var center = this.map.getCenter(); 
    530530            var res  = this.map.getResolution(); 
    531          
    532             var delta_x = viewPortPx.x - (size.w / 2); 
    533             var delta_y = viewPortPx.y - (size.h / 2); 
     531             
     532            var delta_x = viewPortPx.x - Math.ceil((size.w / 2)); 
     533            var delta_y = viewPortPx.y - Math.ceil((size.h / 2)); 
    534534             
    535535            lonlat = new OpenLayers.LonLat(center.lon + delta_x * res , 
     
    546546     * @type OpenLayers.Pixel 
    547547     */ 
    548     getViewPortPxFromLonLat: function (lonlat) { 
     548    getViewPortPxFromLonLat: function (lonlat, resolution) { 
    549549        var px = null;  
    550550        if (lonlat != null) { 
    551             var resolution = this.map.getResolution(); 
     551            if (!resolution) 
     552                resolution = this.map.getResolution(); 
    552553            var extent = this.map.getExtent(); 
    553554            px = new OpenLayers.Pixel( 
     
    700701        // (now the cloned div is above the original; it hides the original) 
    701702        this.map.viewPortDiv.appendChild(this.map.layerContainerDivClone); 
     703         
     704        this.map.layerContainerDiv.style.display= "none"; 
     705 
    702706    }, 
    703707 
     
    713717        // function for map only; not for overviewmap! 
    714718        if (this.map.div.id == "map") {         
    715             // set cloned layerDiv invisibile -> original div is visible                
    716             if (this.map.layerContainerDivClone){ 
    717                 this.map.layerContainerDivClone.style.display= "none"; 
    718             } 
    719  
    720719            // set zoomOutTile invisible 
    721720            if (this.map.baseLayer.zoomOutTile){ 
    722721                this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none"; 
    723722            } 
     723            // set cloned layerDiv invisibile -> original div is visible                
     724            if (this.map.layerContainerDivClone){ 
     725                this.map.layerContainerDivClone.style.display= "none"; 
     726                this.map.layerContainerDiv.style.display= "block"; 
     727 
     728            } 
     729 
     730 
    724731        } 
    725732    }, 
     
    750757     */ 
    751758    scaleTileTo:function(tile, newTileSize) { 
    752          
    753759        //convert the center of the map in pixel 
    754760        var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 
     
    855861        var centerLonLat = extent.getCenterLonLat(); 
    856862          
    857         if( bounds.containsLonLat(centerLonLat) 
    858             && !(extent.equals(maxExtent))) { 
     863    /*    if( bounds.containsLonLat(centerLonLat) 
     864            && !(extent.equals(maxExtent))) {*/ 
    859865            var offsetlon = bounds.left - centerLonLat.lon; 
    860866            var offsetlat = -bounds.top + centerLonLat.lat; 
     
    869875             
    870876            // set zoomOutTile visible if viewport < map bounds 
    871             if ( (bounds.left < extent.left) || (bounds.right > extent.right) )  
     877           /* if ( (bounds.left < extent.left) || (bounds.right > 
     878 * extent.right) )*/  
    872879                this.map.baseLayer.zoomOutTile.imgDiv.style.display = "block"; 
    873             else 
     880/*            else 
    874881                this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none"; 
    875         } 
     882//        }*/ 
    876883         
    877884        return true; 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js

    r2280 r2292  
    547547    /**  
    548548     * Gets tile, which contains the center of the viewport. 
    549      *  
     549     * 
    550550     * @returns the tile, which contains the center of the viewport 
    551551     * @type OpenLayers.Tile 
    552552     */ 
    553553    getCenterTile:function() { 
     554        var center = this.map.getCenter(); 
     555 
    554556        if (this.grid) { 
    555557            for (var iRow=0; iRow < this.grid.length; iRow++) { 
    556558                for (var iCol=0; iCol < this.grid[iRow].length; iCol++) { 
    557559                    var tileBounds = this.grid[iRow][iCol].bounds; 
    558                     if (tileBounds.containsLonLat(this.map.getCenter(), true)) { 
     560                    if (tileBounds.containsLonLat(center, true)) { 
    559561                        this.centerRow = iRow; 
    560562                        this.centerCol = iCol; 
  • sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js

    r2275 r2292  
    131131    theme: null, 
    132132 
     133 
     134    //ANIMATION 
     135     
     136    /** @type Boolean */ 
     137    animated: true, 
     138 
     139    /** steps in the slide 
     140     *  
     141     * @type int */ 
     142    slideSteps: 7,   
     143     
     144    /** millisecondss between each step 
     145     *  
     146     * @type int */ 
     147    slideWait: 0, 
     148 
     149    /** power used to calculate width of slide steps 
     150     *  
     151     * @type float*/ 
     152    slidePower: 0.7, 
     153 
     154    /** @type int */ 
     155    animatedPanningIntervalID: null, 
     156 
     157    /** @type int */ 
     158    animatedZoomingIntervalID: null, 
     159 
     160 
     161    /** @type boolean */ 
     162    zoomanimationActive: false, 
     163 
    133164    /** @type int */ 
    134165    zoomOutTileSizeFactor: 4, 
     166 
     167    /** @type int */ 
     168    zoomlevel_startScale: null,   
     169     
     170    /** @type float */ 
     171    zoomlevel_scale: null,    
     172      
     173    /** @type OpenLayers.Size */ 
     174    tileSize_startScale: null,  
     175     
     176    /** @type OpenLayers.Size */ 
     177    tileSize_scale: null, 
     178  
     179    /** @type OpenLayers.Tile */ 
     180    centerTile: null, 
     181     
     182    /** @type float */ 
     183    resolution_scale: null, 
    135184 
    136185    /** 
     
    212261                      'unload',  
    213262                      this.destroy.bindAsEventListener(this)); 
     263 
     264        this.tileSize_scale = new OpenLayers.Size(); 
    214265    }, 
    215266 
     
    711762        return this.zoom; 
    712763    }, 
    713      
     764 
    714765    /** Allows user to pan by a value of screen pixels 
    715766     *  
    716767     * @param {int} dx 
    717768     * @param {int} dy 
    718      */ 
    719     pan: function(dx, dy) { 
    720  
    721         // getCenter 
    722         var centerPx = this.getViewPortPxFromLonLat(this.getCenter()); 
    723  
    724         // adjust 
    725         var newCenterPx = centerPx.add(dx, dy); 
    726          
    727         // only call setCenter if there has been a change 
    728         if (!newCenterPx.equals(centerPx)) { 
    729             var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 
    730             this.setCenter(newCenterLonLat); 
    731         } 
    732  
    733    }, 
     769     * @param {Boolean} animated  
     770     */ 
     771    pan: function(dx, dy, animated) { 
     772 
     773        if (animated == null) {  
     774            animated = this.animated;  
     775        }  
     776         
     777        if (animated) { 
     778            this.panSlide(dx, dy,  
     779                          this.slideSteps,  
     780                          this.slideWait,  
     781                          this.slidePower); 
     782        } else { 
     783 
     784            // getCenter 
     785            var centerPx = this.getViewPortPxFromLonLat(this.getCenter()); 
     786     
     787            // adjust 
     788            var newCenterPx = centerPx.add(dx, dy); 
     789     
     790            // only call setCenter if there has been a change 
     791            if (!newCenterPx.equals(centerPx)) { 
     792                var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 
     793                this.setCenter(newCenterLonLat, null, null, this.animated); 
     794            } 
     795        } 
     796    }, 
     797     
    734798 
    735799    /** 
     
    840904    }, 
    841905 
     906    /** Position changer with Memory by www.hesido.com 
     907     *  modified by dncpax for OpenLayers 
     908     *  
     909     * @param {int} slideX 
     910     * @param {int} slideY 
     911     * @param {int} totalSteps 
     912     * @param {int} intervals 
     913     * @param {float} power  
     914     */ 
     915    panSlide: function( slideX, slideY, totalSteps, interval, power) { 
     916        if (this.animatedPanningIntervalID) { 
     917            window.clearInterval(this.animatedPanningIntervalID); 
     918            this.animatedPanningIntervalID = null; 
     919        } 
     920        var context = { 
     921            'map': this, 
     922            'slideX': slideX, 
     923            'slideY': slideY, 
     924            'totalSteps': totalSteps, 
     925            'step': 0, 
     926            'power': power 
     927        }; 
     928        var move = function() { 
     929            var dx = OpenLayers.Util.easeInOut(this.slideX,  
     930                                                this.totalSteps,  
     931                                                this.step,  
     932                                                this.power); 
     933            var dy = OpenLayers.Util.easeInOut(this.slideY, 
     934                                                this.totalSteps,  
     935                                                this.step,  
     936                                                this.power); 
     937            this.map.pan(dx, dy, false); 
     938            this.step++; 
     939            if (this.step > this.totalSteps) { 
     940                window.clearInterval(this.map.animatedPanningIntervalID); 
     941                this.map.animatedPanningIntervalID = null; 
     942            } 
     943        }; 
     944 
     945        this.animatedPanningIntervalID =  
     946            window.setInterval(move.bindAsEventListener(context),  
     947                               interval); 
     948    }, 
     949 
     950    /** Position changer with Memory by www.hesido.com 
     951     *  modified by dncpax for OpenLayers 
     952     *  
     953     * @param {int} slideZoom 
     954     * @param {int} totalSteps 
     955     * @param {int} intervals 
     956     * @param {float} power  
     957     */ 
     958    zoomSlide: function( slideZoom, totalSteps, interval, power) { 
     959        if (this.animatedZoomingIntervalID) { 
     960            window.clearInterval(this.animatedZoomingIntervalID); 
     961            this.animatedZoomingIntervalID = null; 
     962        } 
     963        var context = { 
     964            'map': this, 
     965            'slideZoom': slideZoom, 
     966            'totalSteps': totalSteps, 
     967            'step': 0, 
     968            'power': power 
     969        }; 
     970        var move = function() { 
     971            var delta = this.slideZoom - this.map.zoom; 
     972            var dZoom = OpenLayers.Util.easeInOutZoom(delta,  
     973                                                this.totalSteps,  
     974                                                this.step,  
     975                                                this.power); 
     976 
     977            this.map.zoomTo(this.map.zoom + dZoom, false, this.step); 
     978            this.step++; 
     979            if (this.step > this.totalSteps) { 
     980                window.clearInterval(this.map.animatedZoomingIntervalID); 
     981                this.map.animatedZoomingIntervalID = null; 
     982            } 
     983        }; 
     984 
     985        this.animatedZoomingIntervalID =  
     986            window.setInterval(move.bindAsEventListener(context),  
     987                               interval); 
     988    }, 
     989 
    842990    /** 
    843991     * @private  
     
    10441192    /** Zoom to a specific zoom level 
    10451193     *  
     1194     * @param {float} zoom 
     1195     * @param {Boolean} animated  
     1196     * @param {int} step 
     1197     *  
     1198     */ 
     1199    zoomTo: function(zoom, animated, step) { 
     1200        if (this.isValidZoomLevel(zoom)) { 
     1201            if (animated == null) {  
     1202                animated = this.animated;  
     1203            }  
     1204 
     1205            if (animated) { 
     1206                this.zoomSlide(zoom,  
     1207                              this.slideSteps,  
     1208                              this.slideWait,  
     1209                              this.slidePower); 
     1210                 
     1211                // prepare zoom animation 
     1212                this.prepareZoomAnimation(); 
     1213            } else { 
     1214                 
     1215                if (step <= this.slideSteps ) { 
     1216 
     1217                    // set new zoomlevel from zoomSlide function 
     1218                    this.zoomlevel_scale = zoom; 
     1219 
     1220                    // run zoom animation -> scale tile(s)