OpenLayers OpenLayers

Ticket #995: mapguide.5.patch

File mapguide.5.patch, 29.4 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: 400px; 
     6            height: 400px; 
     7            border: 1px solid black; 
     8            float:left; 
     9        } 
     10        #map2 { 
     11            width: 400px; 
     12            height: 400px; 
     13            border: 1px solid black; 
     14            float:left; 
     15        } 
     16    </style> 
     17    <script src="../lib/OpenLayers.js"></script> 
     18    <script type="text/javascript"> 
     19     
     20        var map, layer; 
     21        var url = "http://demo01.dmsolutions.ca/mapguide/mapagent/mapagent.fcgi"; 
     22        //you can use this URL when MapGuide OS is installed locally 
     23        //var url = "/mapguide/mapagent/mapagent.fcgi"; 
     24         
     25        //tiled version 
     26        function initTiled(){ 
     27         
     28            OpenLayers.DOTS_PER_INCH = 96; 
     29            var extent = new OpenLayers.Bounds(-3631568.75,-1293815.5,4491139.5833333321,4937122); 
     30            var tempScales = [50000000,23207944.16806,10772173.45016,5000000,2320794.41681,1077217.34502,500000,232079.44168,107721.7345,50000]; 
     31            var mapOptions = { 
     32                maxExtent: extent,  
     33                scales: tempScales, 
     34                units: 'm', 
     35                projection: 'EPSG:42304' 
     36            }; 
     37            map = new OpenLayers.Map( 'map', mapOptions ); 
     38             
     39            var params = { 
     40              mapdefinition: 'Library://Samples/Gmap/Maps/gmapTiled.MapDefinition', 
     41              basemaplayergroupname: "BaseLayerGroup" 
     42            } 
     43            var options = { 
     44              singleTile: false  
     45            } 
     46            var layer = new OpenLayers.Layer.MapGuide( "MapGuide OS tiled layer", url, params, options ); 
     47            map.addLayer(layer); 
     48             
     49            map.zoomToMaxExtent(); 
     50        } 
     51 
     52        //un-tiled version 
     53        function initUntiled() { 
     54         
     55          OpenLayers.DOTS_PER_INCH = 96; 
     56          var extent = new OpenLayers.Bounds(-87.865114442365922,43.665065564837931,-87.595394059497067,43.823852564430069); 
     57          var mapOptions = { 
     58                maxExtent: extent,  
     59                maxResolution: 'auto' 
     60          }; 
     61          map = new OpenLayers.Map( 'map2', mapOptions ); 
     62             
     63          var options = { 
     64              buffer: 1, 
     65              singleTile: true 
     66          }; 
     67           
     68          var params = { 
     69              mapdefinition: 'Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition' 
     70          }; 
     71          /* 
     72                    The MapGuide layer can also be created using mapname and session as follows provided there 
     73                    is some wrapper code to obtain a valid session id and mapname 
     74          var params = { 
     75              mapname: 'Sheboygan47b3560bf1071', 
     76              session: '043bb716-0000-1000-8000-0017a4e6ff5d_en_7F0000010AFC0AFB0AFA' 
     77          }; 
     78          */ 
     79          var layer = new OpenLayers.Layer.MapGuide( "MapGuide OS untiled baselayer", url, params, options ); 
     80          map.addLayer(layer); 
     81           
     82          //this is how to set up the layer for transparent overlays.  Requires a valid session ID  
     83          //and mapName stored in that session. 
     84          //If the mapagent URL is on a different server than this OL layer, the OpenLayers proxy script 
     85          //must be used since this layer must perform an additional AJAX request before requesting the 
     86          //map  image 
     87          /*  
     88            var options = { 
     89              isBaseLayer: false, 
     90              transparent: true, 
     91              buffer: 1, 
     92              singleTile: true 
     93            }; 
     94            var params = { 
     95              mapName: 'Sheboygan', 
     96              session: '0b8cb80e-0000-1000-8003-0017a4e6ff5d_en_C0A802AD0AFC0AFB0AFA', 
     97            }; 
     98            layer = new OpenLayers.Layer.MapGuide( "MapGuide OS Overlay layer", url, params, options ); 
     99            map.addLayer(layer); 
     100          */  
     101          map.zoomToMaxExtent(); 
     102    } 
     103    </script> 
     104  </head> 
     105  <body onload="initUntiled(); initTiled()"> 
     106    <p>If prompted for a password, username is Anonymous and an empty password</p> 
     107    <div id="map"></div> 
     108    <div id="map2"></div> 
     109  </body> 
     110</html> 
  • lib/OpenLayers.js

    old new  
    103103            "OpenLayers/Layer/Yahoo.js", 
    104104            "OpenLayers/Layer/HTTPRequest.js", 
    105105            "OpenLayers/Layer/Grid.js", 
     106            "OpenLayers/Layer/MapGuide.js", 
    106107            "OpenLayers/Layer/MapServer.js", 
    107108            "OpenLayers/Layer/MapServer/Untiled.js", 
    108109            "OpenLayers/Layer/KaMap.js", 
  • 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 */ 
     16OpenLayers.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. Note that using 
     27     *    singleTile *and* isBaseLayer false is *not recommend*: it uses synchronous 
     28     *    XMLHttpRequests to load tiles, and this will *lock up users browsers* 
     29     *    during requests. 
     30     **/ 
     31    singleTile: false, 
     32     
     33    /** 
     34     * Constant: TILE_PARAMS 
     35     * {Object} Hashtable of default parameter key/value pairs for tiled layer 
     36     */ 
     37    TILE_PARAMS: { 
     38         operation: 'GETTILEIMAGE', 
     39         version: '1.2.0' 
     40    }, 
     41 
     42    /** 
     43     * Constant: SINGLE_TILE_PARAMS 
     44     * {Object} Hashtable of default parameter key/value pairs for untiled layer 
     45     */ 
     46    SINGLE_TILE_PARAMS: { 
     47        operation: 'GETMAPIMAGE', 
     48        format: 'PNG', 
     49        locale: 'en', 
     50        version: '1.0.0' 
     51    }, 
     52     
     53    /**  
     54     * Property: defaultSize 
     55     * {<OpenLayers.Size>} Tile size as produced by MapGuide server 
     56     **/ 
     57    defaultSize: new OpenLayers.Size(300,300), 
     58 
     59    /** 
     60     * Constructor: OpenLayers.Layer.MapGuide 
     61     * Create a new Mapguide layer, either tiled or untiled.   
     62     * 
     63     * For tiled layers, the 'groupName' and 'mapDefnition' options  
     64     * must be specified as options. 
     65     * 
     66     * For untiled layers, specify either combination of 'mapName' and 
     67     * 'session', or 'mapDefinition' and 'locale'. 
     68     * 
     69     * Parameters: 
     70     * name - {String} Name of the layer displayed in the interface 
     71     * url - {String} Location of the MapGuide mapagent executable 
     72     *            (e.g. http://localhost:8008/mapguide/mapagent/mapagent.fcgi) 
     73     * params - {Object} hashtable of additional parameters to use. Some 
     74     *     parameters may require additional code on the serer. The ones that 
     75     *     you may want to use are:  
     76     *   - mapDefinition - {String} The MapGuide resource definition 
     77     *            (e.g. Library://Samples/Gmap/Maps/gmapTiled.MapDefinition) 
     78     *   - locale - Locale setting  
     79     *            (for untiled overlays layers only) 
     80     *   - mapName - {String} Name of the map as stored in the MapGuide session. 
     81     *          (for untiled layers with a session parameter only) 
     82     *   - session - { String} MapGuide session ID  
     83     *            (for untiled overlays layers only) 
     84     *   - basemaplayergroupname - {String} GroupName for tiled MapGuide layers only 
     85     *   - format - Image format to be returned (for untiled overlay layers only) 
     86     *   - showLayers - {String} A comma separated list of GUID's for the 
     87     *       layers to display eg: 'cvc-xcv34,453-345-345sdf'. 
     88     *   - hideLayers - {String} A comma separated list of GUID's for the 
     89     *       layers to hide eg: 'cvc-xcv34,453-345-345sdf'. 
     90     *   - showGroups - {String} A comma separated list of GUID's for the 
     91     *       groups to display eg: 'cvc-xcv34,453-345-345sdf'. 
     92     *   - hideGroups - {String} A comma separated list of GUID's for the 
     93     *       groups to hide eg: 'cvc-xcv34,453-345-345sdf' 
     94     *   - selectionXml - {String} A selection xml string Some server plumbing 
     95     *       is required to read such a value. 
     96     * options - {Ojbect} Hashtable of extra options to tag onto the layer;  
     97     *          will vary depending if tiled or untiled maps are being requested 
     98     */ 
     99    initialize: function(name, url, params, options) { 
     100         
     101        OpenLayers.Layer.Grid.prototype.initialize.apply(this, arguments); 
     102         
     103        // unless explicitly set in options, if the layer is transparent,  
     104        // it will be an overlay 
     105        if (options == null || options.isBaseLayer == null) { 
     106            this.isBaseLayer = ((this.transparent != "true") &&  
     107                                (this.transparent != true)); 
     108        } 
     109 
     110        //initialize for untiled layers 
     111        if (this.singleTile) { 
     112            OpenLayers.Util.applyDefaults( 
     113                           this.params, 
     114                           this.SINGLE_TILE_PARAMS 
     115                           ); 
     116        } else { 
     117            //initialize for tiled layers 
     118            OpenLayers.Util.applyDefaults( 
     119                           this.params, 
     120                           this.TILE_PARAMS 
     121                           ); 
     122            this.setTileSize(this.defaultSize);  
     123        } 
     124    }, 
     125 
     126    /** 
     127     * Method: clone 
     128     * Create a clone of this layer 
     129     * 
     130     * Returns: 
     131     * {<OpenLayers.Layer.MapGuide>} An exact clone of this layer 
     132     */ 
     133    clone: function (obj) { 
     134      if (obj == null) { 
     135            obj = new OpenLayers.Layer.MapGuide(this.name, 
     136                                           this.url, 
     137                                           this.params, 
     138                                           this.options); 
     139      } 
     140      //get all additions from superclasses 
     141      obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); 
     142 
     143      return obj; 
     144    }, 
     145 
     146    /** 
     147     * Method: addTile 
     148     * Creates a tile, initializes it, and adds it to the layer div.  
     149     * 
     150     * Parameters: 
     151     * bounds - {<OpenLayers.Bounds>} 
     152     *  
     153     * Returns: 
     154     * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image 
     155     */ 
     156    addTile:function(bounds,position) { 
     157        return new OpenLayers.Tile.Image(this, position, bounds,  
     158                                         null, this.tileSize); 
     159    }, 
     160 
     161    /** 
     162     * Method: getURL 
     163     * Return a query string for this layer 
     164     * 
     165     * Parameters: 
     166     * bounds - {<OpenLayers.Bounds>} A bounds representing the bbox  
     167     *                                for the request 
     168     * 
     169     * Returns: 
     170     * {String} A string with the layer's url and parameters and also  
     171     *          the passed-in bounds and appropriate tile size specified  
     172     *          as parameters. 
     173     */ 
     174    getURL: function (bounds) { 
     175        var url; 
     176        var center = bounds.getCenterLonLat(); 
     177        var mapSize = this.map.getCurrentSize(); 
     178 
     179        if (this.singleTile) { 
     180          //set up the call for GETMAPIMAGE or GETDYNAMICMAPOVERLAY 
     181          var params = {}; 
     182          params.setdisplaydpi = OpenLayers.DOTS_PER_INCH;    
     183          params.setdisplayheight = mapSize.h*this.ratio; 
     184          params.setdisplaywidth = mapSize.w*this.ratio; 
     185          params.setviewcenterx = center.lon; 
     186          params.setviewcentery = center.lat; 
     187          params.setviewscale = this.map.getScale(); 
     188           
     189          if (!this.isBaseLayer) { 
     190            // in this case the main image operation is remapped to this 
     191            this.params.operation = "GETDYNAMICMAPOVERLAYIMAGE"; 
     192             
     193            //but we first need to call GETVISIBLEMAPEXTENT to set the extent 
     194            var getVisParams = {}; 
     195            getVisParams.operation = "GETVISIBLEMAPEXTENT"; 
     196            getVisParams.version = "1.0.0"; 
     197            getVisParams.session = this.params.session; 
     198            getVisParams.mapName = this.params.mapName; 
     199            getVisParams.format = 'text/xml'; 
     200            getVisParams = OpenLayers.Util.extend(getVisParams, params); 
     201                 
     202            new OpenLayers.Ajax.Request(this.url,  
     203                  { parameters: getVisParams, 
     204                    method: 'get', 
     205                    asynchronous: false   //must be synchronous call to return control here 
     206                  }); 
     207          } 
     208           
     209          //construct the full URL 
     210          url = this.getFullRequestString( params ); 
     211        } else { 
     212 
     213          //tiled version 
     214          var currentRes = this.map.getResolution(); 
     215          var colidx = Math.floor((bounds.left-this.maxExtent.left)/currentRes); 
     216          colidx = Math.round(colidx/this.tileSize.w); 
     217          var rowidx = Math.floor((this.maxExtent.top-bounds.top)/currentRes); 
     218          rowidx = Math.round(rowidx/this.tileSize.h); 
     219 
     220          url = this.getFullRequestString( 
     221                       { 
     222                           tilecol: colidx, 
     223                           tilerow: rowidx, 
     224                           scaleindex: this.resolutions.length - this.map.zoom - 1 
     225                        }); 
     226         } 
     227         
     228        return url; 
     229    }, 
     230 
     231    /** 
     232     * Method: getFullRequestString 
     233     * getFullRequestString on MapGuide layers is special, because we  
     234     * do a regular expression replace on ',' in parameters to '+'. 
     235     * This is why it is subclassed here. 
     236     * 
     237     * Parameters: 
     238     * altUrl - {String} Alternative base URL to use. 
     239     * 
     240     * Returns: 
     241     * {String} A string with the layer's url appropriately encoded for MapGuide 
     242     */ 
     243    getFullRequestString:function(newParams, altUrl) { 
     244        // use layer's url unless altUrl passed in 
     245        var url = (altUrl == null) ? this.url : altUrl; 
     246         
     247        // if url is not a string, it should be an array of strings,  
     248        //  in which case we will randomly select one of them in order 
     249        //  to evenly distribute requests to different urls. 
     250        if (typeof url == "object") { 
     251            url = url[Math.floor(Math.random()*url.length)]; 
     252        }    
     253        // requestString always starts with url 
     254        var requestString = url;         
     255 
     256        // create a new params hashtable with all the layer params and the  
     257        // new params together. then convert to string 
     258        var allParams = OpenLayers.Util.extend({}, this.params); 
     259        allParams = OpenLayers.Util.extend(allParams, newParams); 
     260        // ignore parameters that are already in the url search string 
     261        var urlParams = OpenLayers.Util.upperCaseObject( 
     262                            OpenLayers.Util.getArgs(url)); 
     263        for(var key in allParams) { 
     264            if(key.toUpperCase() in urlParams) { 
     265                delete allParams[key]; 
     266            } 
     267        } 
     268        var paramsString = OpenLayers.Util.getParameterString(allParams); 
     269         
     270        /* MapGuide needs '+' seperating things like bounds/height/width. 
     271           Since typically this is URL encoded, we use a slight hack: we 
     272           depend on the list-like functionality of getParameterString to 
     273           leave ',' only in the case of list items (since otherwise it is 
     274           encoded) then do a regular expression replace on the , characters 
     275           to '+' */ 
     276        paramsString = paramsString.replace(/,/g, "+"); 
     277         
     278        if (paramsString != "") { 
     279            var lastServerChar = url.charAt(url.length - 1); 
     280            if ((lastServerChar == "&") || (lastServerChar == "?")) { 
     281                requestString += paramsString; 
     282            } else { 
     283                if (url.indexOf('?') == -1) { 
     284                    //serverPath has no ? -- add one 
     285                    requestString += '?' + paramsString; 
     286                } else { 
     287                    //serverPath contains ?, so must already have paramsString at the end 
     288                    requestString += '&' + paramsString; 
     289                } 
     290            } 
     291        } 
     292        return requestString; 
     293    }, 
     294 
     295    /**  
     296     * Method: calculateGridLayout 
     297     * Generate parameters for the grid layout. This   
     298     * 
     299     * Parameters: 
     300     * bounds - {<OpenLayers.Bound>} 
     301     * extent - {<OpenLayers.Bounds>} 
     302     * resolution - {Number} 
     303     * 
     304     * Returns: 
     305     * Object containing properties tilelon, tilelat, tileoffsetlat, 
     306     * tileoffsetlat, tileoffsetx, tileoffsety 
     307     */ 
     308    calculateGridLayout: function(bounds, extent, resolution) { 
     309        var tilelon = resolution * this.tileSize.w; 
     310        var tilelat = resolution * this.tileSize.h; 
     311         
     312        var offsetlon = bounds.left - extent.left; 
     313        var tilecol = Math.floor(offsetlon/tilelon) - this.buffer; 
     314        var tilecolremain = offsetlon/tilelon - tilecol; 
     315        var tileoffsetx = -tilecolremain * this.tileSize.w; 
     316        var tileoffsetlon = extent.left + tilecol * tilelon; 
     317         
     318        var offsetlat = extent.top - bounds.top + tilelat;  
     319        var tilerow = Math.floor(offsetlat/tilelat) - this.buffer; 
     320        var tilerowremain = tilerow - offsetlat/tilelat; 
     321        var tileoffsety = tilerowremain * this.tileSize.h; 
     322        var tileoffsetlat = extent.top - tilelat*tilerow; 
     323         
     324        return {  
     325          tilelon: tilelon, tilelat: tilelat, 
     326          tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat, 
     327          tileoffsetx: tileoffsetx, tileoffsety: tileoffsety 
     328        }   
     329    }, 
     330     
     331    CLASS_NAME: "OpenLayers.Layer.MapGuide" 
     332}); 
  • 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&amp;v=2&amp;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      basemaplayergroupname: "BaseLayerGroup",    
     16    } 
     17    var paramsUntiled = { 
     18      mapdefinition: 'Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition', 
     19    }; 
     20 
     21    function test_01_Layer_MapGuide_untiled_constructor (t) { 
     22        t.plan( 8 ); 
     23 
     24        var trans_format = "image/png"; 
     25        var options = {singleTile:true}; 
     26        if (OpenLayers.Util.alphaHack()) { trans_format = "image/gif"; }  
     27         
     28        layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options); 
     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        options.transparent = "true"; 
     38        var layer2 = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options); 
     39        t.eq(layer2.isBaseLayer, false, "transparency == 'true', wms is not baselayer"); 
     40 
     41        options.transparent = true; 
     42        var layer5 = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options); 
     43        t.eq(layer5.isBaseLayer, false, "transparency == true, wms is not baselayer"); 
     44 
     45        options.transparent = false; 
     46        var layer6 = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options); 
     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( 5 ); 
     52 
     53        var trans_format = "image/png"; 
     54        var options = {singleTile:false}; 
     55        if (OpenLayers.Util.alphaHack()) { trans_format = "image/gif"; }  
     56         
     57        layer = new OpenLayers.Layer.MapGuide(name, url, paramsTiled, options); 
     58        t.ok( layer instanceof OpenLayers.Layer.MapGuide, "new OpenLayers.Layer.MapGuide returns object" ); 
     59        t.eq( layer.url, "http://demo01.dmsolutions.ca/mapguide/mapagent/mapagent.fcgi", "layer.url is correct (HTTPRequest inited)" ); 
     60        t.eq( layer.params.basemaplayergroupname, "BaseLayerGroup", "params passed in correctly" ); 
     61 
     62        t.eq( layer.params.operation, "GETTILEIMAGE", "default params correctly uppercased and copied"); 
     63        t.eq( layer.params.version, "1.2.0", "version params 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        var options = {singleTile:true}; 
     148        layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options); 
     149        t.ok( layer.isBaseLayer, "baselayer is true by default"); 
     150 
     151        var newParams = OpenLayers.Util.extend({}, paramsUntiled); 
     152        options.transparent = "true"; 
     153        layer = new OpenLayers.Layer.MapGuide(name, url, newParams, options); 
     154        t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true"); 
     155 
     156        newParams = OpenLayers.Util.extend({}, paramsUntiled); 
     157        options.isBaseLayer = false; 
     158        layer = new OpenLayers.Layer.MapGuide(name, url, newParams, options); 
     159        t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" ); 
     160    } 
     161 
     162    function test_06_Layer_MapGuide_mergeNewParams (t) { 
     163        t.plan( 4 ); 
     164 
     165        var options = {singleTile:true}; 
     166        var map = new OpenLayers.Map("map"); 
     167        layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options); 
     168         
     169        var newParams = { mapDefinition: 'Library://Samples/Gmap/Maps/gmap.MapDefinition', 
     170                          chickpeas: 'image/png'}; 
     171 
     172        map.addLayer(layer); 
     173        map.zoomToMaxExtent(); 
     174 
     175        layer.redraw = function() { 
     176            t.ok(true, "layer is redrawn after new params merged"); 
     177        } 
     178 
     179        layer.mergeNewParams(newParams); 
     180         
     181        t.eq( layer.params.mapDefinition, "Library://Samples/Gmap/Maps/gmap.MapDefinition", "mergeNewParams() overwrites well"); 
     182        t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well"); 
     183     
     184        newParams.chickpeas = 151; 
     185 
     186        t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable"); 
     187        map.destroy(); 
     188    } 
     189 
     190    /* 
     191    function test_07_Layer_MapGuide_getFullRequestString (t) { 
     192 
     193         
     194        t.plan( 2 ); 
     195        var map = new OpenLayers.Map('map'); 
     196        map.projection = "xx"; 
     197        tUrl = "http://octo.metacarta.com/cgi-bin/mapserv"; 
     198        tParams = { layers: 'basic',  
     199                   format: 'image/png'}; 
     200        var tLayer = new OpenLayers.Layer.MapGuide(name, tUrl, tParams); 
     201        map.addLayer(tLayer); 
     202        str = tLayer.getFullRequestString(); 
     203        var tParams = { 
     204            LAYERS: "basic", FORMAT: "image/png", SERVICE: "WMS", 
     205            VERSION: "1.1.1", REQUEST: "GetMap", STYLES: "", 
     206            EXCEPTIONS: "application/vnd.ogc.se_inimage", SRS: "xx" 
     207        }; 
     208        t.eq(str, 
     209             tUrl + "?" + OpenLayers.Util.getParameterString(tParams), 
     210             "getFullRequestString() adds SRS value"); 
     211         
     212        map.removeLayer(tLayer); 
     213        tLayer.projection = "none"; 
     214        map.addLayer(tLayer); 
     215        str = tLayer.getFullRequestString(); 
     216        delete tParams['SRS']; 
     217        t.eq(str, 
     218             tUrl + "?" + OpenLayers.Util.getParameterString(tParams), 
     219             "getFullRequestString() by default does *not* add SRS value if projection is 'none'"); 
     220        map.destroy(); 
     221  
     222    }*/ 
     223 
     224    function test_99_Layer_MapGuide_destroy (t) { 
     225 
     226        t.plan( 1 ); 
     227 
     228        var options = {singleTile:true}; 
     229        var map = new OpenLayers.Map('map'); 
     230        layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options); 
     231        map.addLayer(layer); 
     232 
     233        map.setCenter(new OpenLayers.LonLat(0,0), 5); 
     234 
     235        //grab a reference to one of the tiles 
     236        var tile = layer.grid[0][0];         
     237 
     238        layer.destroy(); 
     239         
     240    // checks to make sure superclass (grid) destroy() was called     
     241         
     242        t.ok( layer.grid == null, "grid set to null"); 
     243    } 
     244     
     245 
     246  </script> 
     247</head> 
     248<body> 
     249<div id="map" style="width:500px;height:550px"></div> 
     250</body> 
     251</html> 
  • tests/list-tests.html

    old new  
    6060    <li>Layer/test_HTTPRequest.html</li> 
    6161    <li>Layer/test_Image.html</li> 
    6262    <li>Layer/test_KaMap.html</li> 
     63    <li>Layer/test_MapGuide.html</li> 
    6364    <li>Layer/test_MapServer.html</li> 
    6465    <li>Layer/test_Markers.html</li> 
    6566    <li>Layer/test_MultiMap.html</li>