OpenLayers OpenLayers

Ticket #1620: ticket1620.patch

File ticket1620.patch, 3.9 kB (added by bartvde, 4 months ago)
  • 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(new OpenLayers.Projection( 
     408                this.map.getProjection()), 
     409                new OpenLayers.Projection(this.ovmap.getProjection()) ); 
     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 sourceProjection = new OpenLayers.Projection( 
     437                this.map.getProjection()); 
     438            var targetProjection = new OpenLayers.Projection( 
     439                this.ovmap.getProjection()); 
     440            var sourceUnits = sourceProjection.proj.units; 
     441            if (sourceUnits == null) { 
     442                sourceUnits = 'degrees'; 
     443            } 
     444            var targetUnits = targetProjection.proj.units; 
     445            if (targetUnits == null) { 
     446                targetUnits = 'degrees'; 
     447            } 
     448            factor = OpenLayers.INCHES_PER_UNIT[targetUnits] / 
     449                OpenLayers.INCHES_PER_UNIT[sourceUnits]; 
     450            center = this.map.center.clone(); 
     451            center.transform(new OpenLayers.Projection( 
     452                this.map.getProjection()), 
     453                new OpenLayers.Projection(this.ovmap.getProjection()) ); 
     454        } else { 
     455            center = this.map.center; 
     456        } 
     457        this.ovmap.setCenter(center, 
     458                            this.ovmap.getZoomForResolution(targetRes/factor)); 
    428459        this.updateRectToMap(); 
    429460    }, 
    430461     
     
    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(new OpenLayers.Projection( 
     531                this.map.getProjection()),  
     532                new OpenLayers.Projection(this.ovmap.getProjection()) ); 
     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                new OpenLayers.Projection(this.ovmap.getProjection()), 
     551                new OpenLayers.Projection(this.map.getProjection()) ); 
     552        } 
    515553        this.map.panTo(lonLatBounds.getCenterLonLat()); 
    516554    }, 
    517555