OpenLayers OpenLayers

Ticket #1967: ArcGISCache.patch

File ArcGISCache.patch, 9.3 kB (added by mpriour, 1 year ago)

*USE THIS ONE* ArcGIS MapCache Layer plus Example

  • examples/agsTileCache.html

    old new  
     1<html xmlns="http://www.w3.org/1999/xhtml"> 
     2    <head> 
     3        <title>ArcGIS Server Tiled Layer Map Cache Example</title> 
     4        <link rel="stylesheet" href="../theme/default/style.css" type="text/css" /> 
     5        <link rel="stylesheet" href="style.css" type="text/css" /> 
     6        <script src="../lib/OpenLayers.js" type="text/javascript"></script> 
     7        <script src="../lib/OpenLayers/Layer/ArcGISCache.js" type="text/javascript"></script> 
     8        <script type="text/javascript"> 
     9        /* First 4 variables extracted from conf.xml file */     
     10        /* Tile layers & map MUST have same projection */ 
     11            var proj='EPSG:26915'; 
     12        /*Layer can also accept serverResolutions array 
     13         * to deal with situation in which layer resolution array & map resolution 
     14         * array are out of sync*/ 
     15            var mapResolutions = [33.0729828126323,16.9333672000677,8.46668360003387,4.23334180001693,2.11667090000847,1.05833545000423]; 
     16        /*For this example this next line is not really needed, 256x256 is default. 
     17         * However, you would need to change this if your layer had different tile sizes */ 
     18            var tileSize = new OpenLayers.Size(256,256); 
     19        /*Tile Origin is required unless it is the same as the implicit map origin 
     20         * which can be effected by several variables including maxExtent for map or base layer */ 
     21            var agsTileOrigin = new OpenLayers.LonLat(-5120900,9998100); 
     22            /*This can really be any valid bounds that the map would reasonably be within*/ 
     23        /*  var mapExtent = new OpenLayers.Bounds(293449.454286,4307691.661132,314827.830376,4323381.484178); */ 
     24            var mapExtent = new OpenLayers.Bounds(289310.8204,4300021.937,314710.8712,4325421.988); 
     25      var aerialsUrl = 'http://serverx.esri.com/arcgiscache/dgaerials/Layers'; 
     26            var roadsUrl = 'http://serverx.esri.com/arcgiscache/DG_County_roads_yesA_backgroundDark/Layers'; 
     27             
     28            function init(){ 
     29                var map = new OpenLayers.Map('map', { 
     30                    projection: proj, 
     31                    resolutions:mapResolutions, 
     32                    tileSize: tileSize, 
     33                    maxExtent:mapExtent, 
     34                    controls: [new OpenLayers.Control.Navigation(),new OpenLayers.Control.LayerSwitcher(), new OpenLayers.Control.PanZoomBar()] 
     35                }); 
     36                var baseLayer = new OpenLayers.Layer.ArcGISCache('Aerials', aerialsUrl, { 
     37                    layername: '_alllayers', 
     38                    tileOrigin: agsTileOrigin, 
     39                    isBaseLayer: true, 
     40                    type: 'jpg' 
     41                }); 
     42                var overlayLayer = new OpenLayers.Layer.ArcGISCache('Roads', roadsUrl, { 
     43                    layername: '_alllayers', 
     44                    tileOrigin: agsTileOrigin, 
     45                    isBaseLayer: false, 
     46                    type: 'png' 
     47                }) 
     48                map.addLayers([baseLayer, overlayLayer]); 
     49                map.zoomToMaxExtent(); 
     50            } 
     51        </script> 
     52    </head> 
     53    <body onload="init()"> 
     54        <h1 id="title">ArcGIS Server Tiled Layer Map Cache Example</h1> 
     55 
     56        <div id="tags"> 
     57        </div> 
     58 
     59        <div id="shortdesc"> 
     60            <p>This example demonstrates using the ArcGISCache layer for  
     61            accessing ESRI's ArcGIS Server (AGS) Map Cache tiles directly.</p> 
     62            You will need to know: 
     63            <ul> 
     64                <li>Tile Size: Defaults to Map.tileSize (default:256x256)</li> 
     65                <li>Image Type (or really file extension)</li> 
     66                <li>Tile Origin: Defaults to Map.tileOrigin</li> 
     67            </ul> 
     68            <p>You will find these in "conf.xml" at the same Url used for this layer</p> 
     69            <ul> 
     70                <li>Tile Size : &lt;Tile Origin&gt; &lt;TileCols&gt; &lt;TileRows&gt;</li> 
     71                <li>Image Type : &lt;TileImageInfo&gt; &lt;CacheTileFormat&gt;</li> 
     72                <li>Tile Origin : &lt;Tile Origin&gt; &lt;X&gt; &lt;Y&gt;</li> 
     73            </ul> 
     74        </div> 
     75         
     76        <div id="map" class="smallmap"></div> 
     77 
     78        <div id="docs"> 
     79            <p> 
     80            The layername config property is REQUIRED. However, in most cases this is just '_alllayers'.<br /> 
     81            The layer URL points the directory just above the one containing the 'layer' (ie. _alllayers) <br /> 
     82            <strong>Do Not Include the trailing '/'</strong><br /> 
     83            For fused map caches this is often http:<i>ServerName</i>/arcgiscache/<i>MapServiceName</i>/Layers <br /> 
     84            For individual layer caches this is often  http:<i>ServerName</i>/arcgiscache/<i>LayerName</i>/Layers <br /> 
     85            </p> 
     86            <p> 
     87            Example:<br /> 
     88            Layer URL: http://serverx.esri.com/arcgiscache/dgaerials/Layers <br /> 
     89            </p> 
     90            OpenLayers Layer Object:<br />  
     91            <pre> 
     92                new OpenLayers.Layer.ArcGISCache('Aerials',  
     93                    'http://serverx.esri.com/arcgiscache/dgaerials/Layers', 
     94                    {layername: '_alllayers', 
     95                    tileOrigin: new OpenLayers.LonLat(-5120900,9998100), 
     96                    isBaseLayer: true, 
     97                    type: 'jpg'} 
     98                ); 
     99            </pre> 
     100        </div> 
     101    </body> 
     102</html> 
  • lib/OpenLayers.js

    old new  
    121121            "OpenLayers/Layer/GeoRSS.js", 
    122122            "OpenLayers/Layer/Boxes.js", 
    123123            "OpenLayers/Layer/TMS.js", 
     124            "OpenLayers/Layer/ArcGISCache.js", 
    124125            "OpenLayers/Layer/TileCache.js", 
    125126            "OpenLayers/Popup/Anchored.js", 
    126127            "OpenLayers/Popup/AnchoredBubble.js", 
  • lib/OpenLayers/Layer/ArcGISCache.js

    old new  
     1/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD licence. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4/** 
     5 * @requires OpenLayers/Layer/TMS.js 
     6 */ 
     7 /** 
     8  * Class: OpenLayers.Layer.ArcGISCache   
     9  * Layer for accessing cached map tiles from an ArcGIS Server style mapcache. 
     10  * Tile MUST already be cached for this layer to access it. Does NOT require 
     11  * ArcGIS Server itself. It will work on any accessible directory structure 
     12  * that is the same as the one which ArcGIS Server creates. 
     13  *  
     14  *Inherits from: 
     15  *  - <OpenLayers.Layer.TMS>             
     16  */    
     17OpenLayers.Layer.ArcGISCache = OpenLayers.Class(OpenLayers.Layer.TMS, {   
     18     
     19     /** 
     20     * APIProperty: tileOrigin 
     21     * The X,Y origin of the tiles in map coordinates. 
     22     * {<OpenLayers.LonLat>} 
     23     */ 
     24    tileOrigin: null, 
     25     
     26     /** 
     27     * Constructor: OpenLayers.Layer.ArcGISCache 
     28     * Creates a new instance of this class 
     29     *  
     30     * Parameters: 
     31     * name - {String} 
     32     * url - {String} 
     33     * options - {Object} Hashtable of extra options to tag onto the layer 
     34     */ 
     35    initialize: function(name, url, options) { 
     36        var newArguments = []; 
     37        newArguments.push(name, url, {}, options); 
     38        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); 
     39    }, 
     40     
     41     
     42    /** 
     43     * APIMethod: clone 
     44     * Returns an exact clone of this OpenLayers.Layer.ArcGISCache       
     45     * 
     46     * Parameters: 
     47     * [obj] - {Object} optional object to assign the cloned instance to.             
     48     *  
     49     * Returns: 
     50     * {<OpenLayers.Layer.ArcGISCache>} clone of this instance 
     51     */ 
     52    clone: function (obj) { 
     53        if (obj == null) { 
     54            obj = new OpenLayers.Layer.ArcGISCache(this.name, 
     55                                           this.url, 
     56                                           this.options); 
     57        } 
     58        //get all additions from superclasses 
     59        obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); 
     60        return obj; 
     61    },     
     62     
     63    /** 
     64     * APIMethod: getURL 
     65     * Gets the URL string for the tile specified by the passed bounds object. 
     66     *  
     67     * Parameters: 
     68     * bounds - {OpenLayers.Bounds} the bounds of the area the tile will fill.                      
     69     *  
     70     * Returns: 
     71     * {String} A string with the layer's url and specific path to the tile. 
     72     */ 
     73    getURL: function (bounds) { 
     74        var path,url,res,x,y,z,center,originTileX,originTileY; 
     75            res = this.map.getResolution(); 
     76            //get tile center 
     77            center = bounds.getCenterLonLat(); 
     78            originTileX = this.tileOrigin.lon + (res * this.tileSize.w/2); 
     79            originTileY = this.tileOrigin.lat - (res * this.tileSize.h/2); 
     80            //calculate x 
     81            x = (Math.round(Math.abs((center.lon - originTileX ) / (res * this.tileSize.w)))).toString(16); 
     82        while (x.length < 8) { 
     83          x = "0" + x; 
     84        } 
     85        x = "C" +x; 
     86        //calculate y 
     87            y = (Math.round(Math.abs((originTileY - center.lat) / (res * this.tileSize.h)))).toString(16); 
     88        while (y.length < 8) { 
     89          y = "0" + y; 
     90        } 
     91        y = "R" +y; 
     92        //calculate z 
     93        z = (this.serverResolutions != null) ? this.serverResolutions.indexOf(res) : this.map.getZoom(); 
     94        if (z <10) z = "L0"+z; 
     95        else z ="L"+z; 
     96            //concatenate path 
     97            path = "/" + this.layername + "/" + z + "/" + y + "/" + x + "." + this.type; 
     98        url = this.url; 
     99        if (url instanceof Array) { 
     100            url = this.selectUrl(path, url); 
     101        } 
     102        return url + path;  
     103    }, 
     104 
     105    CLASS_NAME: "OpenLayers.Layer.ArcGISCache" 
     106});