[OpenLayers-Users] how to return getcenter and getextent?

Robert Buckley robertdbuckley at yahoo.com
Mon Apr 4 12:52:27 EDT 2011


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);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110404/13c80d71/attachment.html


More information about the Users mailing list