Base class for layers that use a lattice of tiles. Create a new grid layer with the ALKMaps.Layer.Grid constructor.
ALKMaps. | Base class for layers that use a lattice of tiles. |
Properties | |
tileSize | {ALKMaps.Size} |
tileOriginCorner | {String} If the tileOrigin property is not provided, the tile origin will be derived from the layer’s maxExtent. |
tileOrigin | {ALKMaps.LonLat} Optional origin for aligning the grid of tiles. |
tileOptions | {Object} optional configuration options for ALKMaps.Tile instances created by this Layer, if supported by the tile class. |
tileClass | {ALKMaps.Tile} The tile class to use for this layer. |
grid | {Array(Array(ALKMaps.Tile))} This is an array of rows, each row is an array of tiles. |
singleTile | {Boolean} Moves the layer into single-tile mode, meaning that one tile will be loaded. |
ratio | {Float} Used only when in single-tile mode, this specifies the ratio of the size of the single tile to the size of the map. |
buffer | {Integer} Used only when in gridded mode, this specifies the number of extra rows and columns of tiles on each side which will surround the minimum grid tiles to cover the map. |
transitionEffect | {String} The transition effect to use when the map is zoomed. |
numLoadingTiles | {Integer} How many tiles are still loading? |
tileLoadingDelay | {Integer} Number of milliseconds before we shift and load tiles when panning. |
serverResolutions | {Array(Number}} This property is documented in subclasses as an API property. |
moveTimerId | {Number} The id of the deferMoveGriddedTiles timer. |
deferMoveGriddedTiles | {Function} A function that defers execution of moveGriddedTiles by tileLoadingDelay. |
tileQueueId | {Number} The id of the drawTileFromQueue animation. |
tileQueue | {Array(ALKMaps.Tile)} Tiles queued for drawing. |
loading | {Boolean} Indicates if tiles are being loaded. |
backBuffer | {DOMElement} The back buffer. |
gridResolution | {Number} The resolution of the current grid. |
backBufferResolution | {Number} The resolution of the current back buffer. |
backBufferLonLat | {Object} The top-left corner of the current back buffer. |
backBufferTimerId | {Number} The id of the back buffer timer. |
removeBackBufferDelay | {Number} Delay for removing the backbuffer when all tiles have finished loading. |
className | {String} Name of the class added to the layer div. |
Constructor | |
ALKMaps. | Create a new grid layer |
Functions | |
setMap | |
removeMap | Called when the layer is removed from the map. |
destroy | Deconstruct the layer and clear the grid. |
clearGrid | Go through and remove all tiles from the grid, calling destroy() on each of them to kill circular references |
clone | Create a clone of this layer |
moveTo | This function is called whenever the map is moved. |
getTileData | Given a map location, retrieve a tile and the pixel offset within that tile corresponding to the location. |
queueTileDraw | Adds a tile to the animation queue that will draw it. |
drawTileFromQueue | Draws the first tile from the tileQueue, and unqueues that tile |
clearTileQueue | Clears the animation queue |
destroyTile | |
getServerResolution | Return the closest highest server-supported resolution. |
getServerZoom | Return the zoom value corresponding to the best matching server resolution, taking into account serverResolutions and <zoomOffset>. |
transformDiv | Transform the layer div. |
getResolutionScale | Return the value by which the layer is currently scaled. |
applyBackBuffer | Create, insert, scale and position a back buffer for the layer. |
createBackBuffer | Create a back buffer. |
removeBackBuffer | Remove back buffer from DOM. |
moveByPx | Move the layer based on pixel vector. |
setTileSize | Check if we are in singleTile mode and if so, set the size as a ratio of the map size (as specified by the layer’s ‘ratio’ property). |
getTilesBounds | Return the bounds of the tile grid. |
initSingleTile | |
calculateGridLayout | Generate parameters for the grid layout. |
getTileOrigin | Determine the origin for aligning the grid of tiles. |
initGriddedTiles | |
getMaxExtent | Get this layer’s maximum extent. |
addTile | Create a tile, initialize it, and add it to the layer div. |
addTileMonitoringHooks | This function takes a tile as input and adds the appropriate hooks to the tile so that the layer can keep track of the loading tiles. |
removeTileMonitoringHooks | This function takes a tile as input and removes the tile hooks that were added in addTileMonitoringHooks() |
moveGriddedTiles | |
shiftRow | Shifty grid work |
shiftColumn | Shift grid work in the other dimension |
removeExcessTiles | When the size of the map or the buffer changes, we may need to remove some excess rows and columns. |
onMapResize | For singleTile layers, this will set a new tile size according to the dimensions of the map pane. |
getTileBounds | Returns The tile bounds for a layer given a pixel location. |
{String} If the tileOrigin property is not provided, the tile origin will be derived from the layer’s maxExtent. The corner of the maxExtent used is determined by this property. Acceptable values are “tl” (top left), “tr” (top right), “bl” (bottom left), and “br” (bottom right). Default is “bl”.
{ALKMaps.LonLat} Optional origin for aligning the grid of tiles. If provided, requests for tiles at all resolutions will be aligned with this location (no tiles shall overlap this location). If not provided, the grid of tiles will be aligned with the layer’s maxExtent. Default is ``null``.
{Object} optional configuration options for ALKMaps.Tile instances created by this Layer, if supported by the tile class.
{ALKMaps.Tile} The tile class to use for this layer. Defaults is ALKMaps.Tile.Image.
{Array(Array(ALKMaps.Tile))} This is an array of rows, each row is an array of tiles.
{Integer} Used only when in gridded mode, this specifies the number of extra rows and columns of tiles on each side which will surround the minimum grid tiles to cover the map. For very slow loading layers, a larger value may increase performance somewhat when dragging, but will increase bandwidth use significantly.
{String} The transition effect to use when the map is zoomed. Two possible values:
null | No transition effect (the default). |
”resize” | Existing tiles are resized on zoom to provide a visual effect of the zoom having taken place immediately. As the new tiles become available, they are drawn over top of the resized tiles. |
Using “resize” on non-opaque layers can cause undesired visual effects. This is therefore discouraged.
{Number} The id of the deferMoveGriddedTiles timer.
{Function} A function that defers execution of moveGriddedTiles by tileLoadingDelay. If <ALKMaps.Animation.isNative> is true, this is null and unused.
{Number} The id of the drawTileFromQueue animation.
{Array(ALKMaps.Tile)} Tiles queued for drawing.
{Number} Delay for removing the backbuffer when all tiles have finished loading. Can be set to 0 when no css opacity transitions for the olTileImage class are used. Default is 0 for singleTile layers, 2500 for tiled layers. See className for more information on tile animation.
{String} Name of the class added to the layer div. If not set in the options passed to the constructor then className defaults to “olLayerGridSingleTile” for single tile layers (see singleTile), and “olLayerGrid” for non single tile layers.
The displaying of tiles is not animated by default for single tile layers - ALKMaps’ default theme (style.css) includes this:
.olLayerGrid .olTileImage { -webkit-transition: opacity 0.2s linear; -moz-transition: opacity 0.2s linear; -o-transition: opacity 0.2s linear; transition: opacity 0.2s linear; }
To animate tile displaying for any grid layer the following CSS rule can be used:
.olTileImage { -webkit-transition: opacity 0.2s linear; -moz-transition: opacity 0.2s linear; -o-transition: opacity 0.2s linear; transition: opacity 0.2s linear; }
In that case, to avoid flash effects, removeBackBufferDelay should not be zero.
Create a new grid layer
name | {String} |
url | {String} |
params | {Object} |
options | {Object} Hashtable of extra options to tag onto the layer |
layer.events.register(type, obj, listener); // Sample code for handling NULL tiles. layer.events.register("tileloaded", layer, function(e){ var w = 0, h = 0, img = e.tile.imgDiv; if(typeof img.naturalWidth === "undefined"){ // IE 6/7/8 var tempImg = new Image(); tempImg.src = img.src; w = tempImg.width; h = tempImg.height; } else{ // HTML5 browsers w = img.naturalWidth; h = img.naturalHeight; } if (w <=0 || h <=0) { // Set blank image and hide it. e.tile.setImgSrc(ALKMaps.Util.getImageLocation("blank.gif")); // e.tile.imgDiv.src = e.tile.blankImageUrl; } });
Listeners will be called with a reference to an event object. The properties of this event depends on exactly what happened.
object | {Object} A reference to layer.events.object. |
element | {DOMElement} A reference to layer.events.element. |
tileloadstart | Triggered when a tile starts loading. Listeners receive an object as first argument, which has a tile property that references the tile that starts loading. |
tileloaded | Triggered when each new tile is loaded, as a means of progress update to listeners. listeners can access ‘numLoadingTiles’ if they wish to keep track of the loading progress. Listeners are called with an object with a tile property as first argument, making the loded tile available to the listener. |
tileerror | Triggered before the tileloaded event (i.e. when the tile is still hidden) if a tile failed to load. Listeners receive an object as first argument, which has a tile property that references the tile that could not be loaded. |
removeMap: function( map )
Called when the layer is removed from the map.
map | {ALKMaps.Map} The map. |
clone: function ( obj )
Create a clone of this layer
obj | {Object} Is this ever used? |
{ALKMaps.Layer.Grid} An exact clone of this ALKMaps.Layer.Grid
moveTo:function( bounds, zoomChanged, dragging )
This function is called whenever the map is moved. All the moving of actual ‘tiles’ is done by the map, but moveTo’s role is to accept a bounds and make sure the data that that bounds requires is pre-loaded.
bounds | {ALKMaps.Bounds} |
zoomChanged | {Boolean} |
dragging | {Boolean} |
getTileData: function( loc )
Given a map location, retrieve a tile and the pixel offset within that tile corresponding to the location. If there is not an existing tile in the grid that covers the given location, null will be returned.
loc | {ALKMaps.LonLat} map location |
{Object} Object with the following properties: tile ({ALKMaps.Tile}), i ({Number} x-pixel offset from top left), and j ({Integer} y-pixel offset from top left).
getServerResolution: function( resolution )
Return the closest highest server-supported resolution. Throw an exception if none is found in the serverResolutions array.
resolution | {Number} The base resolution. If undefined the map resolution is used. |
{Number} The closest highest server resolution value.
getServerZoom: function()
Return the zoom value corresponding to the best matching server resolution, taking into account serverResolutions and <zoomOffset>.
{Number} The closest server supported zoom. This is not the map zoom level, but an index of the server’s resolutions array.
setTileSize: function( size )
Check if we are in singleTile mode and if so, set the size as a ratio of the map size (as specified by the layer’s ‘ratio’ property).
size | {ALKMaps.Size} |
getTilesBounds: function()
Return the bounds of the tile grid.
{ALKMaps.Bounds} A Bounds object representing the bounds of all the currently loaded tiles (including those partially or not at all seen onscreen).
calculateGridLayout: function( bounds, origin, resolution )
Generate parameters for the grid layout.
bounds | {<ALKMaps.Bound>|Object} ALKMaps.Bounds or an object with a ‘left’ and ‘top’ properties. |
origin | {<ALKMaps.LonLat>|Object} ALKMaps.LonLat or an object with a ‘lon’ and ‘lat’ properties. |
resolution | {Number} |
{Object} containing properties tilelon, tilelat, tileoffsetlat, tileoffsetlat, tileoffsetx, tileoffsety
getTileOrigin: function()
Determine the origin for aligning the grid of tiles. If a tileOrigin property is supplied, that will be returned. Otherwise, the origin will be derived from the layer’s maxExtent property. In this case, the tile origin will be the corner of the maxExtent given by the tileOriginCorner property.
{ALKMaps.LonLat} The tile origin.
addTile: function( bounds, position )
Create a tile, initialize it, and add it to the layer div.
Parameters bounds - {ALKMaps.Bounds} position - {ALKMaps.Pixel}
{ALKMaps.Tile} The added ALKMaps.Tile
addTileMonitoringHooks: function( tile )
This function takes a tile as input and adds the appropriate hooks to the tile so that the layer can keep track of the loading tiles.
tile | {ALKMaps.Tile} |
removeTileMonitoringHooks: function( tile )
This function takes a tile as input and removes the tile hooks that were added in addTileMonitoringHooks()
tile | {ALKMaps.Tile} |
getTileBounds: function( viewPortPx )
Returns The tile bounds for a layer given a pixel location.
viewPortPx | {ALKMaps.Pixel} The location in the viewport. |
{ALKMaps.Bounds} Bounds of the tile at the given pixel location.
moveGriddedTiles: function( deferred )
Draws the first tile from the tileQueue, and unqueues that tile
drawTileFromQueue: function()
setMap: function( map )
Called when the layer is removed from the map.
removeMap: function( map )
Deconstruct the layer and clear the grid.
destroy: function()
Go through and remove all tiles from the grid, calling destroy() on each of them to kill circular references
clearGrid:function()
Create a clone of this layer
clone: function ( obj )
This function is called whenever the map is moved.
moveTo:function( bounds, zoomChanged, dragging )
Given a map location, retrieve a tile and the pixel offset within that tile corresponding to the location.
getTileData: function( loc )
Adds a tile to the animation queue that will draw it.
queueTileDraw: function( evt )
Clears the animation queue
clearTileQueue: function()
destroyTile: function( tile )
Return the closest highest server-supported resolution.
getServerResolution: function( resolution )
Return the zoom value corresponding to the best matching server resolution, taking into account serverResolutions and zoomOffset.
getServerZoom: function()
Transform the layer div.
transformDiv: function( scale )
Return the value by which the layer is currently scaled.
getResolutionScale: function()
Create, insert, scale and position a back buffer for the layer.
applyBackBuffer: function( resolution )
Create a back buffer.
createBackBuffer: function()
Remove back buffer from DOM.
removeBackBuffer: function()
Move the layer based on pixel vector.
moveByPx: function( dx, dy )
Check if we are in singleTile mode and if so, set the size as a ratio of the map size (as specified by the layer’s ‘ratio’ property).
setTileSize: function( size )
Return the bounds of the tile grid.
getTilesBounds: function()
initSingleTile: function( bounds )
Generate parameters for the grid layout.
calculateGridLayout: function( bounds, origin, resolution )
Determine the origin for aligning the grid of tiles.
getTileOrigin: function()
initGriddedTiles:function( bounds )
Get this layer’s maximum extent.
getMaxExtent: function()
Create a tile, initialize it, and add it to the layer div.
addTile: function( bounds, position )
This function takes a tile as input and adds the appropriate hooks to the tile so that the layer can keep track of the loading tiles.
addTileMonitoringHooks: function( tile )
This function takes a tile as input and removes the tile hooks that were added in addTileMonitoringHooks()
removeTileMonitoringHooks: function( tile )
Shifty grid work
shiftRow:function( prepend )
Shift grid work in the other dimension
shiftColumn: function( prepend )
When the size of the map or the buffer changes, we may need to remove some excess rows and columns.
removeExcessTiles: function( rows, columns )
For singleTile layers, this will set a new tile size according to the dimensions of the map pane.
onMapResize: function()
Returns The tile bounds for a layer given a pixel location.
getTileBounds: function( viewPortPx )