OpenLayers OpenLayers

Changeset 7864

Show
Ignore:
Timestamp:
08/26/08 10:54:48 (3 months ago)
Author:
ahocevar
Message:

Added support for different projections for main map and overview map. Patch by bartvde. Modifications to the original patch:

  • caclulation of resolution factor no longer depends on proj4js,
  • created a member variable for the resolution factor and moved the calculation of the resolution factor to createMap(),
  • created acceptance test (tests/manual/overviewmap-projection.html).

r=me (closes #1620)

Files:

Legend:

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

    r7675 r7864  
    8989     */ 
    9090    maxRatio: 32, 
    91  
     91     
    9292    /** 
    9393     * APIProperty: mapOptions 
     
    103103     */ 
    104104    handlers: null, 
     105 
     106    /** 
     107     * Property: resolutionFactor 
     108     * {Object} 
     109     */ 
     110    resolutionFactor: 1, 
    105111 
    106112    /** 
     
    403409                                Math.min(mapExtent.right, maxExtent.right), 
    404410                                Math.min(mapExtent.top, maxExtent.top));         
     411 
     412        if (this.ovmap.getProjection() != this.map.getProjection()) { 
     413            testExtent = testExtent.transform( 
     414                this.map.getProjectionObject(), 
     415                this.ovmap.getProjectionObject() ); 
     416        } 
     417 
    405418        var resRatio = this.ovmap.getResolution() / this.map.getResolution(); 
    406419        return ((resRatio > this.minRatio) && 
     
    424437            targetRes = this.maxRatio * mapRes; 
    425438        } 
    426         this.ovmap.setCenter(this.map.center, 
    427                             this.ovmap.getZoomForResolution(targetRes)); 
     439        var center; 
     440        if (this.ovmap.getProjection() != this.map.getProjection()) { 
     441            center = this.map.center.clone(); 
     442            center.transform(this.map.getProjectionObject(), 
     443                this.ovmap.getProjectionObject() ); 
     444        } else { 
     445            center = this.map.center; 
     446        } 
     447        this.ovmap.setCenter(center, this.ovmap.getZoomForResolution( 
     448            targetRes * this.resolutionFactor)); 
    428449        this.updateRectToMap(); 
    429450    }, 
     
    487508        }); 
    488509 
     510        if (this.ovmap.getProjection() != this.map.getProjection()) { 
     511            var sourceUnits = this.map.getProjectionObject().getUnits() || 
     512                this.map.units || this.map.baseLayer.units; 
     513            var targetUnits = this.ovmap.getProjectionObject().getUnits() || 
     514                this.ovmap.units || this.ovmap.baseLayer.units; 
     515            this.resolutionFactor = sourceUnits && targetUnits ? 
     516                OpenLayers.INCHES_PER_UNIT[sourceUnits] / 
     517                OpenLayers.INCHES_PER_UNIT[targetUnits] : 1; 
     518        } 
    489519    }, 
    490520         
     
    494524     */ 
    495525    updateRectToMap: function() { 
    496         // The base layer for overview map needs to be in the same projection 
    497         // as the base layer for the main map.  This should be made more robust. 
    498         if(this.map.getUnits() != 'degrees') { 
    499             if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) { 
    500                 OpenLayers.Console.userError(OpenLayers.i18n("sameProjection")); 
    501             } 
    502         } 
    503         var pxBounds = this.getRectBoundsFromMapBounds(this.map.getExtent()); 
     526        // If the projections differ we need to reproject 
     527        var bounds; 
     528        if (this.ovmap.getProjection() != this.map.getProjection()) { 
     529            bounds = this.map.getExtent().transform( 
     530                this.map.getProjectionObject(),  
     531                this.ovmap.getProjectionObject() ); 
     532        } else { 
     533            bounds = this.map.getExtent(); 
     534        } 
     535        var pxBounds = this.getRectBoundsFromMapBounds(bounds); 
    504536        if (pxBounds) { 
    505537            this.setRectPxBounds(pxBounds); 
     
    513545    updateMapToRect: function() { 
    514546        var lonLatBounds = this.getMapBoundsFromRectBounds(this.rectPxBounds); 
     547        if (this.ovmap.getProjection() != this.map.getProjection()) { 
     548            lonLatBounds = lonLatBounds.transform( 
     549                this.ovmap.getProjectionObject(), 
     550                this.map.getProjectionObject() ); 
     551        } 
    515552        this.map.panTo(lonLatBounds.getCenterLonLat()); 
    516553    },