[OpenLayers-Commits] r11440 - in sandbox/jennier/openlayers:
examples lib/OpenLayers/Layer lib/OpenLayers/Protocol
lib/OpenLayers/Tile
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Feb 24 12:22:52 EST 2011
Author: jennier
Date: 2011-02-24 09:22:52 -0800 (Thu, 24 Feb 2011)
New Revision: 11440
Modified:
sandbox/jennier/openlayers/examples/local-storage-wms-simple.html
sandbox/jennier/openlayers/lib/OpenLayers/Layer/ArcGIS93Rest.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/ArcIMS.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/Grid.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/KaMap.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/MapGuide.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/MapServer.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/TMS.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/TileCache.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/WMS.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/WMTS.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/WorldWind.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/XYZ.js
sandbox/jennier/openlayers/lib/OpenLayers/Layer/Zoomify.js
sandbox/jennier/openlayers/lib/OpenLayers/Protocol/BrowserStorage.js
sandbox/jennier/openlayers/lib/OpenLayers/Tile/Image.js
Log:
Local Storage should now only use a proxy for the tiles it stores. Also should properly retrieve and draw tiles now.
Modified: sandbox/jennier/openlayers/examples/local-storage-wms-simple.html
===================================================================
--- sandbox/jennier/openlayers/examples/local-storage-wms-simple.html 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/examples/local-storage-wms-simple.html 2011-02-24 17:22:52 UTC (rev 11440)
@@ -25,8 +25,8 @@
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
map.addControl( new OpenLayers.Control.LayerSwitcher() );
- // Set the cache counter.
- layerOSGeo.countCache(updateCacheCount);
+ // Set the cache counter, checks every second.
+ window.setInterval(function(){layerOSGeo.countCache(updateCacheCount)},1000);
};
@@ -53,8 +53,8 @@
tiles currently being viewed in local storage. Also allows the store to be cleared.
<br/>
<br/>
- <a href="#" onclick="layerOSGeo.cacheAreaViewed();layerOSGeo.countCache(updateCacheCount);return false;">Cache the area being viewed.</a><br/><br/>
- <a href="#" onclick="layerOSGeo.clearCache();layerOSGeo.countCache(updateCacheCount);return false;">Clear the cache.</a><br/><br/>
+ <a href="#" onclick="layerOSGeo.cacheAreaViewed();return false;">Cache the area being viewed.</a><br/><br/>
+ <a href="#" onclick="layerOSGeo.clearCache();return false;">Clear the cache.</a><br/><br/>
Tiles Stored: <em id="count">0</em>.
</div>
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/ArcGIS93Rest.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/ArcGIS93Rest.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/ArcGIS93Rest.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -175,7 +175,7 @@
var url = this.getFullRequestString(newParams);
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
/**
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/ArcIMS.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/ArcIMS.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/ArcIMS.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -206,7 +206,7 @@
}
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/Grid.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/Grid.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/Grid.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -853,38 +853,19 @@
* {String} a GetMap query string for this layer or the data URI for this
* image from local storage. To be used as the img src.
*/
- getURL: function (url) {
+ getCacheURL: function (url, tile) {
// If we want to use the local cache, check to see if they exist and
// use those values if they do.
- if (this.params.ENABLELOCALCACHE) {
-
- // Check if the map being requested is on the same domain/port
- var sameOrigin = !(url.indexOf("http") == 0);
- var urlParts = !sameOrigin && url.match(this.URL_SPLIT_REGEX);
- if (urlParts) {
- var location = window.location;
- sameOrigin =
- urlParts[1] == location.protocol &&
- urlParts[3] == location.hostname;
- var uPort = urlParts[4], lPort = location.port;
- if (uPort != 80 && uPort != "" || lPort != "80" && lPort != "") {
- sameOrigin = sameOrigin && uPort == lPort;
- }
- }
-
- // For proxy need to url encode the params.
- if (!sameOrigin && OpenLayers.ProxyHost) {
- url = OpenLayers.ProxyHost+encodeURIComponent(url);
- } else if (!sameOrigin){
- OpenLayers.Console.warn(
- OpenLayers.i18n("proxyNeeded"), {url: url});
- }
-
+ if (this.params.ENABLELOCALCACHE) {
+
// check to see if the tile exists in the cache
- var imageCached = this.store.get(url);
+ var imageCached = this.store.get(url, tile.imgDiv);
+
+ if (imageCached) {
+ return imageCached;
+ }
-
}
return url;
@@ -897,35 +878,73 @@
cacheAreaViewed:function() {
if (this.params.ENABLELOCALCACHE) {
-
- var tileImageCount = 0;
-
+
// Go through all the tiles in the current view and get their URL.
for (var i=0; i<this.grid.length; i++) {
for (var j=0; j<this.grid[i].length; j++) {
-
- var canvas = document.createElement("canvas");
- canvas.width = this.tileSize.w;
- canvas.height = this.tileSize.h;
- var ctx = canvas.getContext("2d");
- ctx.drawImage(this.grid[i][j].imgDiv, 0, 0);
- // Below does not work in FireFox
- //var imageData = canvas.toDataURL(this.params.FORMAT,'quality=20');
- var imageData = canvas.toDataURL();
-
- this.store.set(this.grid[i][j].url,imageData);
-
- tileImageCount++;
+
+ // before we can store the image we need to proxy to if it comes
+ // from another domain.
+ var proxiedURL = this.getProxiedURL(this.grid[i][j].url);
+
+ this.grid[i][j].imgDiv.onload = OpenLayers.Function.bindAsEventListener(this.cacheTile ,this.grid[i][j]);
+ this.grid[i][j].imgDiv.src = proxiedURL;
+
}
}
- console.log("Stored "+tileImageCount+" Tiles");
+
}
return false;
},
+
+ getProxiedURL: function(url) {
+
+ // Check if the map being requested is on the same domain/port
+ var sameOrigin = !(url.indexOf("http") == 0);
+ var urlParts = !sameOrigin && url.match(this.URL_SPLIT_REGEX);
+ if (urlParts) {
+ var location = window.location;
+ sameOrigin =
+ urlParts[1] == location.protocol &&
+ urlParts[3] == location.hostname;
+ var uPort = urlParts[4], lPort = location.port;
+ if (uPort != 80 && uPort != "" || lPort != "80" && lPort != "") {
+ sameOrigin = sameOrigin && uPort == lPort;
+ }
+ }
+
+ var proxiedURL;
+ // For proxy need to url encode the params.
+ if (!sameOrigin && OpenLayers.ProxyHost) {
+ proxiedURL = OpenLayers.ProxyHost+encodeURIComponent(url);
+ } else if (!sameOrigin){
+ OpenLayers.Console.warn(
+ OpenLayers.i18n("proxyNeeded"), {url: url});
+ }
+
+ return proxiedURL;
+ },
+
+ cacheTile: function(e) {
+
+ var canvas = document.createElement("canvas");
+ canvas.width = this.size.w;
+ canvas.height = this.size.h;
+ var ctx = canvas.getContext("2d");
+ ctx.drawImage(this.imgDiv, 0, 0);
+ // Below does not work in FireFox
+ //var imageData = canvas.toDataURL(this.params.FORMAT,'quality=20');
+ var imageData = canvas.toDataURL();
+
+ // store under original URL
+ this.layer.store.set(this.url,imageData);
+
+ this.imgDiv.onload = {};
+ },
- clearCache:function() {
+ clearCache: function() {
if (this.store) {
this.store.clear();
}
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/KaMap.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/KaMap.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/KaMap.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -94,7 +94,7 @@
});
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
/**
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/MapGuide.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/MapGuide.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/MapGuide.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -322,7 +322,7 @@
}
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/MapServer.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/MapServer.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/MapServer.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -124,7 +124,7 @@
});
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
/**
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/TMS.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/TMS.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/TMS.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -131,7 +131,7 @@
url = url + path;
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
/**
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/TileCache.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/TileCache.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/TileCache.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -145,7 +145,7 @@
url = url + path;
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
/**
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/WMS.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/WMS.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/WMS.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -186,7 +186,7 @@
* passed-in bounds and appropriate tile size specified as
* parameters.
*/
- getURL: function (bounds) {
+ getURL: function (bounds, tile) {
bounds = this.adjustBounds(bounds);
var imageSize = this.getImageSize();
@@ -199,9 +199,9 @@
newParams.WIDTH = imageSize.w;
newParams.HEIGHT = imageSize.h;
var url= this.getFullRequestString(newParams);
-
+ console.log("in get URL");
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url, tile]);
},
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/WMTS.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/WMTS.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/WMTS.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -439,7 +439,7 @@
}
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
/**
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/WorldWind.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/WorldWind.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/WorldWind.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -116,7 +116,7 @@
}
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
CLASS_NAME: "OpenLayers.Layer.WorldWind"
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/XYZ.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/XYZ.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/XYZ.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -128,7 +128,7 @@
url = OpenLayers.String.format(url, xyz);
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
/**
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Layer/Zoomify.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Layer/Zoomify.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Layer/Zoomify.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -211,7 +211,7 @@
url = url + path;
// Check to see if the Image has been stored locally
- return OpenLayers.Layer.Grid.prototype.getURL.apply(this, [url]);
+ return OpenLayers.Layer.Grid.prototype.getCacheURL.apply(this, [url]);
},
/**
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Protocol/BrowserStorage.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Protocol/BrowserStorage.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Protocol/BrowserStorage.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -8,7 +8,7 @@
*/
/**
- * Class: OpenLayers.Protocol.BroswerStorage
+ * Class: OpenLayers.Protocol.BrowserStorage
* Class for access to SQL Web Storage or Web (local) Storage.
* Allows you to store, retrieve and get information about what
* is stored.
@@ -22,8 +22,8 @@
var store;
// Default to Web SQL Storage
try {
- store = this.sqlStore;
- return store.initialize(name, version, description, size);
+ /// store = this.sqlStore;
+ // return store.initialize(name, version, description, size);
} catch (e) {
/* Does not support Web SQL Storage */
}
@@ -71,8 +71,9 @@
}
}
},
- get: function(key) {
- return localStorage.getItem(key);
+ get: function(key, imgDiv) {
+ imgDiv.src = localStorage.getItem(key);
+ return imgDiv.src;
},
clear: function() {
localStorage.clear();
@@ -119,7 +120,6 @@
},
set: function(key, value) {
- var name = this.name;
// TODO Check for existing entries to prevent duplicates.
this.db.transaction(
function(tx) {
@@ -132,16 +132,16 @@
});
});
},
- get: function(key) {
- var name = this.name;
+ get: function(key, tile) {
this.db.transaction(
function(tx) {
- console.log("Select value from OLTable where key=?");
+ console.log("Select value from OLTable where key="+key);
tx.executeSql("Select value from OLTable where key=?",
[key],
function(tx, result) {
if(result.rows.length){
- return result.rows.item(0).data;
+ tile.src = result.rows.item(0).value;
+ return tile.src;
}
}, function(tx, error) {
console.debug(error);
@@ -167,7 +167,7 @@
var name = this.name;
this.db.transaction(
function(tx) {
- console.log("Select count(*) as count from OLTable");
+ // console.log("Select count(*) as count from OLTable");
tx.executeSql("Select count(*) as count from OLTable",
[],
function(tx, result) {
@@ -177,11 +177,6 @@
}, function(tx, error) {
console.debug(error);
});
- },
- function(tx, result) {
- console.debug(tx);
- }, function(tx, error) {
- console.debug(tx);
});
}
},
Modified: sandbox/jennier/openlayers/lib/OpenLayers/Tile/Image.js
===================================================================
--- sandbox/jennier/openlayers/lib/OpenLayers/Tile/Image.js 2011-02-24 17:11:44 UTC (rev 11439)
+++ sandbox/jennier/openlayers/lib/OpenLayers/Tile/Image.js 2011-02-24 17:22:52 UTC (rev 11440)
@@ -298,11 +298,13 @@
} else {
// syncronous image requests get the url and position the frame immediately,
// and don't wait for an image request to come back.
-
- this.url = this.layer.getURL(this.bounds);
+
+ this.initImgDiv();
+
+ this.url = this.layer.getURL(this.bounds, this);
+ this.imgDiv.src = this.url;
- this.initImgDiv();
-
+
// position the frame immediately
this.positionImage();
}
More information about the Commits
mailing list