Changeset 2979
- Timestamp:
- 04/02/07 13:18:38 (2 years ago)
- Files:
-
- trunk/openlayers/examples/gutter.html (added)
- trunk/openlayers/examples/mapserver.html (modified) (1 diff)
- trunk/openlayers/examples/mapserver_untiled.html (modified) (1 diff)
- trunk/openlayers/examples/wms-untiled.html (added)
- trunk/openlayers/lib/OpenLayers/Layer.js (modified) (5 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/MapServer.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/MapServer/Untiled.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/WMS.js (modified) (3 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Tile/Image.js (modified) (7 diffs)
- trunk/openlayers/tests/Layer/test_MapServer.html (modified) (2 diffs)
- trunk/openlayers/tests/Layer/test_MapServer_Untiled.html (modified) (1 diff)
- trunk/openlayers/tests/Layer/test_WMS.html (modified) (3 diffs)
- trunk/openlayers/tests/Tile/test_Image.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/examples/mapserver.html
r2978 r2979 19 19 map = new OpenLayers.Map( 'map' ); 20 20 layer = new OpenLayers.Layer.MapServer( "OpenLayers WMS", 21 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); 21 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'}, 22 {gutter: 15}); 22 23 map.addLayer(layer); 23 24 trunk/openlayers/examples/mapserver_untiled.html
r2978 r2979 3 3 <style type="text/css"> 4 4 #map { 5 width: 800px;6 height: 475px;5 width: 100%; 6 height: 100%; 7 7 border: 1px solid black; 8 8 } trunk/openlayers/lib/OpenLayers/Layer.js
r2894 r2979 66 66 */ 67 67 inRange: false, 68 69 /** 70 * For layers that use Tile.Image, the image size is cached here. For 71 * layers without a gutter, the image size is equal to the tile size. 72 * For layers with a gutter, the image is larger than the tile by twice 73 * the gutter in each dimension. 74 * 75 * @type OpenLayers.Size 76 * @private 77 */ 78 imageSize: null, 79 80 /** 81 * For layers that use Tile.Image, the image offset is cached here. 82 * Layers without a gutter have zero offset. For layers with a gutter, 83 * the image offset represents displacement due to the gutter. 84 * 85 * @type OpenLayers.Pixel 86 * @private 87 */ 88 imageOffset: null, 68 89 69 90 // OPTIONS … … 71 92 /** @type Array */ 72 93 options: null, 94 95 /** Determines the width (in pixels) of the gutter around image tiles 96 * to ignore. By setting this property to a non-zero value, images 97 * will be requested that are wider and taller than the tile size by 98 * a value of 2 x gutter. This allows artifacts of rendering at tile 99 * edges to be ignored. Set a gutter value that is equal to half the size 100 * of the widest symbol that needs to be displayed. Defaults to zero. 101 * Non-tiled layers always have zero gutter. 102 * 103 * @type Int 104 */ 105 gutter: 0, 73 106 74 107 /** @type String */ … … 244 277 if (!this.isBaseLayer) { 245 278 this.inRange = this.calculateInRange(); 246 } 279 } 280 281 // deal with gutters 282 this.setTileSize(); 247 283 }, 248 284 285 /** 286 * Set the tile size based on the map size. This also sets layer.imageSize 287 * and layer.imageOffset for use by Tile.Image. 288 * 289 * @param OpenLayers.Size 290 */ 291 setTileSize: function(size) { 292 var tileSize = (size) ? size : 293 ((this.tileSize) ? this.tileSize : 294 this.map.getTileSize()); 295 this.tileSize = tileSize; 296 if(this.gutter) { 297 // layers with gutters need non-null tile sizes 298 //if(tileSize == null) { 299 // OpenLayers.console.error("Error in layer.setMap() for " + 300 // this.name + ": layers with gutters " + 301 // "need non-null tile sizes"); 302 //} 303 this.imageOffset = new OpenLayers.Pixel(-this.gutter, -this.gutter); 304 this.imageSize = new OpenLayers.Size(tileSize.w + (2 * this.gutter), 305 tileSize.h + (2 * this.gutter)); 306 } else { 307 // layers without gutters may have null tile size - as long 308 // as they don't rely on Tile.Image 309 this.imageSize = tileSize; 310 this.imageOffset = new OpenLayers.Pixel(0, 0); 311 } 312 }, 313 249 314 /** 250 315 * @returns Whether or not the layer should be displayed (if in range) … … 561 626 562 627 /** 628 * Adjusts the extent of a bounds in map units by the layer's gutter 629 * in pixels. 630 * 631 * @param {OpenLayers.Bounds} bounds 632 * @type OpenLayers.Bounds 633 * @return A bounds adjusted in height and width by the gutter 634 */ 635 adjustBoundsByGutter: function(bounds) { 636 var mapGutter = this.gutter * this.map.getResolution(); 637 bounds = new OpenLayers.Bounds(bounds.left - mapGutter, 638 bounds.bottom - mapGutter, 639 bounds.right + mapGutter, 640 bounds.top + mapGutter); 641 return bounds; 642 }, 643 644 /** 563 645 * Sets the opacity for the entire layer (all images) 564 646 * @param {Float} opacity … … 567 649 this.opacity = opacity; 568 650 for(var i=0; i<this.div.childNodes.length; ++i) { 569 var element = this.div.childNodes[i] ;651 var element = this.div.childNodes[i].firstChild; 570 652 OpenLayers.Util.modifyDOMElement(element, null, null, null, 571 653 null, null, null, opacity); trunk/openlayers/lib/OpenLayers/Layer/MapServer.js
r2920 r2979 88 88 */ 89 89 getURL: function (bounds) { 90 90 if(this.gutter) { 91 bounds = this.adjustBoundsByGutter(bounds); 92 } 91 93 // Make a list, so that getFullRequestString uses literal "," 92 94 var extent = [bounds.left, bounds. bottom, bounds.right, bounds.top]; … … 96 98 {mapext: extent, 97 99 imgext: extent, 98 map_size: [this. tileSize.w,this.tileSize.h],99 imgx: this. tileSize.w/2,100 imgy: this. tileSize.h/2,101 imgxy: [this. tileSize.w,this.tileSize.h]100 map_size: [this.imageSize.w, this.imageSize.h], 101 imgx: this.imageSize.w / 2, 102 imgy: this.imageSize.h / 2, 103 imgxy: [this.imageSize.w, this.imageSize.h] 102 104 }); 103 105 trunk/openlayers/lib/OpenLayers/Layer/MapServer/Untiled.js
r2978 r2979 100 100 */ 101 101 setMap: function(map) { 102 //determine new tile size103 this.tileSize = map.getSize();104 this.tileSize.w = this.tileSize.w * this.ratio;105 this.tileSize.h = this.tileSize.h * this.ratio;106 102 OpenLayers.Layer.HTTPRequest.prototype.setMap.apply(this, arguments); 103 }, 104 105 /** 106 * Set the tile size based on the map size. This also sets layer.imageSize 107 * and layer.imageOffset for use by Tile.Image. 108 */ 109 setTileSize: function() { 110 var tileSize = this.map.getSize(); 111 tileSize.w = tileSize.w * this.ratio; 112 tileSize.h = tileSize.h * this.ratio; 113 this.tileSize = tileSize; 114 this.imageSize = tileSize; 115 this.imageOffset = new OpenLayers.Pixel(0, 0); 107 116 }, 108 117 … … 150 159 151 160 //determine new tile size 152 this.tileSize = this.map.getSize(); 153 this.tileSize.w = this.tileSize.w * this.ratio; 154 this.tileSize.h = this.tileSize.h * this.ratio; 161 this.setTileSize(); 155 162 156 163 //formulate request url string trunk/openlayers/lib/OpenLayers/Layer/WMS.js
r2543 r2979 25 25 26 26 reproject: true, 27 27 28 28 /** 29 29 * @constructor … … 94 94 */ 95 95 getURL: function (bounds) { 96 if(this.gutter) { 97 bounds = this.adjustBoundsByGutter(bounds); 98 } 96 99 return this.getFullRequestString( 97 100 {BBOX:bounds.toBBOX(), 98 WIDTH:this. tileSize.w,99 HEIGHT:this. tileSize.h});101 WIDTH:this.imageSize.w, 102 HEIGHT:this.imageSize.h}); 100 103 }, 101 104 … … 110 113 */ 111 114 addTile:function(bounds,position) { 112 url = this.getURL(bounds);115 var url = this.getURL(bounds); 113 116 return new OpenLayers.Tile.Image(this, position, bounds, 114 117 url, this.tileSize); trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js
r2974 r2979 103 103 */ 104 104 setMap: function(map) { 105 //determine new tile size106 this.tileSize = map.getSize();107 this.tileSize.w = this.tileSize.w * this.ratio;108 this.tileSize.h = this.tileSize.h * this.ratio;109 105 OpenLayers.Layer.HTTPRequest.prototype.setMap.apply(this, arguments); 106 }, 107 108 /** 109 * Set the tile size based on the map size. This also sets layer.imageSize 110 * and layer.imageOffset for use by Tile.Image. 111 */ 112 setTileSize: function() { 113 var tileSize = this.map.getSize(); 114 tileSize.w = tileSize.w * this.ratio; 115 tileSize.h = tileSize.h * this.ratio; 116 this.tileSize = tileSize; 117 this.imageSize = tileSize; 118 this.imageOffset = new OpenLayers.Pixel(0, 0); 110 119 }, 111 120 … … 153 162 154 163 //determine new tile size 155 this.tileSize = this.map.getSize(); 156 this.tileSize.w = this.tileSize.w * this.ratio; 157 this.tileSize.h = this.tileSize.h * this.ratio; 164 this.setTileSize(); 158 165 159 166 //formulate request url string trunk/openlayers/lib/OpenLayers/Tile/Image.js
r2917 r2979 16 16 imgDiv: null, 17 17 18 /** 19 * The image element is appended to the frame. Any gutter on the image 20 * will be hidden behind the frame. 21 * 22 * @type DOMElement div */ 23 frame: null, 24 18 25 /** 19 26 * @constructor … … 27 34 initialize: function(layer, position, bounds, url, size) { 28 35 OpenLayers.Tile.prototype.initialize.apply(this, arguments); 36 this.frame = document.createElement('div'); 37 this.frame.style.overflow = 'hidden'; 38 this.frame.style.position = 'absolute'; 29 39 }, 30 40 … … 35 45 if (this.imgDiv != null) { 36 46 OpenLayers.Event.stopObservingElement(this.imgDiv.id); 37 if (this.imgDiv.parentNode == this. layer.div) {38 this. layer.div.removeChild(this.imgDiv);47 if (this.imgDiv.parentNode == this.frame) { 48 this.frame.removeChild(this.imgDiv); 39 49 this.imgDiv.map = null; 40 50 } 41 51 } 42 52 this.imgDiv = null; 53 if ((this.frame != null) && (this.frame.parentNode == this.layer.div)) { 54 this.layer.div.removeChild(this.frame); 55 } 56 this.frame = null; 43 57 OpenLayers.Tile.prototype.destroy.apply(this, arguments); 44 58 }, … … 61 75 62 76 this.url = this.layer.getURL(this.bounds); 63 77 // position the frame 78 OpenLayers.Util.modifyDOMElement(this.frame, 79 null, this.position, this.size); 80 64 81 if (this.layer.alpha) { 65 82 OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, 66 null, this.position, this.size, this.url);83 null, null, this.layer.imageSize, this.url); 67 84 } else { 68 85 this.imgDiv.src = this.url; 69 86 OpenLayers.Util.modifyDOMElement(this.imgDiv, 70 null, this.position, this.size) ;87 null, null, this.layer.imageSize) ; 71 88 } 72 89 this.drawn = true; … … 103 120 if (this.layer.alpha) { 104 121 this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, 105 this. position,106 this. size,122 this.layer.imageOffset, 123 this.layer.imageSize, 107 124 null, 108 " absolute",125 "relative", 109 126 null, 110 127 null, … … 113 130 } else { 114 131 this.imgDiv = OpenLayers.Util.createImage(null, 115 this. position,116 this. size,132 this.layer.imageOffset, 133 this.layer.imageSize, 117 134 null, 118 " absolute",135 "relative", 119 136 null, 120 137 null, … … 132 149 this.checkImgURL.bindAsEventListener(this) ); 133 150 */ 134 this.layer.div.appendChild(this.imgDiv); 151 this.frame.appendChild(this.imgDiv); 152 this.layer.div.appendChild(this.frame); 153 135 154 if(this.layer.opacity != null) { 136 155 trunk/openlayers/tests/Layer/test_MapServer.html
r2978 r2979 55 55 url + "?" + OpenLayers.Util.getParameterString(tParams).replace(/,/g, "+"), 56 56 "image src is created correctly via addtile" ); 57 t.eq( tile. imgDiv.style.top, "6px", "image top is set correctly via addtile" );58 t.eq( tile. imgDiv.style.left, "5px", "image top is set correctly via addtile" );59 60 var firstChild = layer.div.firstChild ;57 t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" ); 58 t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" ); 59 60 var firstChild = layer.div.firstChild.firstChild; 61 61 if (!isMozilla) 62 62 t.ok( true, "skipping element test outside of Mozilla"); … … 187 187 map.zoomToMaxExtent(); 188 188 t.eq(tLayer.opacity, "0.5", "Opacity is set correctly"); 189 t.eq(parseFloat(tLayer.div.firstChild. style.opacity), 0.5, "Opacity on tile is correct");189 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct"); 190 190 tLayer.setOpacity("0.6"); 191 191 t.eq(tLayer.opacity, "0.6", "setOpacity works properly"); 192 t.eq(parseFloat(tLayer.div.firstChild. style.opacity), 0.6, "Opacity on tile is changed correctly");192 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly"); 193 193 var pixel = new OpenLayers.Pixel(5,6); 194 194 var tile = tLayer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel); trunk/openlayers/tests/Layer/test_MapServer_Untiled.html
r2978 r2979 128 128 map.zoomToMaxExtent(); 129 129 t.eq(tLayer.opacity, "0.5", "Opacity is set correctly"); 130 t.eq(parseFloat(tLayer.div.firstChild. style.opacity), 0.5, "Opacity on tile is correct");130 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct"); 131 131 tLayer.setOpacity("0.6"); 132 132 t.eq(tLayer.opacity, "0.6", "setOpacity works properly"); 133 t.eq(parseFloat(tLayer.div.firstChild. style.opacity), 0.6, "Opacity on tile is changed correctly");133 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly"); 134 134 135 135 } trunk/openlayers/tests/Layer/test_WMS.html
r2852 r2979 51 51 url + "?" + OpenLayers.Util.getParameterString(tParams), 52 52 "image src is created correctly via addtile" ); 53 t.eq( tile. imgDiv.style.top, "6px", "image top is set correctly via addtile" );54 t.eq( tile. imgDiv.style.left, "5px", "image top is set correctly via addtile" );55 56 var firstChild = layer.div.firstChild ;53 t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" ); 54 t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" ); 55 56 var firstChild = layer.div.firstChild.firstChild; 57 57 if (!isMozilla) 58 58 t.ok( true, "skipping element test outside of Mozilla"); … … 192 192 map.zoomToMaxExtent(); 193 193 t.eq(tLayer.opacity, "0.5", "Opacity is set correctly"); 194 t.eq(parseFloat(tLayer.div.firstChild. style.opacity), 0.5, "Opacity on tile is correct");194 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct"); 195 195 tLayer.setOpacity("0.6"); 196 196 t.eq(tLayer.opacity, "0.6", "setOpacity works properly"); 197 t.eq(parseFloat(tLayer.div.firstChild. style.opacity), 0.6, "Opacity on tile is changed correctly");197 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly"); 198 198 var pixel = new OpenLayers.Pixel(5,6); 199 199 var tile = tLayer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel); … … 230 230 231 231 map.destroy(); 232 } 233 234 function test_21_Layer_WMS_noGutters (t) { 235 t.plan(2); 236 var map = new OpenLayers.Map('map'); 237 var layer = new OpenLayers.Layer.WMS("no gutter layer", url, params, {gutter: 0}); 238 map.addLayer(layer); 239 map.setCenter(new OpenLayers.LonLat(0,0), 5); 240 var tile = layer.grid[0][0]; 241 var request = layer.getURL(tile.bounds); 242 var args = OpenLayers.Util.getArgs(request); 243 t.eq(parseInt(args['WIDTH']), 244 tile.size.w, 245 "layer without gutter requests images that are as wide as the tile"); 246 t.eq(parseInt(args['HEIGHT']), 247 tile.size.h, 248 "layer without gutter requests images that are as tall as the tile"); 249 250 layer.destroy(); 251 map.destroy(); 252 } 253 254 function test_22_Layer_WMS_gutters (t) { 255 t.plan(2); 256 var gutter = 15; 257 var map = new OpenLayers.Map('map'); 258 var layer = new OpenLayers.Layer.WMS("gutter layer", url, params, {gutter: gutter}); 259 map.addLayer(layer); 260 map.setCenter(new OpenLayers.LonLat(0,0), 5); 261 var tile = layer.grid[0][0]; 262 var request = layer.getURL(tile.bounds); 263 var args = OpenLayers.Util.getArgs(request); 264 t.eq(parseInt(args['WIDTH']), 265 tile.size.w + (2 * gutter), 266 "layer with gutter requests images that are wider by twice the gutter"); 267 t.eq(parseInt(args['HEIGHT']), 268 tile.size.h + (2 * gutter), 269 "layer with gutter requests images that are taller by twice the gutter"); 270 271 layer.destroy(); 272 map.destroy(); 273 232 274 } 233 275 trunk/openlayers/tests/Tile/test_Image.html
r2803 r2979 30 30 var map = new OpenLayers.Map('map'); 31 31 32 layer = new OpenLayers.Layer.WMS("Name", "http://labs.metacarta.com/TESTURL"); 32 var size = new OpenLayers.Size(5,6); 33 layer = new OpenLayers.Layer.WMS("Name", 34 "http://labs.metacarta.com/TESTURL", 35 null, 36 {tileSize: size}); 33 37 map.addLayer(layer); 34 38 var position = new OpenLayers.Pixel(20,30); 35 39 var bounds = new OpenLayers.Bounds(1,2,3,4); 36 40 var url = "http://www.openlayers.org/dev/tests/tileimage"; 37 var size = new OpenLayers.Size(5,6);38 41 tile = new OpenLayers.Tile.Image(layer, position, bounds, url, size); 39 42 … … 54 57 EXCEPTIONS: "application/vnd.ogc.se_inimage", FORMAT: "image/jpeg", 55 58 SRS: "EPSG:4326", BBOX: "1,2,3,4", 56 WIDTH: "256", HEIGHT: "256"59 WIDTH: String(size.w), HEIGHT: String(size.h) 57 60 }; 58 61 t.eq( img.src, … … 168 171 169 172 } 173 174 function test_05_Tile_Image_gutters(t) { 175 t.plan(5); 176 177 var gutter = 0; 178 var name = 'Test Layer'; 179 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 180 var params = { map: '/mapdata/vmap_wms.map', 181 layers: 'basic', 182 format: 'image/png'}; 183 184 185 var map = new OpenLayers.Map('map'); 186 var layer = new OpenLayers.Layer.WMS(name, url, params, {gutter: gutter}); 187 map.addLayer(layer); 188 map.setCenter(new OpenLayers.LonLat(0,0), 5); 189 190 var tile = layer.grid[0][0]; 191 192 t.ok(tile.layer.imageSize.equals(tile.size), 193 "zero size gutter doesn't change image size"); 194 195 t.ok(tile.layer.imageOffset.equals(new OpenLayers.Pixel(0, 0)), 196 "zero size gutter doesn't affect image offset"); 197 198 map.destroy(); 199 200 var gutter = 15; 201 var map = new OpenLayers.Map('map'); 202 var layer = new OpenLayers.Layer.WMS(name, url, params, {gutter: gutter}); 203 map.addLayer(layer); 204 map.setCenter(new OpenLayers.LonLat(0,0), 5); 205 var tile = layer.grid[0][0]; 206 t.ok(tile.layer.imageSize.equals(new OpenLayers.Size(tile.size.w + (2 * gutter), 207 tile.size.h + (2 * gutter))), 208 "gutter properly changes image size"); 209 210 t.ok(tile.layer.imageOffset.equals(new OpenLayers.Pixel(-gutter, -gutter)), 211 "gutter properly sets image offset"); 212 213 t.ok(tile.bounds.equals(new OpenLayers.Bounds(-33.75, 33.75, -22.5, 45)), 214 "gutter doesn't affect tile bounds"); 215 216 map.destroy(); 217 } 218 170 219 // --> 171 220 </script> 172 221 </head> 173 222 <body> 174 <div id="map" style="height:5 00px;width:500px"></div>223 <div id="map" style="height:550px;width:500px"></div> 175 224 </body> 176 225 </html>
