OpenLayers OpenLayers

Changeset 5519

Show
Ignore:
Timestamp:
12/19/07 18:36:34 (1 year ago)
Author:
crschmidt
Message:

add displayProjection API Property on the Map, and on relevant controls.
Spherical mercator example now makes use of this, displaying coordinates
in lon/lat instead of meters, and permalink/argparser now work in lon/lat
as well. this functionality will make using SphericalMercator easier for
a number of applications.
r=tschaub (Closes #1036)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/spherical-mercator.html

    r5362 r5519  
    2626        function init(){ 
    2727            var options = { 
    28                 projection: "EPSG:900913", 
     28                projection: new OpenLayers.Projection("EPSG:900913"), 
     29                displayProjection: new OpenLayers.Projection("EPSG:4326"), 
    2930                units: "m", 
    3031                maxResolution: 156543.0339, 
     
    105106            map.addControl(new OpenLayers.Control.LayerSwitcher()); 
    106107            map.addControl(new OpenLayers.Control.EditingToolbar(vector)); 
     108            map.addControl(new OpenLayers.Control.Permalink()); 
     109            map.addControl(new OpenLayers.Control.MousePosition()); 
    107110            map.zoomToMaxExtent() 
    108111        } 
  • trunk/openlayers/lib/OpenLayers/Control/ArgParser.js

    r4985 r5519  
    3131     */ 
    3232    layers: null, 
     33     
     34    /**  
     35     * APIProperty: displayProjection 
     36     * {<OpenLayers.Projection>} Requires proj4js support.  
     37     *     Projection used when reading the coordinates from the URL. This will 
     38     *     reproject the map coordinates from the URL into the map's 
     39     *     projection. 
     40     * 
     41     *     If you are using this functionality, be aware that any permalink 
     42     *     which is added to the map will determine the coordinate type which 
     43     *     is read from the URL, which means you should not add permalinks with 
     44     *     different displayProjections to the same map.  
     45     */ 
     46    displayProjection: null,  
    3347 
    3448    /** 
     
    5771            if ( (control != this) && 
    5872                 (control.CLASS_NAME == "OpenLayers.Control.ArgParser") ) { 
     73                 
     74                // If a second argparser is added to the map, then we  
     75                // override the displayProjection to be the one added to the 
     76                // map.  
     77                if (control.displayProjection != this.displayProjection) { 
     78                    this.displayProjection = control.displayProjection; 
     79                }     
     80                 
    5981                break; 
    6082            } 
     
    98120            this.map.events.unregister('changebaselayer', this,  
    99121                                       this.setCenter); 
    100                                         
     122             
     123            if (this.displayProjection) { 
     124                this.center.transform(this.displayProjection,  
     125                                      this.map.getProjectionObject());  
     126            }       
     127 
    101128            this.map.setCenter(this.center, this.zoom); 
    102129        } 
  • trunk/openlayers/lib/OpenLayers/Control/MousePosition.js

    r5490 r5519  
    5252     */ 
    5353    lastXy: null, 
     54 
     55    /** 
     56     * APIProperty: displayProjection 
     57     * {<OpenLayers.Projection>} A projection that the  
     58     * mousecontrol will display. 
     59     */ 
     60    displayProjection: null,  
    5461     
    5562    /** 
     
    114121                return; 
    115122            }     
     123            if (this.displayProjection) { 
     124                lonLat.transform(this.map.getProjectionObject(),  
     125                                 this.displayProjection ); 
     126            }       
    116127            this.lastXy = evt.xy; 
     128             
    117129        } 
    118130         
  • trunk/openlayers/lib/OpenLayers/Control/Permalink.js

    r5406 r5519  
    2525     */ 
    2626    base: '', 
     27 
     28    /**  
     29     * APIProperty: displayProjection 
     30     * {<OpenLayers.Projection>} Requires proj4js support.  Projection used 
     31     *     when creating the coordinates in the link. This will reproject the 
     32     *     map coordinates into display coordinates. If you are using this 
     33     *     functionality, the permalink which is last added to the map will 
     34     *     determine the coordinate type which is read from the URL, which 
     35     *     means you should not add permalinks with different 
     36     *     displayProjections to the same map.  
     37     */ 
     38    displayProjection: null,  
    2739 
    2840    /** 
     
    6880            var control = this.map.controls[i]; 
    6981            if (control.CLASS_NAME == "OpenLayers.Control.ArgParser") { 
     82                 
     83                // If a permalink is added to the map, and an ArgParser already 
     84                // exists, we override the displayProjection to be the one 
     85                // on the permalink.  
     86                if (control.displayProjection != this.displayProjection) { 
     87                    this.displayProjection = control.displayProjection; 
     88                }     
     89                 
    7090                break; 
    7191            } 
    7292        } 
    7393        if (i == this.map.controls.length) { 
    74             this.map.addControl(new OpenLayers.Control.ArgParser());        
     94            this.map.addControl(new OpenLayers.Control.ArgParser( 
     95                { 'displayProjection': this.displayProjection }));        
    7596        } 
    7697 
     
    113134         
    114135        params.zoom = this.map.getZoom();  
    115         params.lat = Math.round(center.lat*100000)/100000; 
    116         params.lon = Math.round(center.lon*100000)/100000; 
    117  
     136        var lat = center.lat; 
     137        var lon = center.lon; 
     138         
     139        if (this.displayProjection) { 
     140            var mapPosition = OpenLayers.Projection.transform( 
     141              { x: lon, y: lat },  
     142              this.map.getProjectionObject(),  
     143              this.displayProjection ); 
     144            lon = mapPosition.x;   
     145            lat = mapPosition.y;   
     146        }        
     147        params.lat = Math.round(lat*100000)/100000; 
     148        params.lon = Math.round(lon*100000)/100000; 
     149         
    118150        params.layers = ''; 
    119151        for(var i=0; i< this.map.layers.length; i++) { 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r5505 r5519  
    239239     */ 
    240240    theme: null, 
     241     
     242    /**  
     243     * APIProperty: displayProjection 
     244     * {<OpenLayers.Projection>} Requires proj4js support.Projection used by 
     245     *     several controls to display data to user. If this property is set, 
     246     *     it will be set on any control which has a null displayProjection 
     247     *     property at the time the control is added to the map.  
     248     */ 
     249    displayProjection: null, 
    241250 
    242251    /** 
     
    916925        // viewport. 
    917926        control.outsideViewport = (control.div != null); 
     927         
     928        // If the map has a displayProjection, and the control doesn't, set  
     929        // the display projection. 
     930        if (this.displayProjection && !control.displayProjection) { 
     931            control.displayProjection = this.displayProjection; 
     932        }     
     933         
    918934        control.setMap(this); 
    919935        var div = control.draw(px); 
  • trunk/openlayers/tests/Control/test_MousePosition.html

    r5461 r5519  
    33  <script src="../../lib/OpenLayers.js"></script> 
    44  <script type="text/javascript"> 
    5  
    6     function test_MousePosition_constructor(t) { 
     5    var map, control;  
     6    function test_01_Control_MousePosition_constructor (t) { 
     7        t.plan( 2 ); 
     8     
     9        control = new OpenLayers.Control.MousePosition(); 
     10        t.ok( control instanceof OpenLayers.Control.MousePosition, "new OpenLayers.Control returns object" ); 
     11        t.eq( control.displayClass,  "olControlMousePosition", "displayClass is correct" ); 
     12    } 
     13    function test_02_Control_MousePosition_redraw_noLayer_displayProjection(t) { 
    714        t.plan(2); 
    8      
    9         var control = new OpenLayers.Control.MousePosition(); 
    10         t.ok(control instanceof OpenLayers.Control.MousePosition, "new OpenLayers.Control.MousePosition returns object"); 
    11         t.eq(control.displayClass, "olControlMousePosition", "displayClass set correctly"); 
     15        control = new OpenLayers.Control.MousePosition({'displayProjection': new OpenLayers.Projection("WGS84")}); 
     16        map = new OpenLayers.Map('map'); 
     17        map.addControl(control); 
     18        control.redraw({'xy': new OpenLayers.Pixel(10,10)}); 
     19        control.redraw({'xy': new OpenLayers.Pixel(12,12)}); 
     20        t.eq(control.div.innerHTML, "", "innerHTML set correctly"); 
     21        l = new OpenLayers.Layer('name', {'isBaseLayer': true}); 
     22        map.addLayer(l); 
     23        map.zoomToMaxExtent(); 
     24        control.redraw({'xy': new OpenLayers.Pixel(10,10)}); 
     25        control.redraw({'xy': new OpenLayers.Pixel(12,12)}); 
     26        t.eq(control.div.innerHTML, "-175.78125, 85.78125", "innerHTML set correctly when triggered."); 
    1227    } 
    13  
    1428    function test_MousePosition_destroy(t) { 
    1529        t.plan(1); 
     
    5771        map.destroy();      
    5872    } 
    59  
    6073  </script> 
    6174</head>