what means "it doesn´t work as I expected"?
 
as your map is in EPSG:900913, you will not get any reasonable result by
transforming these coordinates from EPSG:4326 to EPSG:900913.

Arnd
 
 
  _____  

Von: [email protected]
[mailto:[email protected]] Im Auftrag von Robert
Buckley
Gesendet: Montag, 4. April 2011 18:52
An: [email protected]
Betreff: [OpenLayers-Users] how to return getcenter and getextent?


Hi,

I want to call the extent and center of my openlayers map and put the
results in a msgbox. Unfortunately i´m missing something because it doesn´t
work as I expected.

Could someone explain how to simply get the extents and center of the
current view? The map is in 900913

var map;

var extent = new OpenLayers.Bounds(10.0, 51.8, 10.8, 52.8).transform(
                  new OpenLayers.Projection(epsg4326), // transform from WGS
1984
                  new OpenLayers.Projection(epsg900913) // to Spherical
Mercator Projection
        );


var mapOptions = {
                    projection: epsg900913,
                    displayProjection: new OpenLayers.Projection(epsg4326),
                    units: "m",
                    minScale: 1000,
                    maxResolution: 156543, 
                    maxExtent: new OpenLayers.Bounds(1092438.008103,
6799532.287192, 1245312.064646, 6921831.532427),
                    controls: [    
                                new OpenLayers.Control.MouseDefaults(), 
                                new OpenLayers.Control.PanZoomBar(), 
                                new OpenLayers.Control.ScaleLine({
                        maxWidth: 200,
                        geodesic: true
                    })]
                };
        
map = new OpenLayers.Map("map_wea",mapOptions);

// my base map
var mapnik = new OpenLayers.Layer.OSM();


//  messagebox to display info about map

var latlon = map.getCenter();
                var currentlatlon = new OpenLayers.LonLat(latlon).transform(
                  new OpenLayers.Projection(epsg4326), // transform from WGS
1984
                  new OpenLayers.Projection(epsg900913) // to Spherical
Mercator Projection
                );
                
                var mapextent = map.getExtent();
                var currentmapextent= new
OpenLayers.Bounds(mapextent).transform(
                  new OpenLayers.Projection(epsg4326), // transform from WGS
1984
                  new OpenLayers.Projection(epsg900913) // to Spherical
Mercator Projection
                );
                    
                Ext.Msg.alert('bounds', currentmapextent + " / " +
currentlatlon);

_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to