[OSM-dev] strange OpenLayers longitude and latitude
Christopher Schmidt
crschmidt at metacarta.com
Thu Aug 30 18:20:37 BST 2007
OSM tiles are projected. Displaying them in an unprojected map will not
work at all how you expect.
-- Chris
On Thu, Aug 30, 2007 at 09:06:58PM +0400, Vladimir Elistratov wrote:
> Hi!
>
> I added the option to see the longitude and latitude for the TMS Layer
> http://tile.openstreetmap.org
> It is well known line:
> map.addControl(new OpenLayers.Control.MousePosition());
>
> The longitude and latitude seem to be quite strange. Say, the
> longitude for London is around 90.
>
> What is the problem about! How is it possible to get "normal"
> longitude and latitude?
>
> I attach the small file for you to see how it happens.
>
> The related Javascript code:
> <script type="text/javascript">
> var lon = 90;
> var lat = 29;
> var zoom = 6;
> var map, layer;
>
> function init(){
> map = new OpenLayers.Map( 'map',
> {maxResolution:1.40625/2} );
>
> var mapnik = new OpenLayers.Layer.TMS("Mapnik",
> "http://tile.openstreetmap.org/",
> { type: 'png', getURL:
> getTileURL, displayOutsideMaxExtent: true });
>
> map.addLayer(mapnik);
>
> map.addControl(new OpenLayers.Control.LayerSwitcher());
> map.addControl(new OpenLayers.Control.MousePosition());
> map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
> }
>
> function getTileURL(bounds) {
> var res = this.map.getResolution();
> var x = Math.round((bounds.left - this.maxExtent.left) /
> (res * this.tileSize.w));
> var y = Math.round((this.maxExtent.top - bounds.top) / (res
> * this.tileSize.h));
> var z = this.map.getZoom();
> var limit = Math.pow(2, z);
>
> if (y < 0 || y >= limit)
> {
> return OpenLayers.Util.getImagesLocation() +
> "404.png";
> }
> else
> {
> x = ((x % limit) + limit) % limit;
> return this.url + z + "/" + x + "/" + y + "." +
> this.type;
> }
> }
>
> </script>
>
> Thank you for any advice!
>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
>
> <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
> <script type="text/javascript">
> var lon = 90;
> var lat = 29;
> var zoom = 6;
> var map, layer;
>
> function init(){
> map = new OpenLayers.Map( 'map', {maxResolution:1.40625/2} );
>
> var mapnik = new OpenLayers.Layer.TMS("Mapnik", "http://tile.openstreetmap.org/",
> { type: 'png', getURL: getTileURL, displayOutsideMaxExtent: true });
>
> map.addLayer(mapnik);
>
> map.addControl(new OpenLayers.Control.LayerSwitcher());
> map.addControl(new OpenLayers.Control.MousePosition());
> map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
> }
>
> function getTileURL(bounds) {
> var res = this.map.getResolution();
> var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
> var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
> var z = this.map.getZoom();
> var limit = Math.pow(2, z);
>
> if (y < 0 || y >= limit)
> {
> return OpenLayers.Util.getImagesLocation() + "404.png";
> }
> else
> {
> x = ((x % limit) + limit) % limit;
> return this.url + z + "/" + x + "/" + y + "." + this.type;
> }
> }
>
> </script>
> </head>
> <body onload="init()">
> <div id="map"></div>
> </body>
> </html>
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev
--
Christopher Schmidt
MetaCarta
More information about the dev
mailing list