1

I have a high resolution image, which I've broken down into tiles and named the tiles according to x,y co-ordinates and zoom levels. The image is not projected in any geospatial/gis (WGS84 ellipsoid, spherical mercator) ellipsoid.

If it is possible to use OpenLayers (version 2.x) to display the image in the browser, then how should I go about doing that?

Note that I also want to be able to overlay the image with other data, and OL allows me to do this easily on a map but not entirely sure if I can do this with an image.

  • for Openlayers 3, I could recommend the zoomify Projection: openlayers.org/en/master/examples/zoomify.html – fidelfisch Sep 15 '15 at 15:33
  • The entire application, which is fairly large, is built in OL 2. Unless porting to OL 3 is incredibly simple, it is hard for me to justify using it just for this purpose. However, there must be a way to do this in OL 2, I think. – MRashid Sep 15 '15 at 21:49
  • I am afraid it is not that simple to switch to OL3. But maybe there's a solution for you when you use the GDAL command "gdal2tiles" (gdal.org/gdal2tiles.html). It should create tiles of your original image and will provide you also with an OpenLayers html file. – fidelfisch Sep 16 '15 at 10:13
  • That looks very interesting. I will try that today and update you about my results. Thanks for the pointer. – MRashid Sep 16 '15 at 19:14
2

Yes, you can show tile image in browser by following code:

var Layer = new OpenLayers.Layer.TMS("map", "", {'type':'png', 'getURL':get_my_url,isBaseLayer:true});

and get_my_url function is:

function get_my_url(bounds) {

var res = this.map.getResolution();
if (url instanceof Array) {
    url = this.selectUrl(path, url);
}
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 path = z + "_" + x + "_" + y + "." + this.type;
var url = this.url;

return url + path;

}

I hope it can help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.