OpenLayers OpenLayers

Ticket #1620: ticket1620.2.patch

File ticket1620.2.patch, 3.5 kB (added by bartvde, 4 months ago)

updated patch using getProjectionObject()

  • OverviewMap.js

    old new  
    402402                                Math.max(mapExtent.bottom, maxExtent.bottom), 
    403403                                Math.min(mapExtent.right, maxExtent.right), 
    404404                                Math.min(mapExtent.top, maxExtent.top));         
     405 
     406        if (this.ovmap.getProjection() != this.map.getProjection()) { 
     407            testExtent = testExtent.transform( 
     408                this.map.getProjectionObject(), 
     409                this.ovmap.getProjectionObject() ); 
     410        } 
     411 
    405412        var resRatio = this.ovmap.getResolution() / this.map.getResolution(); 
    406413        return ((resRatio > this.minRatio) && 
    407414                (resRatio <= this.maxRatio) && 
     
    423430            // zoom out overview map 
    424431            targetRes = this.maxRatio * mapRes; 
    425432        } 
    426         this.ovmap.setCenter(this.map.center, 
    427                             this.ovmap.getZoomForResolution(targetRes)); 
     433        var center; 
     434        var factor = 1; 
     435        if (this.ovmap.getProjection() != this.map.getProjection()) { 
     436            var sourceUnits = this.map.getProjectionObject().getUnits(); 
     437            if (sourceUnits == null) { 
     438                sourceUnits = 'degrees'; 
     439            } 
     440            var targetUnits = this.ovmap.getProjectionObject().getUnits(); 
     441            if (targetUnits == null) { 
     442                targetUnits = 'degrees'; 
     443            } 
     444            factor = OpenLayers.INCHES_PER_UNIT[targetUnits] / 
     445                OpenLayers.INCHES_PER_UNIT[sourceUnits]; 
     446            center = this.map.center.clone(); 
     447            center.transform(this.map.getProjectionObject(), 
     448                this.ovmap.getProjectionObject() ); 
     449        } else { 
     450            center = this.map.center; 
     451        } 
     452        this.ovmap.setCenter(center, 
     453            this.ovmap.getZoomForResolution(targetRes/factor)); 
    428454        this.updateRectToMap(); 
    429455    }, 
    430456     
     
    493524     * Updates the extent rectangle position and size to match the map extent 
    494525     */ 
    495526    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.units != 'degrees') { 
    499             if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) { 
    500                 alert(OpenLayers.i18n("sameProjection")); 
    501             } 
     527        // If the projections differ we need to reproject 
     528        var bounds; 
     529        if (this.ovmap.getProjection() != this.map.getProjection()) { 
     530            bounds = this.map.getExtent().transform( 
     531                this.map.getProjectionObject(),  
     532                this.ovmap.getProjectionObject() ); 
     533        } else { 
     534            bounds = this.map.getExtent(); 
    502535        } 
    503         var pxBounds = this.getRectBoundsFromMapBounds(this.map.getExtent()); 
     536        var pxBounds = this.getRectBoundsFromMapBounds(bounds); 
    504537        if (pxBounds) { 
    505538            this.setRectPxBounds(pxBounds); 
    506539        } 
     
    512545     */ 
    513546    updateMapToRect: function() { 
    514547        var lonLatBounds = this.getMapBoundsFromRectBounds(this.rectPxBounds); 
     548        if (this.ovmap.getProjection() != this.map.getProjection()) { 
     549            lonLatBounds = lonLatBounds.transform( 
     550                this.ovmap.getProjectionObject(), 
     551                this.map.getProjectionObject() ); 
     552        } 
    515553        this.map.panTo(lonLatBounds.getCenterLonLat()); 
    516554    }, 
    517555