Ticket #995: mapguide.patch
| File mapguide.patch, 30.3 kB (added by madair, 1 year ago) |
|---|
-
examples/mapguide.html
old new 1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <style type="text/css"> 4 #map { 5 width: 800px; 6 height: 800px; 7 border: 1px solid black; 8 } 9 </style> 10 <script src="../lib/OpenLayers.js"></script> 11 <script type="text/javascript"> 12 13 var map, layer; 14 var url = "http://demo01.dmsolutions.ca/mapguide/mapagent/mapagent.fcgi"; 15 //var url = "/mapguide/mapagent/mapagent.fcgi"; 16 17 //tiled version 18 function init(){ 19 20 OpenLayers.DOTS_PER_INCH = 96; 21 var extent = new OpenLayers.Bounds(-3631568.75,-1293815.5,4491139.5833333321,4937122); 22 var tempScales = [50000000,23207944.16806,10772173.45016,5000000,2320794.41681,1077217.34502,500000,232079.44168,107721.7345,50000]; 23 var mapOptions = { 24 maxExtent: extent, 25 scales: tempScales, 26 units: 'm', 27 projection: 'EPSG:42304' 28 }; 29 map = new OpenLayers.Map( 'map', mapOptions ); 30 map.addControl( new OpenLayers.Control.LayerSwitcher() ); 31 32 var options = { 33 mapDefinition: 'Library://Samples/Gmap/Maps/gmapTiled.MapDefinition', 34 groupName: "BaseLayerGroup", 35 buffer:1, 36 singleTile: false, 37 } 38 var layer = new OpenLayers.Layer.MapGuide( "MapGuide OS tiled layer", url, options ); 39 map.addLayer(layer); 40 41 map.zoomToMaxExtent(); 42 } 43 44 //un-tiled version 45 function initUntiled() { 46 47 OpenLayers.DOTS_PER_INCH = 96; 48 var extent = new OpenLayers.Bounds(-87.865114442365922,43.665065564837931,-87.595394059497067,43.823852564430069); 49 var mapOptions = { 50 maxExtent: extent, 51 maxResolution: 'auto' 52 }; 53 map = new OpenLayers.Map( 'map', mapOptions ); 54 map.addControl( new OpenLayers.Control.LayerSwitcher() ); 55 56 var options = { 57 mapDefinition: 'Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition', 58 buffer: 1, 59 singleTile: true 60 }; 61 var layer = new OpenLayers.Layer.MapGuide( "MapGuide OS untiled baselayer", url, options ); 62 map.addLayer(layer); 63 64 //this is how to set up the layer for transparent overlays. Requires a valid session ID 65 //and mapName stored in that session. 66 //If the mapagent URL is on a different server than this OL layer, the OpenLayers proxy script 67 //must be used since this layer must perform an additional AJAX request before requesting the 68 //map image 69 var options = { 70 isBaseLayer: false, 71 transparent: true, 72 mapName: 'Sheboygan', 73 session: '0b8cb80e-0000-1000-8003-0017a4e6ff5d_en_C0A802AD0AFC0AFB0AFA', 74 buffer: 1, 75 singleTile: true 76 }; 77 layer = new OpenLayers.Layer.MapGuide( "MapGuide OS Overlay layer", url, options ); 78 //map.addLayer(layer); 79 80 map.zoomToMaxExtent(); 81 } 82 </script> 83 </head> 84 <body onload="initUntiled()"> 85 <p>If prompted for a password, username is Anonymous and an empty password</p> 86 <div id="map"></div> 87 </body> 88 </html> -
lib/OpenLayers.js
old new 102 102 "OpenLayers/Layer/Yahoo.js", 103 103 "OpenLayers/Layer/HTTPRequest.js", 104 104 "OpenLayers/Layer/Grid.js", 105 "OpenLayers/Layer/MapGuide.js", 105 106 "OpenLayers/Layer/MapServer.js", 106 107 "OpenLayers/Layer/MapServer/Untiled.js", 107 108 "OpenLayers/Layer/KaMap.js", -
lib/OpenLayers/Layer/Grid.js
old new 60 60 numLoadingTiles: 0, 61 61 62 62 /** 63 * APIProperty: gridOrigin 64 * {String} where to start the 0,0 tile for the grid 65 */ 66 gridOrigin: 'lowerLeft', 67 68 /** 63 69 * Constructor: OpenLayers.Layer.Grid 64 70 * Create a new grid layer 65 71 * … … 327 333 var tileoffsetx = -tilecolremain * this.tileSize.w; 328 334 var tileoffsetlon = extent.left + tilecol * tilelon; 329 335 330 var offsetlat = bounds.top - (extent.bottom + tilelat); 331 var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer; 332 var tilerowremain = tilerow - offsetlat/tilelat; 333 var tileoffsety = -tilerowremain * this.tileSize.h; 334 var tileoffsetlat = extent.bottom + tilerow * tilelat; 336 var offsetlat, tilerow, tilerowremain, tileoffsety, tileoffsetlat; 337 if (this.gridOrigin == 'upperLeft') { 338 offsetlat = extent.top - bounds.top + tilelat; 339 tilerow = Math.floor(offsetlat/tilelat) - this.buffer; 340 tilerowremain = tilerow - offsetlat/tilelat; 341 tileoffsety = tilerowremain * this.tileSize.h; 342 tileoffsetlat = extent.top - tilelat*tilerow; 343 } else { //default lower left 344 offsetlat = bounds.top - (extent.bottom + tilelat); 345 tilerow = Math.ceil(offsetlat/tilelat) + this.buffer; 346 tilerowremain = tilerow - offsetlat/tilelat; 347 tileoffsety = -tilerowremain * this.tileSize.h; 348 tileoffsetlat = extent.bottom + tilerow * tilelat; 349 } 335 350 336 351 tileoffsetx = Math.round(tileoffsetx); // heaven help us 337 352 tileoffsety = Math.round(tileoffsety); -
lib/OpenLayers/Layer/MapGuide.js
old new 1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD 2 * licence. See http://svn.openlayers.org/trunk/openlayers/license.txt for the 3 * full text of the license. */ 4 5 /** 6 * @requires OpenLayers/Ajax.js 7 * @requires OpenLayers/Layer/Grid.js 8 * 9 * Class: OpenLayers.Layer.MapGuide 10 * Instances of OpenLayers.Layer.MapGuide are used to display 11 * data from a MapGuide OS instance. 12 * 13 * Inherits from: 14 * - <OpenLayers.Layer.Grid> 15 */ 16 OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, { 17 18 /** 19 * APIProperty: isBaseLayer 20 * {Boolean} Treat this layer as a base layer. Default is true. 21 **/ 22 isBaseLayer: true, 23 24 /** 25 * APIProperty: singleTile 26 * {Boolean} use tile server or request single tile image 27 **/ 28 singleTile: true, 29 30 /** 31 * Constant: TILE_PARAMS 32 * {Object} Hashtable of default parameter key/value pairs for tiled layer 33 */ 34 TILE_PARAMS: { 35 operation: 'GETTILEIMAGE', 36 version: '1.2.0' 37 }, 38 39 /** 40 * Constant: SINGLE_TILE_PARAMS 41 * {Object} Hashtable of default parameter key/value pairs for untiled layer 42 */ 43 SINGLE_TILE_PARAMS: { 44 operation: 'GETMAPIMAGE', 45 version: '1.0.0' 46 }, 47 48 /** 49 * APIProperty: session 50 * {String} MapGuide session ID 51 * (for untiled overlays layers only) 52 **/ 53 session: null, 54 55 /** 56 * APIProperty: mapName 57 * {String} Name of the map as stored in the MapGuide session. 58 * (for untiled overlay layers only) 59 **/ 60 mapName: null, 61 62 /** 63 * APIProperty: mapDefinition 64 * {String} The MapGuide resource definition 65 * (e.g. Library://Samples/Gmap/Maps/gmapTiled.MapDefinition) 66 **/ 67 mapDefinition: null, 68 69 /** 70 * APIProperty: groupName 71 * {String} GroupName for tiled MapGuide layers 72 **/ 73 groupName: null, 74 75 /** 76 * APIProperty: format 77 * {String} Image format to be returned (for untiled overlay layers only) 78 **/ 79 format: 'PNG', 80 81 /** 82 * APIProperty: locale 83 * {String} Locale setting 84 * (for untiled overlays layers only) 85 **/ 86 locale: "en", 87 88 /** 89 * APIProperty: showLayers 90 * {String} A comma separated list of GUID's for the layers to display 91 * eg: 'cvc-xcv34,453-345-345sdf' 92 * This only works with runtime maps, and some server plumbing is required to read these values. 93 */ 94 showLayers: null, 95 96 /** 97 * APIProperty: hideLayers 98 * {String} A comma separated list of GUID's for the layers to hide 99 * eg: 'cvc-xcv34,453-345-345sdf' 100 * This only works with runtime maps, and some server plumbing is required to read these values. 101 */ 102 hideLayers: null, 103 104 /** 105 * APIProperty: showGroups 106 * {String} A comma separated list of GUID's for the groups to display 107 * eg: 'cvc-xcv34,453-345-345sdf' 108 * This only works with runtime maps, and some server plumbing is required to read these values. 109 */ 110 showGroups: null, 111 112 /** 113 * APIProperty: hideGroups 114 * {String} A comma separated list of GUID's for the groups to hide 115 * eg: 'cvc-xcv34,453-345-345sdf' 116 * This only works with runtime maps, and some server plumbing is required to read these values. 117 */ 118 hideGroups: null, 119 120 /** 121 * APIProperty: selectionXml 122 * {String} A selection xml string 123 * Some server plumbing is required to read such a value. 124 */ 125 selectionXml: null, 126 127 /** 128 * APIProperty: defaultSize 129 * {<OpenLayers.Size>} Tile size as produced by MapGuide server 130 **/ 131 defaultSize: new OpenLayers.Size(300,300), 132 133 /** 134 * Constructor: OpenLayers.Layer.MapGuide 135 * Create a new Mapguide layer, either tiled or untiled. 136 * 137 * For tiled layers, the 'groupName' and 'mapDefnition' options 138 * must be specified as options. 139 * 140 * For untiled layers, specify either combination of 'mapName' and 'session', 141 * or 'mapDefinition' and 'locale'. 142 * 143 * The following parameters are typically set on a per request basis using 144 * mergeNewParams (or similar), but may also be specified once for the layer: 145 * 'showLayers', 'hideLayers', 'showGroups', 'hideGroups', 'selectionXml' 146 * 147 * Parameters: 148 * name - {String} Name of the layer displayed in the interface 149 * url - {String} Location of the MapGuide mapagent executable 150 (e.g. http://localhost:8008/mapguide/mapagent/mapagent.fcgi) 151 * options - {Ojbect} Hashtable of extra options to tag onto the layer; 152 * will vary depending if tiled or untiled maps are being requested 153 */ 154 initialize: function(name, url, options) { 155 156 var newArguments = new Array(); 157 newArguments.push(name, url, {}, options); 158 OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); 159 160 // unless explicitly set in options, if the layer is transparent, 161 // it will be an overlay 162 if (options == null || options.isBaseLayer == null) { 163 this.isBaseLayer = ((this.transparent != "true") && 164 (this.transparent != true)); 165 } 166 167 //initialize for untiled layers 168 if (this.singleTile) { 169 if (this.session && this.mapName) { 170 this.params.session = this.session; 171 this.params.mapName = this.mapName; 172 } else if (this.mapDefinition) { 173 this.params.mapDefinition = this.mapDefinition; 174 this.params.locale = this.locale; 175 } 176 this.params.format = this.format; 177 178 /* these may also be set as parameters on a per request basis in the params argument */ 179 if (this.showLayers) { 180 this.params.showLayers = this.showLayers; 181 } 182 if (this.hideLayers) { 183 this.params.hideLayers = this.hideLayers; 184 } 185 if (this.showGroups) { 186 this.params.showGroups = this.showGroups; 187 } 188 if (this.hideGroups) { 189 this.params.hideGroups = this.hideGroups; 190 } 191 if (this.refreshLayers) { 192 this.params.refreshLayers = this.refreshLayers; 193 } 194 if (this.selectionXml) { 195 this.params.selectionXml = this.selectionXml; 196 } 197 198 OpenLayers.Util.applyDefaults( 199 this.params, 200 this.SINGLE_TILE_PARAMS 201 ); 202 } else { 203 //initialize for tiled layers 204 this.params.mapDefinition = this.mapDefinition; 205 this.params.basemaplayergroupname = this.groupName; 206 OpenLayers.Util.applyDefaults( 207 this.params, 208 this.TILE_PARAMS 209 ); 210 this.setTileSize(this.defaultSize); 211 this.gridOrigin = 'upperLeft'; 212 } 213 }, 214 215 /** 216 * Method: clone 217 * Create a clone of this layer 218 * 219 * Returns: 220 * {<OpenLayers.Layer.MapGuide>} An exact clone of this layer 221 */ 222 clone: function (obj) { 223 if (obj == null) { 224 obj = new OpenLayers.Layer.MapGuide(this.name, 225 this.url, 226 this.params, 227 this.options); 228 } 229 //get all additions from superclasses 230 obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); 231 232 // copy/set any non-init, non-simple values here 233 234 return obj; 235 }, 236 237 /** 238 * Method: addTile 239 * Creates a tile, initializes it, and adds it to the layer div. 240 * 241 * Parameters: 242 * bounds - {<OpenLayers.Bounds>} 243 * 244 * Returns: 245 * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image 246 */ 247 addTile:function(bounds,position) { 248 return new OpenLayers.Tile.Image(this, position, bounds, null, this.tileSize); 249 }, 250 251 /** 252 * Method: getURL 253 * Return a query string for this layer 254 * 255 * Parameters: 256 * bounds - {<OpenLayers.Bounds>} A bounds representing the bbox 257 * for the request 258 * 259 * Returns: 260 * {String} A string with the layer's url and parameters and also 261 * the passed-in bounds and appropriate tile size specified 262 * as parameters. 263 */ 264 getURL: function (bounds) { 265 var url; 266 var center = bounds.getCenterLonLat(); 267 var mapSize = this.map.getCurrentSize(); 268 269 if (this.singleTile) { 270 //set up the call for GETMAPIMAGE or GETDYNAMICMAPOVERLAY 271 var params = {}; 272 params.setdisplaydpi = OpenLayers.DOTS_PER_INCH; 273 params.setdisplayheight = mapSize.h*this.ratio; 274 params.setdisplaywidth = mapSize.w*this.ratio; 275 params.setviewcenterx = center.lon; 276 params.setviewcentery = center.lat; 277 params.setviewscale = this.map.getScale(); 278 279 if (!this.isBaseLayer) { 280 // in this case the main image operation is remapped to this 281 this.params.operation = "GETDYNAMICMAPOVERLAYIMAGE"; 282 283 //but we first need to call GETVISIBLEMAPEXTENT to set the extent 284 var getVisParams = {}; 285 getVisParams.operation = "GETVISIBLEMAPEXTENT"; 286 getVisParams.version = "1.0.0"; 287 getVisParams.session = this.session; 288 getVisParams.mapName = this.mapName; 289 getVisParams.format = 'text/xml'; 290 getVisParams = OpenLayers.Util.extend(getVisParams, params); 291 292 new OpenLayers.Ajax.Request(this.url, 293 { parameters: getVisParams, 294 method: 'get', 295 asynchronous: false //must be synchronous call to return control here 296 }); 297 } 298 299 //construct the full URL 300 url = this.getFullRequestString( params ); 301 } else { 302 303 //tiled version 304 var currentRes = this.map.getResolution(); 305 var colidx = Math.floor((bounds.left-this.maxExtent.left)/currentRes); 306 colidx = Math.round(colidx/this.tileSize.w); 307 var rowidx = Math.floor((this.maxExtent.top-bounds.top)/currentRes); 308 rowidx = Math.round(rowidx/this.tileSize.h); 309 310 url = this.getFullRequestString( 311 { 312 tilecol: colidx, 313 tilerow: rowidx, 314 scaleindex: this.resolutions.length-this.map.zoom-1 315 }); 316 } 317 318 return url; 319 }, 320 321 /** 322 * Method: getFullRequestString 323 * getFullRequestString on MapGuide layers is special, because we 324 * do a regular expression replace on ',' in parameters to '+'. 325 * This is why it is subclassed here. 326 * 327 * Parameters: 328 * newParams - {Object} newParams Parameters to add to the default parameters 329 * for the layer. 330 * altUrl - {String} Alternative base URL to use. 331 * 332 * Returns: 333 * {String} A string with the layer's url appropriately encoded for MapGuide 334 */ 335 getFullRequestString:function(newParams, altUrl) { 336 // use layer's url unless altUrl passed in 337 var url = (altUrl == null) ? this.url : altUrl; 338 339 // if url is not a string, it should be an array of strings, 340 // in which case we will randomly select one of them in order 341 // to evenly distribute requests to different urls. 342 if (typeof url == "object") { 343 url = url[Math.floor(Math.random()*url.length)]; 344 } 345 // requestString always starts with url 346 var requestString = url; 347 348 // create a new params hashtable with all the layer params and the 349 // new params together. then convert to string 350 var allParams = OpenLayers.Util.extend({}, this.params); 351 allParams = OpenLayers.Util.extend(allParams, newParams); 352 // ignore parameters that are already in the url search string 353 var urlParams = OpenLayers.Util.upperCaseObject( 354 OpenLayers.Util.getArgs(url)); 355 for(var key in allParams) { 356 if(key.toUpperCase() in urlParams) { 357 delete allParams[key]; 358 } 359 } 360 var paramsString = OpenLayers.Util.getParameterString(allParams); 361 362 /* MapGuide needs '+' seperating things like bounds/height/width. 363 Since typically this is URL encoded, we use a slight hack: we 364 depend on the list-like functionality of getParameterString to 365 leave ',' only in the case of list items (since otherwise it is 366 encoded) then do a regular expression replace on the , characters 367 to '+' */ 368 paramsString = paramsString.replace(/,/g, "+"); 369 370 if (paramsString != "") { 371 var lastServerChar = url.charAt(url.length - 1); 372 if ((lastServerChar == "&") || (lastServerChar == "?")) { 373 requestString += paramsString; 374 } else { 375 if (url.indexOf('?') == -1) { 376 //serverPath has no ? -- add one 377 requestString += '?' + paramsString; 378 } else { 379 //serverPath contains ?, so must already have paramsString at the end 380 requestString += '&' + paramsString; 381 } 382 } 383 } 384 return requestString; 385 }, 386 387 CLASS_NAME: "OpenLayers.Layer.MapGuide" 388 }); -
tests/Layer/test_MapGuide.html
old new 1 <html> 2 <head> 3 <script type="text/javascript">var oldAlert = window.alert, gMess; window.alert = function(message) {gMess = message; return true;};</script> 4 <script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script> 5 <script type="text/javascript">window.alert = oldAlert;</script> 6 <script src="../../lib/OpenLayers.js"></script> 7 <script type="text/javascript"> 8 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1); 9 var layer; 10 11 var name = 'MapGuide Test Layer'; 12 var url = "http://demo01.dmsolutions.ca/mapguide/mapagent/mapagent.fcgi"; 13 var paramsTiled = { 14 mapDefinition: 'Library://Samples/Gmap/Maps/gmapTiled.MapDefinition', 15 groupName: "BaseLayerGroup", 16 singleTile: false 17 } 18 var paramsUntiled = { 19 mapDefinition: 'Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition' 20 }; 21 22 function test_01_Layer_MapGuide_untiled_constructor (t) { 23 t.plan( 8 ); 24 25 var trans_format = "image/png"; 26 if (OpenLayers.Util.alphaHack()) { trans_format = "image/gif"; } 27 28 layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled); 29 t.ok( layer instanceof OpenLayers.Layer.MapGuide, "new OpenLayers.Layer.MapGuide returns object" ); 30 t.eq( layer.url, "http://demo01.dmsolutions.ca/mapguide/mapagent/mapagent.fcgi", "layer.url is correct (HTTPRequest inited)" ); 31 t.eq( layer.params.mapDefinition, "Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition", "params passed in correctly" ); 32 33 t.eq( layer.params.operation, "GETMAPIMAGE", "default params set correctly and copied"); 34 35 t.eq(layer.isBaseLayer, true, "no transparency setting, layer is baselayer"); 36 37 paramsUntiled.transparent = "true"; 38 var layer2 = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled); 39 t.eq(layer2.isBaseLayer, false, "transparency == 'true', wms is not baselayer"); 40 41 paramsUntiled.transparent = true; 42 var layer5 = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled); 43 t.eq(layer5.isBaseLayer, false, "transparency == true, wms is not baselayer"); 44 45 paramsUntiled.transparent = false; 46 var layer6 = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled); 47 t.eq(layer6.isBaseLayer, true, "transparency == false, wms is baselayer"); 48 } 49 50 function test_02_Layer_MapGuide_tiled_constructor (t) { 51 t.plan( 6 ); 52 53 var trans_format = "image/png"; 54 if (OpenLayers.Util.alphaHack()) { trans_format = "image/gif"; } 55 56 layer = new OpenLayers.Layer.MapGuide(name, url, paramsTiled); 57 t.ok( layer instanceof OpenLayers.Layer.MapGuide, "new OpenLayers.Layer.MapGuide returns object" ); 58 t.eq( layer.url, "http://demo01.dmsolutions.ca/mapguide/mapagent/mapagent.fcgi", "layer.url is correct (HTTPRequest inited)" ); 59 t.eq( layer.params.basemaplayergroupname, "BaseLayerGroup", "params passed in correctly" ); 60 61 t.eq( layer.params.operation, "GETTILEIMAGE", "default params correctly uppercased and copied"); 62 t.eq( layer.params.version, "1.2.0", "version params set correctly set"); 63 t.eq( layer.gridOrigin, "upperLeft", "grid origin set correctly set"); 64 } 65 /* 66 function test_Layer_MapGuide_bboxEncoding (t) { 67 t.plan( 6 ); 68 69 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 70 layer = new OpenLayers.Layer.MapGuide(name, url, params, {encodeBBOX:true}); 71 var map = new OpenLayers.Map('map'); 72 map.addLayer(layer); 73 var pixel = new OpenLayers.Pixel(5,6); 74 var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel); 75 tile.draw(); 76 77 var img = tile.imgDiv; 78 var tParams = OpenLayers.Util.extend({}, 79 OpenLayers.Util.upperCaseObject(params)); 80 tParams = OpenLayers.Util.extend(tParams, { 81 SERVICE: "WMS", VERSION: "1.1.1", 82 REQUEST: "GetMap", STYLES: "", 83 EXCEPTIONS: "application/vnd.ogc.se_inimage", 84 SRS: "EPSG:4326", BBOX: "1,2,3,4", 85 WIDTH: "256", HEIGHT: "256" 86 }); 87 t.eq( img.src, 88 url + "?" + OpenLayers.Util.getParameterString(tParams), 89 "image src is created correctly via addtile" ); 90 t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" ); 91 t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" ); 92 93 var firstChild = layer.div.firstChild.firstChild; 94 if (!isMozilla) 95 t.ok( true, "skipping element test outside of Mozilla"); 96 else 97 t.ok( firstChild instanceof HTMLElement, "div first child is an image object" ); 98 t.eq( firstChild.src, 99 url + "?" + OpenLayers.Util.getParameterString(tParams), 100 "div first child is correct image object" ); 101 t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." ); 102 map.destroy(); 103 } 104 */ 105 106 function test_03_Layer_MapGuide_inittiles (t) { 107 t.plan( 2 ); 108 var map = new OpenLayers.Map('map'); 109 layer = new OpenLayers.Layer.MapGuide(name, url, paramsTiled); 110 map.addLayer(layer); 111 map.setCenter(new OpenLayers.LonLat(0,400000),5); 112 t.eq( layer.grid.length, 6, "Grid rows is correct." ); 113 t.eq( layer.grid[0].length, 6, "Grid cols is correct." ); 114 map.destroy(); 115 } 116 117 118 function test_04_Layer_MapGuide_clone (t) { 119 t.plan(4); 120 121 var options = {tileSize: new OpenLayers.Size(500,50)}; 122 var map = new OpenLayers.Map('map', options); 123 layer = new OpenLayers.Layer.MapGuide(name, url, paramsTiled); 124 map.addLayer(layer); 125 126 layer.grid = [ [6, 7], 127 [8, 9]]; 128 129 var clone = layer.clone(); 130 131 t.eq( layer.tileSize.w, 300, "layer.tileSize fixed to 300x300"); 132 t.ok( clone.grid != layer.grid, "clone does not copy grid"); 133 134 t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned"); 135 136 layer.tileSize.w += 40; 137 138 t.eq( clone.alpha, layer.alpha, "alpha copied correctly"); 139 140 layer.grid = null; 141 map.destroy(); 142 } 143 144 function test_05_Layer_MapGuide_isBaseLayer(t) { 145 t.plan(3); 146 147 layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled); 148 t.ok( layer.isBaseLayer, "baselayer is true by default"); 149 150 var newParams = OpenLayers.Util.extend({}, paramsUntiled); 151 newParams.transparent = "true"; 152 layer = new OpenLayers.Layer.MapGuide(name, url, newParams); 153 t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true"); 154 155 newParams = OpenLayers.Util.extend({}, paramsUntiled); 156 newParams.isBaseLayer = false; 157 layer = new OpenLayers.Layer.MapGuide(name, url, newParams); 158 t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" ); 159 } 160 161 function test_06_Layer_MapGuide_mergeNewParams (t) { 162 t.plan( 4 ); 163 164 var map = new OpenLayers.Map("map"); 165 layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled); 166 167 var newParams = { mapDefinition: 'Library://Samples/Gmap/Maps/gmap.MapDefinition', 168 chickpeas: 'image/png'}; 169 170 map.addLayer(layer); 171 map.zoomToMaxExtent(); 172 173 layer.redraw = function() { 174 t.ok(true, "layer is redrawn after new params merged"); 175 } 176 177 layer.mergeNewParams(newParams); 178 179 t.eq( layer.params.mapDefinition, "Library://Samples/Gmap/Maps/gmap.MapDefinition", "mergeNewParams() overwrites well"); 180 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well"); 181 182 newParams.chickpeas = 151; 183 184 t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable"); 185 map.destroy(); 186 } 187 188 /* 189 function test_07_Layer_MapGuide_getFullRequestString (t) { 190 191 192 t.plan( 2 ); 193 var map = new OpenLayers.Map('map'); 194 map.projection = "xx"; 195 tUrl = "http://octo.metacarta.com/cgi-bin/mapserv"; 196 tParams = { layers: 'basic', 197 format: 'image/png'}; 198 var tLayer = new OpenLayers.Layer.MapGuide(name, tUrl, tParams); 199 map.addLayer(tLayer); 200 str = tLayer.getFullRequestString(); 201 var tParams = { 202 LAYERS: "basic", FORMAT: "image/png", SERVICE: "WMS", 203 VERSION: "1.1.1", REQUEST: "GetMap", STYLES: "", 204 EXCEPTIONS: "application/vnd.ogc.se_inimage", SRS: "xx" 205 }; 206 t.eq(str, 207 tUrl + "?" + OpenLayers.Util.getParameterString(tParams), 208 "getFullRequestString() adds SRS value"); 209 210 map.removeLayer(tLayer); 211 tLayer.projection = "none"; 212 map.addLayer(tLayer); 213 str = tLayer.getFullRequestString(); 214 delete tParams['SRS']; 215 t.eq(str, 216 tUrl + "?" + OpenLayers.Util.getParameterString(tParams), 217 "getFullRequestString() by default does *not* add SRS value if projection is 'none'"); 218 map.destroy(); 219 220 }*/ 221 222 function test_99_Layer_MapGuide_destroy (t) { 223 224 t.plan( 1 ); 225 226 var map = new OpenLayers.Map('map'); 227 layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled); 228 map.addLayer(layer); 229 230 map.setCenter(new OpenLayers.LonLat(0,0), 5); 231 232 //grab a reference to one of the tiles 233 var tile = layer.grid[0][0]; 234 235 layer.destroy(); 236 237 // checks to make sure superclass (grid) destroy() was called 238 239 t.ok( layer.grid == null, "grid set to null"); 240 } 241 242 243 </script> 244 </head> 245 <body> 246 <div id="map" style="width:500px;height:550px"></div> 247 </body> 248 </html> -
tests/list-tests.html
old new 58 58 <li>Layer/test_HTTPRequest.html</li> 59 59 <li>Layer/test_Image.html</li> 60 60 <li>Layer/test_KaMap.html</li> 61 <li>Layer/test_MapGuide.html</li> 61 62 <li>Layer/test_MapServer.html</li> 62 63 <li>Layer/test_Markers.html</li> 63 64 <li>Layer/test_MultiMap.html</li>
