javascriptdeepzoomopenseadragon

OpenSeadragon Dynamic Image


I would like to create a tilesource for OpenSeadragon, to render a player's view for a game. The world has coordinates (x,y), player is on a particular coord, with a view range.

What I would like is to create a tilesource for OpenSeadragon, that can display the whole view. At maximum zoom, 1 tile = 1 coord. So I have a few questions : How can I compute the maximum zoomlevel for player's view range ? How can I know the world positions I have to render in the tile that is requested by OpenSeadragon (x, y, level) ?

Thanks :)


Solution

  • If I understand correctly, you're trying to create a custom TileSource where you can load from a set of standard tiles that make up the building blocks of your game map. If you want, you can specify that the max level is the only level it tries to load (by making minLevel and maxLevel the same), so you don't have to deal with generating tile combinations. That makes getTileUrl(level, x, y) easy, since you only have to deal with the 1:1 layer. This leaves the question of what is that max level. As defined in:

    http://openseadragon.github.io/docs/OpenSeadragon.TileSource.html

    ...the formula is:

    By default the image pyramid is split into N layers where the images longest side in M (in pixels), where N is the smallest integer which satisfies 2^(N+1) >= M.

    Basically you're just counting powers of 2 until you get to the size of your image. So, if your image is 1 pixel on a side, your max level is 0. If it's 2 pixels on a side, your max level is 1, 4 = 2, 8 = 3, etc.

    Let's say your tileSize is 100 pixels and the map is 5x7 tiles. This means the longest dimension is 700 pixels. Looking at powers of 2, 700 is bigger than 512 and smaller than 1024, so we use 1024. 1024 is the 10th power of 2, so your max level is 10.

    Does that answer your questions?