[GIS] OpenLayers 2.13 : How to display a local tiled raster

openlayers-2rastertiles

I am trying to display (on OpenLayers 2.13) a local tiled raster I made with gdal2tiles.py. Unfortunately it's all blank or pink. Here is my layer definition:

var tiles = new OpenLayers.Layer.XYZ("Local tiles", "tiles/${z}/${x}/${y}.png", {
    isBaseLayer: true,
    displayProjection: new OpenLayers.Projection("EPSG:4326"),
    maxExtent: [-75.1729846, 39.9439032, -75.1529085, 39.9599679]
});

map.addLayer(tiles);

What is wrong?

Here is a link to my OpenLayers test page : http://popopopopo.voila.net/index.html

And here is the original image: http://popopopopo.voila.net/raster.tif (EPSG: 3857)

Best Answer

Gdal2tiles numbers the tiles from South to North (according to the OGC TMS sepcification), while OSM numbers from North to South (like Google and bing does it).

I described here what I changed to make it numbering in correct (OSM) order:

GDAL2Tiles: MapTiles from BSB/KAP are Switched

If I load the OSM tile with the example numbers you gave above, I get one from the Pacific off the coast of Chile, at -75° East -39.95° North. I guess that is not what you intended with your extent, which should direct to Philadelphia.

The mapquest tiles you show in your map are in the range of

http://otile4.mqcdn.com/tiles/1.0.0/map/14/4770/6205.jpg

So you have to make sure your self rendered tiles have the same number if they should appear in the same place.

Leaflet has an option to set tms=true for tiles generated according to the TMS specification. Openlayers seems to lack this opportunity yet.

See also:

http://trac.osgeo.org/openlayers/wiki/UsingCustomTiles

http://www-user.tu-chemnitz.de/~poenisch/vortraege/osm/slide-4-5.html


EDIT

It is possible to use the TMS numbered tiles by extending the Openlayers TMS call, see my answer here:

Add TMS layer to OpenLayers