[OpenLayers-Users] How to make OpenLayers.Map.panTo() work?

Arnd Wippermann arnd.wippermann at web.de
Sun Feb 7 07:39:30 EST 2010


Hi,
 
your result is absolute right. For sphericalMercator (180,90) are ~(0,0). 
 
You can calculate your lonlat from sphericalMercator bounds
new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508)
 
or transform your coordinates to sphericalMercator 
var lonlat = new OpenLayers.LonLat(lon, lat).transform(new
OpenLayers.Projection("EPSG:4326"),new
OpenLayers.Projection("EPSG:900913"));

Arnd

  _____  

Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von Vincent Gulinao
Gesendet: Sonntag, 7. Februar 2010 05:38
An: users at openlayers.org
Betreff: Re: [OpenLayers-Users] How to make OpenLayers.Map.panTo() work?


Sorry, accidentally sent...

I copied this from an example somewhere to start:

    map = new OpenLayers.Map('map',
        {
            numZoomLevels: 19,
              maxResolution: 156543.0399,
              units: 'm',
              projection: new OpenLayers.Projection("EPSG:900913"),
              displayProjection: new OpenLayers.Projection("EPSG:4326")
        });


    var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
    map.addLayers([layerMapnik]);

Then I call this function from html drop-down list's onchange:

function setCenter(region) {
    lon = Math.random() * 360 - 180;
    lat = Math.random() * 180 - 90;
    var lonlat = new OpenLayers.LonLat(lon, lat);
    map.panTo(lonlat);
}

... but it only brings me to (I believe) 0,0.

I've been trying to figure it out for hours but with no luck. Please help.

TIA.


On Sun, Feb 7, 2010 at 12:30 PM, Vincent Gulinao <vincent.gulinao at gmail.com>
wrote:


I'm a newbie, I copied this from an example somewhere to start:

map = new OpenLayers.Map('map',
        {
            numZoomLevels: 19,
              maxResolution: 156543.0399,
              units: 'm',
              projection: new OpenLayers.Projection("EPSG:900913"),
              displayProjection: new OpenLayers.Projection("EPSG:4326")
        });


    var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
map.addLayers([layerMapnik,layerTah]);



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100207/0da8cf39/attachment.html


More information about the Users mailing list