[OpenLayers-Commits] r4774 - in sandbox/stvn/arcgis-server: examples lib lib/OpenLayers/Layer

commits at openlayers.org commits at openlayers.org
Wed Oct 3 05:14:28 EDT 2007


Author: stvn
Date: 2007-10-03 05:14:27 -0400 (Wed, 03 Oct 2007)
New Revision: 4774

Added:
   sandbox/stvn/arcgis-server/examples/arcgis-server.html
   sandbox/stvn/arcgis-server/lib/OpenLayers/Layer/AGS.js
Modified:
   sandbox/stvn/arcgis-server/lib/OpenLayers.js
Log:
Added support for ArcGIS server 9.2's tilecache algorythm. Be aware that you need to get the extent perfect to get it working properly

Added: sandbox/stvn/arcgis-server/examples/arcgis-server.html
===================================================================
--- sandbox/stvn/arcgis-server/examples/arcgis-server.html	                        (rev 0)
+++ sandbox/stvn/arcgis-server/examples/arcgis-server.html	2007-10-03 09:14:27 UTC (rev 4774)
@@ -0,0 +1,60 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <style type="text/css">
+      
+    </style>
+    <script src="../lib/OpenLayers.js"></script>
+    <script type="text/javascript">
+        <!--
+        var lon = 4316075;
+        var lat = 303196;
+        var zoom = 3;
+        var map, layer;
+
+        function init(){
+            map = new OpenLayers.Map( 'map', {
+
+								maxExtent: new OpenLayers.Bounds(292358,4305237,314033,4326912),
+
+								maxResolution: 33.0729828126323,
+
+								resolutions: new Array(33.0729828126323,16.9333672000677,8.46668360003387,4.23334180001693,2.11667090000847,1.05833545000423), tileSize : new OpenLayers.Size(256,256),
+
+								tileOrigin: new OpenLayers.LonLat(-5120900,9998100),
+
+								units: 'm'} );
+            layer = new OpenLayers.Layer.AGS( "AGS", 
+                    "http://serverx.esri.com/arcgiscache/DG_County_roads_yesA_backgroundDark/Layers", {layername: '_alllayers', type:'png', 
+
+                    tileOrigin: new OpenLayers.LonLat(-5120900,9998100)
+
+                    } );
+
+                     
+
+            map.addLayer(layer);
+
+                     
+            map.addControl(new OpenLayers.Control.LayerSwitcher());
+            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
+        }
+        function addAGS() {
+            l = new OpenLayers.Layer.AGS(
+                OpenLayers.Util.getElement('layer').value, 
+                OpenLayers.Util.getElement('url').value, 
+                {
+                    'layername': OpenLayers.Util.getElement('layer').value, 
+                    'type': OpenLayers.Util.getElement('type').value
+            });
+            map.addLayer(l);
+            map.setBaseLayer(l);
+        }  
+        // -->
+    </script>
+  </head>
+  <body onload="init()">
+
+An example showing OpenLayers using the MapCache of ArcGIS server 9.2
+    <div id="map"></div>
+  </body>
+</html>

Added: sandbox/stvn/arcgis-server/lib/OpenLayers/Layer/AGS.js
===================================================================
--- sandbox/stvn/arcgis-server/lib/OpenLayers/Layer/AGS.js	                        (rev 0)
+++ sandbox/stvn/arcgis-server/lib/OpenLayers/Layer/AGS.js	2007-10-03 09:14:27 UTC (rev 4774)
@@ -0,0 +1,125 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD licence.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
+ * for the full text of the license. */
+
+
+/**
+ * @class
+ * 
+ * @requires OpenLayers/Layer/Grid.js
+ */
+OpenLayers.Layer.AGS = OpenLayers.Class(OpenLayers.Layer.Grid, {
+
+    
+    reproject: false,
+    isBaseLayer: true,
+    tileOrigin: null,
+
+    /**
+    * @constructor
+    *
+    * @param {String} name
+    * @param {String} url
+    * @param {Object} params
+    * @param {Object} options Hashtable of extra options to tag onto the layer
+    */
+    initialize: function(name, url, options) {
+        var newArguments = [];
+        newArguments.push(name, url, {}, options);
+        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
+    },    
+
+    /**
+     * 
+     */
+    destroy: function() {
+        // for now, nothing special to do here. 
+        OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);  
+    },
+
+    
+    /**
+     * @param {Object} obj
+     * 
+     * @returns An exact clone of this OpenLayers.Layer.TMS
+     * @type OpenLayers.Layer.TMS
+     */
+    clone: function (obj) {
+        
+        if (obj == null) {
+            obj = new OpenLayers.Layer.AGS(this.name,
+                                           this.url,
+                                           this.options);
+        }
+
+        //get all additions from superclasses
+        obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
+
+        // copy/set any non-init, non-simple values here
+
+        return obj;
+    },    
+    
+    /**
+     * @param {OpenLayers.Bounds} bounds
+     * 
+     * @returns A string with the layer's url and parameters and also the 
+     *           passed-in bounds and appropriate tile size specified as 
+     *           parameters
+     * @type String
+     */
+    getURL: function (bounds) {
+        var res = this.map.getResolution();
+        var x = (Math.floor((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w))).toString(16);
+        while (x.length < 8) {
+        x = "0" + x;
+        }
+        x = "C" +x;
+        var y = (Math.floor((this.tileOrigin.lat - bounds.top ) / (res * this.tileSize.h))).toString(16);
+        while (y.length < 8) {
+        y = "0" + y;
+        }
+        y = "R" +y;
+        
+        /*
+        var x = (bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w);
+        var y = (bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h);*/
+        
+        var z = this.map.getZoom();
+        if (z <10) z = "L0"+z;
+        else z ="L"+z;
+        return this.url + "/" + this.layername + "/" + z + "/" + y + "/" + x + "." + this.type; 
+    },
+
+    /**
+    * addTile creates a tile, initializes it, and 
+    * adds it to the layer div. 
+    *
+    * @param {OpenLayers.Bounds} bounds
+    *
+    * @returns The added OpenLayers.Tile.Image
+    * @type OpenLayers.Tile.Image
+    */
+    addTile:function(bounds,position) {
+        var url = this.getURL(bounds);
+        return new OpenLayers.Tile.Image(this, position, bounds, 
+                                             url, this.tileSize);
+    },
+
+    /** When the layer is added to a map, then we can fetch our origin 
+     *  (if we don't have one.) 
+     * 
+     * @param {OpenLayers.Map} map
+     */
+    setMap: function(map) {
+        OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments);
+        if (!this.tileOrigin) { 
+            this.tileOrigin = new OpenLayers.LonLat(this.map.maxExtent.left,
+                                                this.map.maxExtent.bottom);
+        }                                       
+    },
+
+    
+    /** @final @type String */
+    CLASS_NAME: "OpenLayers.Layer.AGS"
+});

Modified: sandbox/stvn/arcgis-server/lib/OpenLayers.js
===================================================================
--- sandbox/stvn/arcgis-server/lib/OpenLayers.js	2007-10-03 09:10:01 UTC (rev 4773)
+++ sandbox/stvn/arcgis-server/lib/OpenLayers.js	2007-10-03 09:14:27 UTC (rev 4774)
@@ -108,6 +108,7 @@
             "OpenLayers/Layer/GeoRSS.js",
             "OpenLayers/Layer/Boxes.js",
             "OpenLayers/Layer/TMS.js",
+            "OpenLayers/Layer/AGS.js",            
             "OpenLayers/Layer/TileCache.js",
             "OpenLayers/Popup/Anchored.js",
             "OpenLayers/Popup/AnchoredBubble.js",



More information about the Commits mailing list