Changeset 4068
- Timestamp:
- 08/27/07 19:22:13 (1 year ago)
- Files:
-
- trunk/openlayers/examples/mapserver_untiled.html (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Layer/MapServer/Untiled.js (modified) (1 diff)
- trunk/openlayers/tests/Layer/test_MapServer.html (modified) (2 diffs)
- trunk/openlayers/tests/Layer/test_MapServer_Untiled.html (deleted)
- trunk/openlayers/tests/list-tests.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/examples/mapserver_untiled.html
r2979 r4068 9 9 </style> 10 10 <script src="../lib/OpenLayers.js"></script> 11 <script src="../lib/OpenLayers/Layer/MapServer/Untiled.js"></script>12 11 <script type="text/javascript"> 13 12 window.onload = function(){ 14 13 var map = new OpenLayers.Map( 'map', {maxResolution: 'auto'} ); 15 var layer = new OpenLayers.Layer.MapServer .Untiled( "MapServer Untiled",16 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );14 var layer = new OpenLayers.Layer.MapServer( "MapServer Untiled", 15 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'}, {singleTile: true} ); 17 16 map.addLayer(layer); 18 17 map.setCenter(new OpenLayers.LonLat(0, 0), 1); trunk/openlayers/lib/OpenLayers/Layer/MapServer/Untiled.js
r3786 r4068 1 /* Copyright (c) 2006-2007 MetaCarta, Inc., published under theBSD license.2 * See http://svn.openlayers.org/trunk/openlayers/re lease-license.txt1 /* Copyright 2006-2007 MetaCarta, Inc., published under a modified BSD license. 2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 3 3 * for the full text of the license. */ 4 4 5 5 6 /** 6 * @requires OpenLayers/Layer/HTTPRequest.js7 7 * @requires OpenLayers/Layer/MapServer.js 8 8 * 9 * Class: OpenLayers.Layer.MapServer.Untiled 10 * 11 * Inherits from: 12 * - <OpenLayers.Layer.HTTPRequest> 9 * Class: OpenLayers.Layer.MapServer 10 * Deprecated, to be removed in 3.0 - instead use OpenLayers.Layer.MapServer and 11 * pass the option 'singleTile' as true. 12 * 13 * Inherits from: 14 * - <OpenLayers.Layer.MapServer> 13 15 */ 14 OpenLayers.Layer.MapServer.Untiled = OpenLayers.Class( 15 OpenLayers.Layer.HTTPRequest, { 16 OpenLayers.Layer.MapServer.Untiled = OpenLayers.Class(OpenLayers.Layer.MapServer, { 16 17 17 18 /** 18 * Constant: default_params19 * Hashtable of default parameter key/value pairs19 * APIProperty: singleTile 20 * {singleTile} Always true for untiled. 20 21 */ 21 default_params: { 22 mode: "map", 23 map_imagetype: "png" 24 }, 25 26 /** 27 * APIProperty: reproject 28 * {Boolean} 'stretch' tiles according to base layer. 29 */ 30 reproject: true, 22 singleTile: true, 31 23 32 24 /** 33 * APIProperty: ratio 34 * {Float} the ratio of image/tile size to map size (this is the untiled 35 * buffer) 25 * Constructor: OpenLayers.Layer.MapServer.Untiled 26 * 27 * Parameters: 28 * name - {String} 29 * url - {String} 30 * params - {Object} 31 * options - {Object} 36 32 */ 37 ratio: 1,38 39 /**40 * Property: tile41 * {<OpenLayers.Tile.Image>}42 */43 tile: null,44 45 /**46 * Propety: doneLoading47 * {Boolean} did the image finish loading before a new draw was initiated?48 */49 doneLoading: false,50 51 /**52 * Constructor: OpenLayers.Layer.MapServer.Untiled53 *54 * Parameters:55 * name - {String}56 * url - {String}57 * params - {Object}58 */59 33 initialize: function(name, url, params, options) { 60 var newArguments = []; 61 newArguments.push(name, url, params, options); 62 OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this, 63 newArguments); 64 OpenLayers.Util.applyDefaults( 65 this.params, 66 this.default_params 67 ); 68 69 // unless explicitly set in options, if the layer is transparent, 70 // it will be an overlay 71 if ((options == null) || (options.isBaseLayer == null)) { 72 this.isBaseLayer = ((this.params.transparent != "true") && 73 (this.params.transparent != true)); 74 } 34 OpenLayers.Layer.MapServer.prototype.initialize.apply(this, arguments); 35 36 var msg = "The OpenLayers.Layer.MapServer.Untiled class is deprecated and " + 37 "will be removed in 3.0. Instead, you should use the " + 38 "normal OpenLayers.Layer.MapServer class, passing it the option " + 39 "'singleTile' as true."; 40 OpenLayers.Console.warn(msg); 75 41 }, 76 42 77 /**78 * APIMethod: destroy79 */80 destroy: function() {81 if (this.tile) {82 this.tile.destroy();83 this.tile = null;84 }85 OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments);86 },87 88 /**89 * APIMethod: clone90 * obj - {Object}91 *92 * Returns:93 * {<OpenLayers.Layer.MapServer.Untiled>} An exact clone of this94 * OpenLayers.Layer.MapServer.Untiled95 */96 clone: function (obj) {97 98 if (obj == null) {99 obj = new OpenLayers.Layer.MapServer.Untiled(this.name,100 this.url,101 this.params,102 this.options);103 }104 105 //get all additions from superclasses106 obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]);107 108 // copy/set any non-init, non-simple values here109 110 return obj;111 },112 113 114 /**115 * Method: setMap116 * Once HTTPRequest has set the map, we can load the image div117 *118 * Parameters:119 * map - {<OpenLayers.Map>}120 */121 setMap: function(map) {122 OpenLayers.Layer.HTTPRequest.prototype.setMap.apply(this, arguments);123 },124 125 /**126 * Method: setTileSize127 * Set the tile size based on the map size.128 */129 setTileSize: function() {130 var tileSize = this.map.getSize();131 tileSize.w = tileSize.w * this.ratio;132 tileSize.h = tileSize.h * this.ratio;133 this.tileSize = tileSize;134 },135 136 /**137 * Method: moveTo138 * When it is not a dragging move (ie when done dragging)139 * reload and recenter the div.140 *141 * Parameters:142 * bounds - {<OpenLayers.Bounds>}143 * zoomChanged - {Boolean}144 * dragging - {Boolean}145 */146 moveTo:function(bounds, zoomChanged, dragging) {147 if (!this.doneLoading) {148 this.events.triggerEvent("loadcancel");149 this.doneLoading = true;150 }151 OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this,arguments);152 153 if (bounds == null) {154 bounds = this.map.getExtent();155 }156 157 var firstRendering = (this.tile == null);158 159 //does the new bounds to which we need to move fall outside of the160 // current tile's bounds?161 var outOfBounds = (!firstRendering &&162 !this.tile.bounds.containsBounds(bounds));163 164 if ( zoomChanged || firstRendering || (!dragging && outOfBounds) ) {165 166 //clear out the old tile167 if (this.tile) {168 this.tile.clear();169 }170 171 //determine new tile bounds172 var center = bounds.getCenterLonLat();173 var tileWidth = bounds.getWidth() * this.ratio;174 var tileHeight = bounds.getHeight() * this.ratio;175 var tileBounds =176 new OpenLayers.Bounds(center.lon - (tileWidth / 2),177 center.lat - (tileHeight / 2),178 center.lon + (tileWidth / 2),179 center.lat + (tileHeight / 2));180 181 //determine new tile size182 this.setTileSize();183 184 //determine new position (upper left corner of new bounds)185 var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top);186 var pos = this.map.getLayerPxFromLonLat(ul);187 188 if ( this.tile && !this.tile.size.equals(this.tileSize)) {189 this.tile.destroy();190 this.tile = null;191 }192 193 this.events.triggerEvent("loadstart");194 this.doneLoading = false;195 if (!this.tile) {196 this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds,197 null, this.tileSize);198 this.tile.draw();199 var onload = function() {200 this.doneLoading = true;201 this.events.triggerEvent("loadend");202 }203 OpenLayers.Event.observe(this.tile.imgDiv, 'load',204 onload.bind(this));205 } else {206 this.tile.moveTo(tileBounds, pos);207 }208 209 }210 },211 212 /**213 * Method: getURL214 *215 * Parameters:216 * bounds - {<OpenLayers.Bounds>}217 */218 getURL: function(bounds) {219 var url = this.getFullRequestString(220 {mapext:bounds.toBBOX().replace(/,/g," "),221 imgext:bounds.toBBOX().replace(/,/g," "),222 map_size: this.tileSize.w + " " + this.tileSize.h,223 imgx: this.tileSize.w / 2,224 imgy: this.tileSize.h / 2,225 imgxy: this.tileSize.w + " " + this.tileSize.h226 });227 return url;228 },229 230 231 /**232 * APIMehod: setUrl233 * Once HTTPRequest has updated the url, reload the image div234 *235 * Parameters:236 * newUrl - {String}237 */238 setUrl: function(newUrl) {239 OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments);240 this.redraw();241 },242 243 /**244 * APIMethod: getFullRequestString245 * combine the layer's url with its params and these newParams.246 *247 * Add the SRS parameter from 'projection' -- this is probably248 * more eloquently done via a setProjection() method, but this249 * works for now and always.250 *251 * Parameters:252 * newParams - {Object}253 */254 getFullRequestString:function(newParams) {255 var projection = this.map.getProjection();256 this.params.srs = (projection == "none") ? null : projection;257 258 return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(259 this, arguments);260 },261 262 /** @final @type String */263 43 CLASS_NAME: "OpenLayers.Layer.MapServer.Untiled" 264 44 }); trunk/openlayers/tests/Layer/test_MapServer.html
r4060 r4068 232 232 } 233 233 234 function test_30_Layer_MapServer_singleTile (t) { 235 t.plan( 5 ); 236 var map = new OpenLayers.Map('map'); 237 layer = new OpenLayers.Layer.MapServer(name, url, params, {singleTile: true}); 238 map.addLayer(layer); 239 map.setCenter(new OpenLayers.LonLat(0,0),5); 240 t.eq( layer.singleTile, true, "layer has singleTile property, great!" ); 241 t.eq( layer.grid.length, 1, "Grid has only a single row, good enough!" ); 242 t.eq( layer.grid[0].length, 1, "Grid has only a single column, good enough!" ); 243 t.eq( layer.tileSize.w, 750, "Image width is correct" ); 244 t.eq( layer.tileSize.h, 825, "Image height is correct" ); 245 } 246 247 248 234 249 function test_99_Layer_MapServer_destroy (t) { 235 250 … … 251 266 t.ok( layer.grid == null, "grid set to null"); 252 267 } 253 254 268 269 // Untiled tests 270 271 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1); 272 var layer; 273 274 var name = 'Test Layer'; 275 var url = "http://labs.metacarta.com/cgi-bin/mapserv"; 276 var params = { map: '/mapdata/vmap_wms.map', 277 layers: 'basic'}; 278 279 function test_01_Layer_MapServer_Untiled_constructor (t) { 280 t.plan( 4 ); 281 282 var url = "http://labs.metacarta.com/cgi-bin/mapserv"; 283 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params); 284 t.ok( layer instanceof OpenLayers.Layer.MapServer.Untiled, "new OpenLayers.Layer.MapServer returns object" ); 285 t.eq( layer.url, "http://labs.metacarta.com/cgi-bin/mapserv", "layer.url is correct (HTTPRequest inited)" ); 286 287 t.eq( layer.params.mode, "map", "default mode param correctly copied"); 288 t.eq( layer.params.map_imagetype, "png", "default imagetype correctly copied"); 289 290 291 } 292 293 function test_04_Layer_MapServer_Untiled_clone (t) { 294 t.plan(3); 295 296 var url = "http://labs.metacarta.com/cgi-bin/mapserv"; 297 var map = new OpenLayers.Map('map', {}); 298 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params); 299 map.addLayer(layer); 300 301 var clone = layer.clone(); 302 layer.tile = [[1,2],[3,4]]; 303 304 t.ok( clone.tile != layer.tile, "clone does not copy tile"); 305 306 layer.ratio += 1; 307 308 t.eq( clone.ratio, 1.5, "changing layer.ratio does not change clone.ratio -- a fresh copy was made, not just copied reference"); 309 310 t.eq( clone.alpha, layer.alpha, "alpha copied correctly"); 311 312 layer.tile = null; 313 } 314 315 function test_05_Layer_MapServer_Untiled_isBaseLayer(t) { 316 t.plan(3); 317 318 var url = "http://labs.metacarta.com/cgi-bin/mapserv"; 319 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params); 320 t.ok( layer.isBaseLayer, "baselayer is true by default"); 321 322 var newParams = OpenLayers.Util.extend({}, params); 323 newParams.transparent = "true"; 324 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, newParams); 325 t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true"); 326 327 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params, {isBaseLayer: false}); 328 t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" ); 329 } 330 331 function test_06_Layer_MapServer_Untiled_mergeNewParams (t) { 332 t.plan( 5 ); 333 334 var map = new OpenLayers.Map("map"); 335 var url = "http://labs.metacarta.com/cgi-bin/mapserv"; 336 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params); 337 338 var newParams = { layers: 'sooper', 339 chickpeas: 'image/png'}; 340 341 map.addLayer(layer); 342 map.zoomToMaxExtent(); 343 t.ok( !layer.grid[0][0].url.match("chickpeas"), "chickpeas is not in URL of first tile in grid" ); 344 345 layer.mergeNewParams(newParams); 346 347 t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well"); 348 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well"); 349 t.ok( layer.grid[0][0].url.match("chickpeas"), "chickpeas is in URL of first tile in grid" ); 350 351 newParams.chickpeas = 151; 352 353 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable"); 354 } 355 356 function test_07_Layer_MapServer_Untiled_getFullRequestString (t) { 357 358 359 t.plan( 1 ); 360 var map = new OpenLayers.Map('map'); 361 tUrl = "http://labs.metacarta.com/cgi-bin/mapserv"; 362 tParams = { layers: 'basic', 363 format: 'png'}; 364 var tLayer = new OpenLayers.Layer.MapServer.Untiled(name, tUrl, tParams); 365 map.addLayer(tLayer); 366 str = tLayer.getFullRequestString(); 367 var tParams = { 368 layers: 'basic', 369 format: 'png', 370 mode: 'map', 371 map_imagetype: 'png' 372 }; 373 374 var sStr = tUrl + "?" + OpenLayers.Util.getParameterString(tParams); 375 sStr = sStr.replace(/,/g, "+"); 376 377 t.eq(str, sStr , "getFullRequestString() works"); 378 379 } 380 381 function test_08_Layer_MapServer_Untiled_setOpacity (t) { 382 t.plan( 4 ); 383 384 var map = new OpenLayers.Map('map'); 385 map.projection = "xx"; 386 tUrl = "http://labs.metacarta.com/cgi-bin/mapserv"; 387 tParams = { layers: 'basic', 388 format: 'image/png'}; 389 tOptions = { 'opacity': '0.5' }; 390 var tLayer = new OpenLayers.Layer.MapServer.Untiled(name, tUrl, tParams, tOptions); 391 map.addLayer(tLayer); 392 map.zoomToMaxExtent(); 393 t.eq(tLayer.opacity, "0.5", "Opacity is set correctly"); 394 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.5, "Opacity on tile is correct"); 395 tLayer.setOpacity("0.6"); 396 t.eq(tLayer.opacity, "0.6", "setOpacity works properly"); 397 t.eq(parseFloat(tLayer.div.firstChild.firstChild.style.opacity), 0.6, "Opacity on tile is changed correctly"); 398 399 } 400 401 function test_99_Layer_MapServer_Untiled_destroy (t) { 402 403 t.plan( 1 ); 404 405 var map = new OpenLayers.Map('map'); 406 layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params); 407 map.addLayer(layer); 408 409 map.setCenter(new OpenLayers.LonLat(0,0), 5); 410 411 //grab a reference to one of the tiles 412 var tile = layer.tile; 413 414 layer.destroy(); 415 416 // checks to make sure superclass (grid) destroy() was called 417 418 t.ok( layer.tile == null, "tile set to null"); 419 } 420 421 // --> 255 422 </script> 256 423 </head> trunk/openlayers/tests/list-tests.html
r4042 r4068 48 48 <li>Layer/test_MultiMap.html</li> 49 49 <li>Layer/test_MapServer.html</li> 50 <li>Layer/test_MapServer_Untiled.html</li>51 50 <li>Layer/test_Text.html</li> 52 51 <li>Layer/test_WMS.html</li>
