Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -8,13 +8,10 @@ function init() {
|
|||||||
div: "map",
|
div: "map",
|
||||||
projection: "EPSG:900913",
|
projection: "EPSG:900913",
|
||||||
layers: [
|
layers: [
|
||||||
new OpenLayers.Layer.WMS("OSGeo", "http://vmap0.tiles.osgeo.org/wms/vmap0", {
|
new OpenLayers.Layer.WMS(
|
||||||
layers: "basic"
|
"OSGeo", "http://vmap0.tiles.osgeo.org/wms/vmap0",
|
||||||
}, {
|
{layers: "basic"}
|
||||||
eventListeners: {
|
)
|
||||||
tileloaded: updateStatus
|
|
||||||
}
|
|
||||||
})
|
|
||||||
],
|
],
|
||||||
center: [0, 0],
|
center: [0, 0],
|
||||||
zoom: 1
|
zoom: 1
|
||||||
@@ -38,6 +35,7 @@ function init() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// update the number of cached tiles and detect local storage support
|
// update the number of cached tiles and detect local storage support
|
||||||
|
map.layers[0].events.on({'tileloaded': updateStatus});
|
||||||
function updateStatus() {
|
function updateStatus() {
|
||||||
if (window.localStorage) {
|
if (window.localStorage) {
|
||||||
status.innerHTML = localStorage.length + " entries in cache.";
|
status.innerHTML = localStorage.length + " entries in cache.";
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -19,14 +19,12 @@
|
|||||||
function init(){
|
function init(){
|
||||||
map = new OpenLayers.Map('map');
|
map = new OpenLayers.Map('map');
|
||||||
|
|
||||||
var options = {numZoomLevels: 3};
|
|
||||||
|
|
||||||
var graphic = new OpenLayers.Layer.Image(
|
var graphic = new OpenLayers.Layer.Image(
|
||||||
'City Lights',
|
'City Lights',
|
||||||
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif',
|
'data/4_m_citylights_lg.gif',
|
||||||
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
|
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
|
||||||
new OpenLayers.Size(580, 288),
|
new OpenLayers.Size(580, 288),
|
||||||
options
|
{numZoomLevels: 3}
|
||||||
);
|
);
|
||||||
|
|
||||||
graphic.events.on({
|
graphic.events.on({
|
||||||
@@ -38,9 +36,12 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
|
var jpl_wms = new OpenLayers.Layer.WMS(
|
||||||
"http://t1.hypercube.telascience.org/cgi-bin/landsat7",
|
"Global Imagery",
|
||||||
{layers: "landsat7"}, options);
|
"http://demo.opengeo.org/geoserver/wms",
|
||||||
|
{layers: "bluemarble"},
|
||||||
|
{maxExtent: [-160, -88.759, 160, 88.759], numZoomLevels: 3}
|
||||||
|
);
|
||||||
|
|
||||||
map.addLayers([graphic, jpl_wms]);
|
map.addLayers([graphic, jpl_wms]);
|
||||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ OpenLayers.Control.CacheWrite = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
addLayer: function(evt) {
|
addLayer: function(evt) {
|
||||||
evt.layer.events.on({
|
evt.layer.events.on({
|
||||||
tileloadstart: this.makeSameOrigin,
|
tileloadstart: this.makeSameOrigin,
|
||||||
tileloaded: this.cache,
|
tileloaded: this.onTileLoaded,
|
||||||
scope: this
|
scope: this
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -128,7 +128,7 @@ OpenLayers.Control.CacheWrite = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
removeLayer: function(evt) {
|
removeLayer: function(evt) {
|
||||||
evt.layer.events.un({
|
evt.layer.events.un({
|
||||||
tileloadstart: this.makeSameOrigin,
|
tileloadstart: this.makeSameOrigin,
|
||||||
tileloaded: this.cache,
|
tileloaded: this.onTileLoaded,
|
||||||
scope: this
|
scope: this
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -156,6 +156,22 @@ OpenLayers.Control.CacheWrite = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: onTileLoaded
|
||||||
|
* Decides whether a tile can be cached and calls the cache method.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* evt - {Event}
|
||||||
|
*/
|
||||||
|
onTileLoaded: function(evt) {
|
||||||
|
if (this.active && !evt.aborted &&
|
||||||
|
evt.tile instanceof OpenLayers.Tile.Image &&
|
||||||
|
evt.tile.url.substr(0, 5) !== 'data:') {
|
||||||
|
this.cache({tile: evt.tile});
|
||||||
|
delete OpenLayers.Control.CacheWrite.urlMap[evt.tile.url];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: cache
|
* Method: cache
|
||||||
* Adds a tile to the cache. When the cache is full, the "cachefull" event
|
* Adds a tile to the cache. When the cache is full, the "cachefull" event
|
||||||
@@ -166,29 +182,25 @@ OpenLayers.Control.CacheWrite = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* <OpenLayers.Tile.Image> with the data to add to the cache
|
* <OpenLayers.Tile.Image> with the data to add to the cache
|
||||||
*/
|
*/
|
||||||
cache: function(obj) {
|
cache: function(obj) {
|
||||||
if (this.active && window.localStorage) {
|
if (window.localStorage) {
|
||||||
var tile = obj.tile;
|
var tile = obj.tile;
|
||||||
if (tile instanceof OpenLayers.Tile.Image &&
|
try {
|
||||||
tile.url.substr(0, 5) !== 'data:') {
|
var canvasContext = tile.getCanvasContext();
|
||||||
try {
|
if (canvasContext) {
|
||||||
var canvasContext = tile.getCanvasContext();
|
var urlMap = OpenLayers.Control.CacheWrite.urlMap;
|
||||||
if (canvasContext) {
|
var url = urlMap[tile.url] || tile.url;
|
||||||
var urlMap = OpenLayers.Control.CacheWrite.urlMap;
|
window.localStorage.setItem(
|
||||||
var url = urlMap[tile.url] || tile.url;
|
"olCache_" + url,
|
||||||
window.localStorage.setItem(
|
canvasContext.canvas.toDataURL(this.imageFormat)
|
||||||
"olCache_" + url,
|
);
|
||||||
canvasContext.canvas.toDataURL(this.imageFormat)
|
}
|
||||||
);
|
} catch(e) {
|
||||||
delete urlMap[tile.url];
|
// local storage full or CORS violation
|
||||||
}
|
var reason = e.name || e.message;
|
||||||
} catch(e) {
|
if (reason && this.quotaRegEx.test(reason)) {
|
||||||
// local storage full or CORS violation
|
this.events.triggerEvent("cachefull", {tile: tile});
|
||||||
var reason = e.name || e.message;
|
} else {
|
||||||
if (reason && this.quotaRegEx.test(reason)) {
|
OpenLayers.Console.error(e.toString());
|
||||||
this.events.triggerEvent("cachefull", {tile: tile});
|
|
||||||
} else {
|
|
||||||
OpenLayers.Console.error(e.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,6 +358,17 @@ OpenLayers.Layer.ArcGISCache = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
return OpenLayers.Layer.XYZ.prototype.clone.apply(this, [obj]);
|
return OpenLayers.Layer.XYZ.prototype.clone.apply(this, [obj]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: initGriddedTiles
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* bounds - {<OpenLayers.Bounds>}
|
||||||
|
*/
|
||||||
|
initGriddedTiles: function(bounds) {
|
||||||
|
delete this._tileOrigin;
|
||||||
|
OpenLayers.Layer.XYZ.prototype.initGriddedTiles.apply(this, arguments);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: getMaxExtent
|
* Method: getMaxExtent
|
||||||
* Get this layer's maximum extent.
|
* Get this layer's maximum extent.
|
||||||
@@ -379,8 +390,11 @@ OpenLayers.Layer.ArcGISCache = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
* {<OpenLayers.LonLat>} The tile origin.
|
* {<OpenLayers.LonLat>} The tile origin.
|
||||||
*/
|
*/
|
||||||
getTileOrigin: function() {
|
getTileOrigin: function() {
|
||||||
var extent = this.getMaxExtent();
|
if (!this._tileOrigin) {
|
||||||
return new OpenLayers.LonLat(extent.left, extent.bottom);
|
var extent = this.getMaxExtent();
|
||||||
|
this._tileOrigin = new OpenLayers.LonLat(extent.left, extent.bottom);
|
||||||
|
}
|
||||||
|
return this._tileOrigin;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+103
-97
@@ -262,14 +262,29 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
* loaded, as a means of progress update to listeners.
|
* loaded, as a means of progress update to listeners.
|
||||||
* listeners can access 'numLoadingTiles' if they wish to keep
|
* listeners can access 'numLoadingTiles' if they wish to keep
|
||||||
* track of the loading progress. Listeners are called with an object
|
* track of the loading progress. Listeners are called with an object
|
||||||
* with a tile property as first argument, making the loded tile
|
* with a 'tile' property as first argument, making the loaded tile
|
||||||
* available to the listener.
|
* available to the listener, and an 'aborted' property, which will be
|
||||||
|
* true when loading was aborted and no tile data is available.
|
||||||
* tileerror - Triggered before the tileloaded event (i.e. when the tile is
|
* tileerror - Triggered before the tileloaded event (i.e. when the tile is
|
||||||
* still hidden) if a tile failed to load. Listeners receive an object
|
* still hidden) if a tile failed to load. Listeners receive an object
|
||||||
* as first argument, which has a tile property that references the
|
* as first argument, which has a tile property that references the
|
||||||
* tile that could not be loaded.
|
* tile that could not be loaded.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: gridLayout
|
||||||
|
* {Object} Object containing properties tilelon, tilelat, startcol,
|
||||||
|
* startrow
|
||||||
|
*/
|
||||||
|
gridLayout: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: rowSign
|
||||||
|
* {Number} 1 for grids starting at the top, -1 for grids starting at the
|
||||||
|
* bottom. This is used for several grid index and offset calculations.
|
||||||
|
*/
|
||||||
|
rowSign: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Layer.Grid
|
* Constructor: OpenLayers.Layer.Grid
|
||||||
* Create a new grid layer
|
* Create a new grid layer
|
||||||
@@ -301,6 +316,8 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
this.moveTimerId = null;
|
this.moveTimerId = null;
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.rowSign = this.tileOriginCorner.substr(0, 1) === "t" ? 1 : -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -363,6 +380,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
}
|
}
|
||||||
this.grid = [];
|
this.grid = [];
|
||||||
this.gridResolution = null;
|
this.gridResolution = null;
|
||||||
|
this.gridLayout = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -866,35 +884,24 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
* resolution - {Number}
|
* resolution - {Number}
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Object} containing properties tilelon, tilelat, tileoffsetlat,
|
* {Object} Object containing properties tilelon, tilelat, startcol,
|
||||||
* tileoffsetlat, tileoffsetx, tileoffsety
|
* startrow
|
||||||
*/
|
*/
|
||||||
calculateGridLayout: function(bounds, origin, resolution) {
|
calculateGridLayout: function(bounds, origin, resolution) {
|
||||||
var tilelon = resolution * this.tileSize.w;
|
var tilelon = resolution * this.tileSize.w;
|
||||||
var tilelat = resolution * this.tileSize.h;
|
var tilelat = resolution * this.tileSize.h;
|
||||||
|
|
||||||
var ratio = resolution / this.map.getResolution(),
|
|
||||||
tileSize = {
|
|
||||||
w: Math.round(this.tileSize.w * ratio),
|
|
||||||
h: Math.round(this.tileSize.h * ratio)
|
|
||||||
};
|
|
||||||
|
|
||||||
var offsetlon = bounds.left - origin.lon;
|
var offsetlon = bounds.left - origin.lon;
|
||||||
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
||||||
var tilecolremain = offsetlon/tilelon - tilecol;
|
|
||||||
var tileoffsetx = -tilecolremain * tileSize.w;
|
|
||||||
var tileoffsetlon = origin.lon + tilecol * tilelon;
|
|
||||||
|
|
||||||
var offsetlat = bounds.top - (origin.lat + tilelat);
|
var rowSign = this.rowSign;
|
||||||
var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
|
|
||||||
var tilerowremain = tilerow - offsetlat/tilelat;
|
var offsetlat = rowSign * (origin.lat - bounds.top + tilelat);
|
||||||
var tileoffsety = -tilerowremain * tileSize.h;
|
var tilerow = Math[~rowSign ? 'floor' : 'ceil'](offsetlat/tilelat) - this.buffer * rowSign;
|
||||||
var tileoffsetlat = origin.lat + tilerow * tilelat;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tilelon: tilelon, tilelat: tilelat,
|
tilelon: tilelon, tilelat: tilelat,
|
||||||
tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
|
startcol: tilecol, startrow: tilerow
|
||||||
tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
|
|
||||||
};
|
};
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -925,6 +932,32 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
return origin;
|
return origin;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: getTileBoundsForGridIndex
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* row - {Number} The row of the grid
|
||||||
|
* col - {Number} The column of the grid
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {<OpenLayers.Bounds>} The bounds for the tile at (row, col)
|
||||||
|
*/
|
||||||
|
getTileBoundsForGridIndex: function(row, col) {
|
||||||
|
var origin = this.getTileOrigin();
|
||||||
|
var tileLayout = this.gridLayout;
|
||||||
|
var tilelon = tileLayout.tilelon;
|
||||||
|
var tilelat = tileLayout.tilelat;
|
||||||
|
var startcol = tileLayout.startcol;
|
||||||
|
var startrow = tileLayout.startrow;
|
||||||
|
var rowSign = this.rowSign;
|
||||||
|
return new OpenLayers.Bounds(
|
||||||
|
origin.lon + (startcol + col) * tilelon,
|
||||||
|
origin.lat - (startrow + row * rowSign) * tilelat * rowSign,
|
||||||
|
origin.lon + (startcol + col + 1) * tilelon,
|
||||||
|
origin.lat - (startrow + (row - 1) * rowSign) * tilelat * rowSign
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: initGriddedTiles
|
* Method: initGriddedTiles
|
||||||
*
|
*
|
||||||
@@ -954,50 +987,38 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
2 * this.buffer + 1;
|
2 * this.buffer + 1;
|
||||||
|
|
||||||
var tileLayout = this.calculateGridLayout(bounds, origin, serverResolution);
|
var tileLayout = this.calculateGridLayout(bounds, origin, serverResolution);
|
||||||
var tileoffsetx = Math.round(tileLayout.tileoffsetx); // heaven help us
|
this.gridLayout = tileLayout;
|
||||||
var tileoffsety = Math.round(tileLayout.tileoffsety);
|
|
||||||
|
|
||||||
var tileoffsetlon = tileLayout.tileoffsetlon;
|
|
||||||
var tileoffsetlat = tileLayout.tileoffsetlat;
|
|
||||||
|
|
||||||
var tilelon = tileLayout.tilelon;
|
var tilelon = tileLayout.tilelon;
|
||||||
var tilelat = tileLayout.tilelat;
|
var tilelat = tileLayout.tilelat;
|
||||||
|
|
||||||
var startX = tileoffsetx;
|
|
||||||
var startLon = tileoffsetlon;
|
|
||||||
|
|
||||||
var rowidx = 0;
|
|
||||||
|
|
||||||
var layerContainerDivLeft = this.map.layerContainerOriginPx.x;
|
var layerContainerDivLeft = this.map.layerContainerOriginPx.x;
|
||||||
var layerContainerDivTop = this.map.layerContainerOriginPx.y;
|
var layerContainerDivTop = this.map.layerContainerOriginPx.y;
|
||||||
|
|
||||||
|
var tileBounds = this.getTileBoundsForGridIndex(0, 0);
|
||||||
|
var startPx = this.map.getViewPortPxFromLonLat(
|
||||||
|
new OpenLayers.LonLat(tileBounds.left, tileBounds.top)
|
||||||
|
);
|
||||||
|
startPx.x = Math.round(startPx.x) - layerContainerDivLeft;
|
||||||
|
startPx.y = Math.round(startPx.y) - layerContainerDivTop;
|
||||||
|
|
||||||
var tileData = [], center = this.map.getCenter();
|
var tileData = [], center = this.map.getCenter();
|
||||||
|
|
||||||
|
var rowidx = 0;
|
||||||
do {
|
do {
|
||||||
var row = this.grid[rowidx++];
|
var row = this.grid[rowidx];
|
||||||
if (!row) {
|
if (!row) {
|
||||||
row = [];
|
row = [];
|
||||||
this.grid.push(row);
|
this.grid.push(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
tileoffsetlon = startLon;
|
|
||||||
tileoffsetx = startX;
|
|
||||||
var colidx = 0;
|
var colidx = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
var tileBounds =
|
tileBounds = this.getTileBoundsForGridIndex(rowidx, colidx);
|
||||||
new OpenLayers.Bounds(tileoffsetlon,
|
var px = startPx.clone();
|
||||||
tileoffsetlat,
|
px.x = px.x + colidx * Math.round(tileSize.w);
|
||||||
tileoffsetlon + tilelon,
|
px.y = px.y + rowidx * Math.round(tileSize.h);
|
||||||
tileoffsetlat + tilelat);
|
var tile = row[colidx];
|
||||||
|
|
||||||
var x = tileoffsetx;
|
|
||||||
x -= layerContainerDivLeft;
|
|
||||||
|
|
||||||
var y = tileoffsety;
|
|
||||||
y -= layerContainerDivTop;
|
|
||||||
|
|
||||||
var px = new OpenLayers.Pixel(x, y);
|
|
||||||
var tile = row[colidx++];
|
|
||||||
if (!tile) {
|
if (!tile) {
|
||||||
tile = this.addTile(tileBounds, px);
|
tile = this.addTile(tileBounds, px);
|
||||||
this.addTileMonitoringHooks(tile);
|
this.addTileMonitoringHooks(tile);
|
||||||
@@ -1012,14 +1033,12 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
Math.pow(tileCenter.lat - center.lat, 2)
|
Math.pow(tileCenter.lat - center.lat, 2)
|
||||||
});
|
});
|
||||||
|
|
||||||
tileoffsetlon += tilelon;
|
colidx += 1;
|
||||||
tileoffsetx += Math.round(tileSize.w);
|
} while ((tileBounds.right <= bounds.right + tilelon * this.buffer)
|
||||||
} while ((tileoffsetlon <= bounds.right + tilelon * this.buffer)
|
|
||||||
|| colidx < minCols);
|
|| colidx < minCols);
|
||||||
|
|
||||||
tileoffsetlat -= tilelat;
|
rowidx += 1;
|
||||||
tileoffsety += Math.round(tileSize.h);
|
} while((tileBounds.bottom >= bounds.bottom - tilelat * this.buffer)
|
||||||
} while((tileoffsetlat >= bounds.bottom - tilelat * this.buffer)
|
|
||||||
|| rowidx < minRows);
|
|| rowidx < minRows);
|
||||||
|
|
||||||
//shave off exceess rows and colums
|
//shave off exceess rows and colums
|
||||||
@@ -1090,9 +1109,12 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
this.numLoadingTiles++;
|
this.numLoadingTiles++;
|
||||||
};
|
};
|
||||||
|
|
||||||
tile.onLoadEnd = function() {
|
tile.onLoadEnd = function(evt) {
|
||||||
this.numLoadingTiles--;
|
this.numLoadingTiles--;
|
||||||
this.events.triggerEvent("tileloaded", {tile: tile});
|
this.events.triggerEvent("tileloaded", {
|
||||||
|
tile: tile,
|
||||||
|
aborted: evt.type === "unload"
|
||||||
|
});
|
||||||
//if that was the last tile, then trigger a 'loadend' on the layer
|
//if that was the last tile, then trigger a 'loadend' on the layer
|
||||||
if (this.tileQueue.length === 0 && this.numLoadingTiles === 0) {
|
if (this.tileQueue.length === 0 && this.numLoadingTiles === 0) {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
@@ -1194,31 +1216,23 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
* if false, then append to end
|
* if false, then append to end
|
||||||
* tileSize - {Object} rendered tile size; object with w and h properties
|
* tileSize - {Object} rendered tile size; object with w and h properties
|
||||||
*/
|
*/
|
||||||
shiftRow:function(prepend, tileSize) {
|
shiftRow: function(prepend, tileSize) {
|
||||||
var modelRowIndex = (prepend) ? 0 : (this.grid.length - 1);
|
|
||||||
var grid = this.grid;
|
var grid = this.grid;
|
||||||
var modelRow = grid[modelRowIndex];
|
var rowIndex = prepend ? 0 : (grid.length - 1);
|
||||||
|
|
||||||
var sign = prepend ? -1 : 1;
|
var sign = prepend ? -1 : 1;
|
||||||
var deltaLat = this.getServerResolution() * -sign * this.tileSize.h;
|
var rowSign = this.rowSign;
|
||||||
|
var tileLayout = this.gridLayout;
|
||||||
|
tileLayout.startrow += sign * rowSign;
|
||||||
|
|
||||||
var row = (prepend) ? grid.pop() : grid.shift();
|
var modelRow = grid[rowIndex];
|
||||||
|
var row = grid[prepend ? 'pop' : 'shift']();
|
||||||
for (var i=0, len=modelRow.length; i<len; i++) {
|
for (var i=0, len=row.length; i<len; i++) {
|
||||||
var modelTile = modelRow[i];
|
var tile = row[i];
|
||||||
var bounds = modelTile.bounds.clone();
|
var position = modelRow[i].position.clone();
|
||||||
var position = modelTile.position.clone();
|
position.y += tileSize.h * sign;
|
||||||
bounds.bottom = bounds.bottom + deltaLat;
|
tile.moveTo(this.getTileBoundsForGridIndex(rowIndex, i), position);
|
||||||
bounds.top = bounds.top + deltaLat;
|
|
||||||
position.y = position.y + sign * tileSize.h;
|
|
||||||
row[i].moveTo(bounds, position);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prepend) {
|
|
||||||
grid.unshift(row);
|
|
||||||
} else {
|
|
||||||
grid.push(row);
|
|
||||||
}
|
}
|
||||||
|
grid[prepend ? 'unshift' : 'push'](row);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1231,27 +1245,19 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
* tileSize - {Object} rendered tile size; object with w and h properties
|
* tileSize - {Object} rendered tile size; object with w and h properties
|
||||||
*/
|
*/
|
||||||
shiftColumn: function(prepend, tileSize) {
|
shiftColumn: function(prepend, tileSize) {
|
||||||
|
var grid = this.grid;
|
||||||
|
var colIndex = prepend ? 0 : (grid[0].length - 1);
|
||||||
var sign = prepend ? -1 : 1;
|
var sign = prepend ? -1 : 1;
|
||||||
var deltaLon = this.getServerResolution() * sign * this.tileSize.w;
|
var tileLayout = this.gridLayout;
|
||||||
|
tileLayout.startcol += sign;
|
||||||
|
|
||||||
for (var i=0, len=this.grid.length; i<len; i++) {
|
for (var i=0, len=grid.length; i<len; i++) {
|
||||||
var row = this.grid[i];
|
var row = grid[i];
|
||||||
var modelTileIndex = (prepend) ? 0 : (row.length - 1);
|
var position = row[colIndex].position.clone();
|
||||||
var modelTile = row[modelTileIndex];
|
var tile = row[prepend ? 'pop' : 'shift']();
|
||||||
|
position.x += tileSize.w * sign;
|
||||||
var bounds = modelTile.bounds.clone();
|
tile.moveTo(this.getTileBoundsForGridIndex(i, colIndex), position);
|
||||||
var position = modelTile.position.clone();
|
row[prepend ? 'unshift' : 'push'](tile);
|
||||||
bounds.left = bounds.left + deltaLon;
|
|
||||||
bounds.right = bounds.right + deltaLon;
|
|
||||||
position.x = position.x + sign * tileSize.w;
|
|
||||||
|
|
||||||
var tile = prepend ? this.grid[i].pop() : this.grid[i].shift();
|
|
||||||
tile.moveTo(bounds, position);
|
|
||||||
if (prepend) {
|
|
||||||
row.unshift(tile);
|
|
||||||
} else {
|
|
||||||
row.push(tile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
* resolution - {Number}
|
* resolution - {Number}
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Object} Object containing properties tilelon, tilelat, tileoffsetlat,
|
* {Object} Object containing properties tilelon, tilelat, startcol,
|
||||||
* tileoffsetlat, tileoffsetx, tileoffsety
|
* startrow
|
||||||
*/
|
*/
|
||||||
calculateGridLayout: function(bounds, origin, resolution) {
|
calculateGridLayout: function(bounds, origin, resolution) {
|
||||||
var tilelon = resolution*this.tileSize.w;
|
var tilelon = resolution*this.tileSize.w;
|
||||||
@@ -101,23 +101,39 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
|
|
||||||
var offsetlon = bounds.left;
|
var offsetlon = bounds.left;
|
||||||
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
||||||
var tilecolremain = offsetlon/tilelon - tilecol;
|
|
||||||
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
|
||||||
var tileoffsetlon = tilecol * tilelon;
|
|
||||||
|
|
||||||
var offsetlat = bounds.top;
|
var offsetlat = bounds.top;
|
||||||
var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
|
var tilerow = Math.floor(offsetlat/tilelat) + this.buffer;
|
||||||
var tilerowremain = tilerow - offsetlat/tilelat;
|
|
||||||
var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
|
|
||||||
var tileoffsetlat = tilerow * tilelat;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tilelon: tilelon, tilelat: tilelat,
|
tilelon: tilelon, tilelat: tilelat,
|
||||||
tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
|
startcol: tilecol, startrow: tilerow
|
||||||
tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: getTileBoundsForGridIndex
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* row - {Number} The row of the grid
|
||||||
|
* col - {Number} The column of the grid
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {<OpenLayers.Bounds>} The bounds for the tile at (row, col)
|
||||||
|
*/
|
||||||
|
getTileBoundsForGridIndex: function(row, col) {
|
||||||
|
var origin = this.getTileOrigin();
|
||||||
|
var tileLayout = this.gridLayout;
|
||||||
|
var tilelon = tileLayout.tilelon;
|
||||||
|
var tilelat = tileLayout.tilelat;
|
||||||
|
var minX = (tileLayout.startcol + col) * tilelon;
|
||||||
|
var minY = (tileLayout.startrow - row) * tilelat;
|
||||||
|
return new OpenLayers.Bounds(
|
||||||
|
minX, minY,
|
||||||
|
minX + tilelon, minY + tilelat
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: clone
|
* APIMethod: clone
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -439,41 +439,5 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
return requestString;
|
return requestString;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Method: calculateGridLayout
|
|
||||||
* Generate parameters for the grid layout. This
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* bounds - {<OpenLayers.Bound>}
|
|
||||||
* origin - {<OpenLayers.LonLat>}
|
|
||||||
* resolution - {Number}
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Object} Object containing properties tilelon, tilelat, tileoffsetlat,
|
|
||||||
* tileoffsetlat, tileoffsetx, tileoffsety
|
|
||||||
*/
|
|
||||||
calculateGridLayout: function(bounds, origin, resolution) {
|
|
||||||
var tilelon = resolution * this.tileSize.w;
|
|
||||||
var tilelat = resolution * this.tileSize.h;
|
|
||||||
|
|
||||||
var offsetlon = bounds.left - origin.lon;
|
|
||||||
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
|
||||||
var tilecolremain = offsetlon/tilelon - tilecol;
|
|
||||||
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
|
||||||
var tileoffsetlon = origin.lon + tilecol * tilelon;
|
|
||||||
|
|
||||||
var offsetlat = origin.lat - bounds.top + tilelat;
|
|
||||||
var tilerow = Math.floor(offsetlat/tilelat) - this.buffer;
|
|
||||||
var tilerowremain = tilerow - offsetlat/tilelat;
|
|
||||||
var tileoffsety = tilerowremain * this.tileSize.h;
|
|
||||||
var tileoffsetlat = origin.lat - tilelat*tilerow;
|
|
||||||
|
|
||||||
return {
|
|
||||||
tilelon: tilelon, tilelat: tilelat,
|
|
||||||
tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
|
|
||||||
tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Layer.MapGuide"
|
CLASS_NAME: "OpenLayers.Layer.MapGuide"
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -256,41 +256,5 @@ OpenLayers.Layer.Zoomify = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
this.map.maxExtent.top);
|
this.map.maxExtent.top);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Method: calculateGridLayout
|
|
||||||
* Generate parameters for the grid layout. This
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* bounds - {<OpenLayers.Bound>}
|
|
||||||
* origin - {<OpenLayers.LonLat>}
|
|
||||||
* resolution - {Number}
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Object} Object containing properties tilelon, tilelat, tileoffsetlat,
|
|
||||||
* tileoffsetlat, tileoffsetx, tileoffsety
|
|
||||||
*/
|
|
||||||
calculateGridLayout: function(bounds, origin, resolution) {
|
|
||||||
var tilelon = resolution * this.tileSize.w;
|
|
||||||
var tilelat = resolution * this.tileSize.h;
|
|
||||||
|
|
||||||
var offsetlon = bounds.left - origin.lon;
|
|
||||||
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
|
||||||
var tilecolremain = offsetlon/tilelon - tilecol;
|
|
||||||
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
|
||||||
var tileoffsetlon = origin.lon + tilecol * tilelon;
|
|
||||||
|
|
||||||
var offsetlat = origin.lat - bounds.top + tilelat;
|
|
||||||
var tilerow = Math.floor(offsetlat/tilelat) - this.buffer;
|
|
||||||
var tilerowremain = tilerow - offsetlat/tilelat;
|
|
||||||
var tileoffsety = tilerowremain * this.tileSize.h;
|
|
||||||
var tileoffsetlat = origin.lat - tilelat*tilerow;
|
|
||||||
|
|
||||||
return {
|
|
||||||
tilelon: tilelon, tilelat: tilelat,
|
|
||||||
tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
|
|
||||||
tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Layer.Zoomify"
|
CLASS_NAME: "OpenLayers.Layer.Zoomify"
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -217,8 +217,8 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
|
|||||||
if (this.layer instanceof OpenLayers.Layer.Grid) {
|
if (this.layer instanceof OpenLayers.Layer.Grid) {
|
||||||
ratio = this.layer.getServerResolution() / this.layer.map.getResolution();
|
ratio = this.layer.getServerResolution() / this.layer.map.getResolution();
|
||||||
}
|
}
|
||||||
style.left = (this.position.x | 0) + "px";
|
style.left = this.position.x + "px";
|
||||||
style.top = (this.position.y | 0) + "px";
|
style.top = this.position.y + "px";
|
||||||
style.width = Math.round(ratio * size.w) + "px";
|
style.width = Math.round(ratio * size.w) + "px";
|
||||||
style.height = Math.round(ratio * size.h) + "px";
|
style.height = Math.round(ratio * size.h) + "px";
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
t.plan(3);
|
t.plan(4);
|
||||||
OpenLayers.Control.CacheWrite.clearCache();
|
OpenLayers.Control.CacheWrite.clearCache();
|
||||||
var length = window.localStorage.length;
|
var length = window.localStorage.length;
|
||||||
|
|
||||||
@@ -68,6 +68,9 @@
|
|||||||
// content will be null for browsers that have localStorage but no canvas support
|
// content will be null for browsers that have localStorage but no canvas support
|
||||||
var content = canvasContext ? canvasContext.canvas.toDataURL("image/png") : null;
|
var content = canvasContext ? canvasContext.canvas.toDataURL("image/png") : null;
|
||||||
t.eq(window.localStorage.getItem("olCache_"+url), content, "localStorage contains correct image data");
|
t.eq(window.localStorage.getItem("olCache_"+url), content, "localStorage contains correct image data");
|
||||||
|
|
||||||
|
layer.events.triggerEvent('tileloaded', {aborted: true, tile: layer.grid[1][1]});
|
||||||
|
t.eq(window.localStorage.length, length + (canvasContext ? tiles-1 : 0), "tile aborted during load not cached");
|
||||||
|
|
||||||
var key = Math.random();
|
var key = Math.random();
|
||||||
window.localStorage.setItem(key, "bar");
|
window.localStorage.setItem(key, "bar");
|
||||||
|
|||||||
@@ -533,6 +533,30 @@
|
|||||||
|
|
||||||
map.destroy();
|
map.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_tileBounds(t) {
|
||||||
|
// do not defer moveGriddedTiles
|
||||||
|
var isNative = OpenLayers.Animation.isNative;
|
||||||
|
OpenLayers.Animation.isNative = true;
|
||||||
|
t.plan(3);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map("map", {projection: "EPSG:3857"});
|
||||||
|
var layer = new OpenLayers.Layer.WMS("wms", "../../img/blank.gif");
|
||||||
|
map.addLayer(layer);
|
||||||
|
map.setCenter([0, 0], 1);
|
||||||
|
map.pan(2, -100);
|
||||||
|
map.zoomIn();
|
||||||
|
t.eq(layer.grid[1][0].bounds, new OpenLayers.Bounds(-10018754.17, 0, 0, 10018754.17), "no floating point errors after zooming");
|
||||||
|
map.setCenter([0, 0], 14);
|
||||||
|
var bounds = layer.grid[0][0].bounds.clone();
|
||||||
|
map.pan(260, 520);
|
||||||
|
map.pan(-260, -520);
|
||||||
|
t.eq(layer.grid[0][0].bounds, bounds, "no floating point errors after dragging back and forth");
|
||||||
|
t.eq(bounds.right, 0, "0 is 0, and not some super small number");
|
||||||
|
|
||||||
|
map.destroy();
|
||||||
|
OpenLayers.Animation.isNative = isNative;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -154,9 +154,9 @@
|
|||||||
var m = new OpenLayers.Map('map', {adjustZoom: function(z) {return z;}});
|
var m = new OpenLayers.Map('map', {adjustZoom: function(z) {return z;}});
|
||||||
m.addLayer(layer);
|
m.addLayer(layer);
|
||||||
m.zoomToMaxExtent();
|
m.zoomToMaxExtent();
|
||||||
t.eq(layer.grid[5][7].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][7] kamap is okay");
|
t.eq(layer.grid[4][7].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][7] kamap is okay");
|
||||||
t.eq(layer.grid[5][6].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=0&s=221471921.25", "grid[5][6] kamap is okay");
|
t.eq(layer.grid[4][6].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=0&s=221471921.25", "grid[5][6] kamap is okay");
|
||||||
t.eq(layer.grid[5][5].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][5] is okay");
|
t.eq(layer.grid[4][5].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][5] is okay");
|
||||||
t.ok(layer.grid[7][6].url == null, "no latitudinal wrapping - tile not loaded if outside maxExtent");
|
t.ok(layer.grid[7][6].url == null, "no latitudinal wrapping - tile not loaded if outside maxExtent");
|
||||||
m.destroy();
|
m.destroy();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user