OpenLayers OpenLayers

Changeset 66

Show
Ignore:
Timestamp:
05/16/06 19:46:41 (3 years ago)
Author:
sderle
Message:

Fixed zoomend event code; changed semantics of the argument to moveToNewExtent to make the argument be the *previous* zoom level. Added tests.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Map.js

    r65 r66  
    242242        } 
    243243        this.center = latlon.copyOf(); 
    244         var zoomChanged = false
    245         if (zoom != null) { 
    246             if (this.zoom && zoom != this.zoom) 
    247                 zoomChanged = true
     244        var zoomChanged = null
     245        if (zoom != null && zoom != this.zoom  
     246            && zoom >= 0 && zoom <= this.getZoomLevels()) { 
     247            zoomChanged = (this.zoom == null ? 0 : this.zoom)
    248248            this.zoom = zoom; 
    249249        } 
     
    255255     
    256256    moveToNewExtent: function (zoomChanged) { 
    257         if (zoomChanged) { // reset the layerContainerDiv's location 
     257        if (zoomChanged != null) { // reset the layerContainerDiv's location 
    258258            this.layerContainerDiv.style.left = "0px"; 
    259259            this.layerContainerDiv.style.top  = "0px"; 
     
    261261        var bounds = this.getExtent(); 
    262262        for (var i = 0; i < this.layers.length; i++) { 
    263             this.layers[i].moveTo(bounds, zoomChanged); 
     263            this.layers[i].moveTo(bounds, (zoomChanged != null)); 
    264264        } 
    265265        this.events.triggerEvent("move"); 
    266         if (zoomChanged) 
    267             this.events.triggerEvent("zoomend"); 
     266        if (zoomChanged != null) 
     267            this.events.triggerEvent("zoomend",  
     268                {oldZoom: zoomChanged, newZoom: this.zoom}); 
    268269    }, 
    269270 
     
    287288            var oldZoom = this.zoom; 
    288289            this.zoom = zoom; 
    289             this.moveToNewExtent(true); 
    290             this.events.triggerEvent("zoomend", {oldZoom: oldZoom, newZoom: this.zoom}); 
     290            this.moveToNewExtent(oldZoom); 
    291291       } 
    292292    }, 
     
    304304    zoomExtent: function() { 
    305305        var fullExtent = this.getFullExtent(); 
    306          
     306        var oldZoom = this.zoom; 
    307307        this.zoom = this.getZoomForExtent( fullExtent ); 
    308308        this.setCenter( 
     
    312312          ) 
    313313        ); 
    314         this.moveToNewExtent(true); 
    315          
    316314    }, 
    317315 
     
    338336    defaultDblClick: function (evt) { 
    339337        var newCenter = this.getLatLonFromPixel( evt.xy );  
    340         this.zoomIn(); 
    341         this.setCenter(newCenter); 
     338        this.setCenter(newCenter, this.zoom + 1); 
    342339    }, 
    343340 
  • trunk/openlayers/tests/test_Map.html

    r64 r66  
    5555    } 
    5656    function test_05_Map_center(t) { 
    57         t.plan(5); 
     57        t.plan(4); 
    5858        map = new OpenLayers.Map($('map')); 
    5959        map.setCenter(new OpenLayers.LatLon(1,2), 0); 
    6060        map.zoomIn(); 
    61         t.ok( map.getCenter() instanceof OpenLayers.LatLon, "map.getCenter returns a LatLon"); 
    6261        t.eq( map.getZoom(), 1, "map.zoom is correct after calling setCenter,zoom in"); 
    6362        t.eq( map.getCenter().lat, 1, "map center lat is correct after calling setCenter,zoom in"); 
     
    6564        map.zoomOut(); 
    6665        t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out"); 
     66    } 
     67    function test_06_Map_zoomend_event (t) { 
     68        t.plan(3); 
     69        map = new OpenLayers.Map('map'); 
     70        map.events.register("zoomend", {count: 0}, function() {  
     71            this.count++;  
     72            t.ok(true, "zoomend event was triggered " + this.count + " times"); 
     73            }); 
     74        map.setCenter(new OpenLayers.LatLon(1,2), 0); 
     75        map.zoomIn(); 
     76        map.zoomOut(); 
    6777    } 
    6878    function test_99_Map_destroy (t) {