OpenLayers OpenLayers

Changeset 6961

Show
Ignore:
Timestamp:
04/17/08 19:41:40 (9 months ago)
Author:
edgemaster
Message:

* Add example of using multiple projections on one map
* Also attempt to adjust resolution properties of the Vector layer so that it will display as intended

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/edgemaster/openlayers/lib/OpenLayers/Layer/Vector.js

    r6888 r6961  
    494494    }, 
    495495     
    496     /* APIMethod: transform 
    497      * Transform the Vector layer from source to dest projection.  
     496    /** 
     497     * APIMethod: transform 
     498     * Transform the Vector layer from source to dest projection. 
     499     * * Please note that you may have to manually change other 
     500     * options such as resolutions to get the layer to display as 
     501     * you intend on a base layer (see adjustResolutions()) 
    498502     * 
    499503     * Parameters:  
     
    502506     * 
    503507     * Returns: 
    504      * {<OpenLayers.Layer.Markers>} Itself, for use in chaining operations. 
     508     * {<OpenLayers.Layer.Vector>} Itself, for use in chaining operations. 
    505509     */ 
    506510    transform: function(source, dest) { 
     
    509513            feature.geometry.transform(source, dest); 
    510514        } 
     515        if(this.maxExtent != null) { 
     516            this.maxExtent.transform(source, dest); 
     517        } 
     518        this.projection = dest; 
    511519        this.redraw(); 
    512520        return this; 
     521    }, 
     522     
     523    /** 
     524     * Method: adjustResolutions 
     525     * Attempts to adjust resolution options to that of a new base layer if 
     526     * originally copied from a base layer or the map object. 
     527     * 
     528     * Parameters: 
     529     * layer - {<OpenLayers.Layer>} Layer to copy new resolution options from 
     530     */ 
     531    adjustResolutions: function(layer) { 
     532        // These are the relevant options which are used for comparing 
     533        //  resolutions information. 
     534        // (copied from OpenLayers.Layer.initResolutions()) 
     535        var props = new Array( 
     536            'projection', 'units', 
     537            'scales', 'resolutions', 
     538            'maxScale', 'minScale',  
     539            'maxResolution', 'minResolution', 
     540            'minExtent', 'maxExtent', 
     541            'numZoomLevels', 'maxZoomLevel' 
     542        ); 
     543         
     544        // This is probably ugly - we clobber derived properties 
     545        for(var i=0; i < props.length; i++) { 
     546            if((this.options[props[i]] === undefined) && (this[props[i]])) { 
     547                this[props[i]] = layer[props[i]]; 
     548            } 
     549        } 
    513550    }, 
    514551     
  • sandbox/edgemaster/openlayers/lib/OpenLayers/Map.js

    r6888 r6961  
    971971    setBaseLayer: function(newBaseLayer) { 
    972972        var oldExtent = null; 
     973        var oldProjection = null; 
    973974        if (this.baseLayer) { 
    974975            oldExtent = this.baseLayer.getExtent(); 
     
    10071008                    // Convert centre point to new layer projection - so we can 
    10081009                    // maintain roughly the same view 
    1009                     if(!oldProjection.equals(this.getProjectionObject())) { 
    1010                         newCenter.transform(oldProjection, this.getProjectionObject()); 
    1011                         oldExtent.transform(oldProjection, this.getProjectionObject()); 
     1010                    var newProjection = this.getProjectionObject(); 
     1011                    if(!oldProjection.equals(newProjection)) { 
     1012                        newCenter.transform(oldProjection, newProjection); 
     1013                        oldExtent.transform(oldProjection, newProjection); 
     1014                         
     1015                        // Also convert vector layers - assuming they are in the 
     1016                        // same projection as the original baseLayer - we cannot 
     1017                        // trust the projection property all the time as it is 
     1018                        // used as a shortcut for externalProjection 
    10121019                        vectorLayers = this.getLayersBy("isVector", true); 
    10131020                        for (l = 0; l < vectorLayers.length; l++) { 
    1014                             vectorLayers[l].transform(oldProjection, this.getProjectionObject()); 
     1021                            vectorLayers[l].transform(oldProjection, newProjection); 
     1022                            vectorLayers[l].adjustResolutions(this.baseLayer); 
    10151023                        } 
    10161024                    } 
    10171025 
    10181026                    //the new zoom will either come from the old Extent or  
    1019                     // from the current resolution of the map                                                 
     1027                    // from the current resolution of the map 
    10201028                    var newZoom = (oldExtent)  
    10211029                        ? this.getZoomForExtent(oldExtent, true)