| 1 | | /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD |
|---|
| 2 | | * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
|---|
| 3 | | * full text of the license. */ |
|---|
| 4 | | |
|---|
| | 1 | /* Copyright (c) 2006-2007 MetaCarta, Inc., published under the BSD license. |
|---|
| | 2 | * See http://svn.openlayers.org/trunk/openlayers/release-license.txt |
|---|
| | 3 | * for the full text of the license. */ |
|---|
| | 4 | |
|---|
| | 5 | /* |
|---|
| | 6 | Modified 18th Nov, 2007. Added support for local tile caches. Andrew Larcombe. |
|---|
| | 7 | */ |
|---|
| 49 | | * options - {Object} additional options |
|---|
| | 57 | * options - {Object} additional options. |
|---|
| | 58 | * |
|---|
| | 59 | * If the option localCache is set, or the url for the layer is of a file schema (ie starts file://) |
|---|
| | 60 | * then intialize will use this as the base directory for a cached set of worldwind data. Level n data should |
|---|
| | 61 | * be present in a subdirectory named n. eg if the url of the layer is set to file:///home/wwcache/ then worldwind |
|---|
| | 62 | * level 1 data is expected to be found in the directory /home/wwcache/1. |
|---|
| | 63 | * If running on Internet Explorer or Firefox then this function tests for the presence |
|---|
| | 64 | * of the file 0000/0000_0000.jpg to confirm the presence of the cache files. |
|---|
| 52 | | this.lzd = lzd; |
|---|
| | 67 | |
|---|
| | 68 | this.cacheDir = new Array(); |
|---|
| | 69 | |
|---|
| | 70 | if((options != undefined && options.localCache) || (url.substr(0,7) == 'file://')) { |
|---|
| | 71 | |
|---|
| | 72 | var fso = false; |
|---|
| | 73 | var mozFile = false; |
|---|
| | 74 | |
|---|
| | 75 | if(url.substr(0,7) != 'file://') { |
|---|
| | 76 | |
|---|
| | 77 | try { |
|---|
| | 78 | fso = new ActiveXObject("Scripting.FileSystemObject"); |
|---|
| | 79 | } |
|---|
| | 80 | catch(ex) { |
|---|
| | 81 | } |
|---|
| | 82 | |
|---|
| | 83 | try { |
|---|
| | 84 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); |
|---|
| | 85 | var mozFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); |
|---|
| | 86 | } |
|---|
| | 87 | catch(ex) { |
|---|
| | 88 | } |
|---|
| | 89 | |
|---|
| | 90 | } |
|---|
| | 91 | |
|---|
| | 92 | var base; |
|---|
| | 93 | if(url.substr(0,7) == 'file://') { |
|---|
| | 94 | base = url.substring(7); |
|---|
| | 95 | } |
|---|
| | 96 | else { |
|---|
| | 97 | base = options.localCache; |
|---|
| | 98 | } |
|---|
| | 99 | |
|---|
| | 100 | var dir; |
|---|
| | 101 | var zeroFileExists; |
|---|
| | 102 | var zeroFilePath; |
|---|
| | 103 | |
|---|
| | 104 | for(i = 0; i <= zoomLevels; i++ ) { |
|---|
| | 105 | dir = base + "/" + i; |
|---|
| | 106 | zeroFilePath = dir + "/0000/0000_0000.jpg"; |
|---|
| | 107 | zeroFileExists = false; |
|---|
| | 108 | |
|---|
| | 109 | if(mozFile) { |
|---|
| | 110 | try { |
|---|
| | 111 | mozFile.initWithPath(zeroFilePath); |
|---|
| | 112 | zeroFileExists = mozFile.exists(); |
|---|
| | 113 | } |
|---|
| | 114 | catch(ex) { |
|---|
| | 115 | } |
|---|
| | 116 | } |
|---|
| | 117 | else if(fso) { |
|---|
| | 118 | zeroFileExists = fso.FileExists(zeroFilePath); |
|---|
| | 119 | } |
|---|
| | 120 | else { |
|---|
| | 121 | zeroFileExists = true; |
|---|
| | 122 | } |
|---|
| | 123 | |
|---|
| | 124 | if (zeroFileExists) { |
|---|
| | 125 | this.cacheDir[i] = dir; |
|---|
| | 126 | } |
|---|
| | 127 | } |
|---|
| | 128 | |
|---|
| | 129 | |
|---|
| | 130 | } |
|---|
| | 131 | |
|---|
| | 132 | this.lzd = lzd; |
|---|
| 102 | | if (this.map.getResolution() <= (this.lzd/512) |
|---|
| 103 | | && this.getZoom() <= this.zoomLevels) { |
|---|
| 104 | | return this.getFullRequestString( |
|---|
| 105 | | { L: zoom, |
|---|
| | 183 | //if (this.map.getResolution() <= (this.lzd/512) && this.getZoom() <= this.zoomLevels) { |
|---|
| | 184 | //if (this.map.getResolution() <= (this.lzd/this.tileSize.w) && zoom <= this.zoomLevels) { |
|---|
| | 185 | return this.getURLForTile(zoom,x,y); |
|---|
| | 186 | //} else { |
|---|
| | 187 | // return OpenLayers.Util.getImagesLocation() + "blank.gif"; |
|---|
| | 188 | //} |
|---|
| | 189 | |
|---|
| | 190 | }, |
|---|
| | 191 | |
|---|
| | 192 | |
|---|
| | 193 | /** |
|---|
| | 194 | * Method: getURLForTile |
|---|
| | 195 | * |
|---|
| | 196 | * Parameters: |
|---|
| | 197 | * z - {Integer} zoom level |
|---|
| | 198 | * x - {Integer} x |
|---|
| | 199 | * y - {Integer} y |
|---|
| | 200 | * |
|---|
| | 201 | * |
|---|
| | 202 | * Returns: |
|---|
| | 203 | * {String} A string containing the URL of the tile depending on whether the tile |
|---|
| | 204 | * should be retrieved from a local cache or a remote server. If this.cachedir[z] is |
|---|
| | 205 | * defined then the function will return the URI to the image file in the local cache, |
|---|
| | 206 | * else it'll return the result of a call to getFullRequestString |
|---|
| | 207 | * |
|---|
| | 208 | */ |
|---|
| | 209 | getURLForTile: function(z,x,y) { |
|---|
| | 210 | |
|---|
| | 211 | if(this.map.getResolution() > (this.lzd/this.tileSize.w)) { |
|---|
| | 212 | if(this.adjustTileSizeAndRedraw(512 / (2*(this.getZoomForResolution(this.lzd/512) - this.map.getZoom())))) { |
|---|
| | 213 | return; |
|---|
| | 214 | } |
|---|
| | 215 | } |
|---|
| | 216 | else if(this.tileSize.w < 512 && (this.map.getResolution() <= (this.lzd/512)) ) { |
|---|
| | 217 | if(this.adjustTileSizeAndRedraw(512)) { |
|---|
| | 218 | return; |
|---|
| | 219 | } |
|---|
| | 220 | } |
|---|
| | 221 | else if(this.tileSize.w > 512 && z <= this.zoomLevels) { |
|---|
| | 222 | if(this.adjustTileSizeAndRedraw(512)) { |
|---|
| | 223 | return; |
|---|
| | 224 | } |
|---|
| | 225 | } |
|---|
| | 226 | else if(this.getZoom() > this.zoomLevels) { |
|---|
| | 227 | if(this.adjustTileSizeAndRedraw(512 * (2*(this.getZoom() - this.zoomLevels)))) { |
|---|
| | 228 | return; |
|---|
| | 229 | } |
|---|
| | 230 | } |
|---|
| | 231 | |
|---|
| | 232 | z = Math.min(z,this.zoomLevels); |
|---|
| | 233 | |
|---|
| | 234 | if(this.cacheDir[z] != undefined) { |
|---|
| | 235 | x = "0000" + x; |
|---|
| | 236 | y = "0000" + y; |
|---|
| | 237 | return this.cacheDir[z]+"/"+y.substr(y.length-4)+"/"+y.substr(y.length-4)+"_"+x.substr(x.length-4)+".jpg"; |
|---|
| | 238 | } |
|---|
| | 239 | else { |
|---|
| | 240 | return this.getFullRequestString( |
|---|
| | 241 | { L: z, |
|---|