1 /* Copyright (c) 2008 Avencia, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
7 * @requires OpenLayers/Layer/Grid.js
8 * @requires OpenLayers/Tile/Image.js
12 * Class: OpenLayers.Layer.ArcGIS93Rest
13 * Instances of OpenLayers.Layer.ArcGIS93Rest are used to display data from
14 * ESRI ArcGIS Server 9.3 (and up?) Mapping Services using the REST API.
15 * Create a new ArcGIS93Rest layer with the <OpenLayers.Layer.ArcGIS93Rest>
16 * constructor. More detail on the REST API is available at
17 * http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/index.html ;
18 * specifically, the URL provided to this layer should be an export service
19 * URL: http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/export.html
22 * - <OpenLayers.Layer.Grid>
24 OpenLayers.Layer.ArcGIS93Rest = OpenLayers.Class(OpenLayers.Layer.Grid, {
27 * Constant: DEFAULT_PARAMS
28 * {Object} Hashtable of default parameter key/value pairs
35 * APIProperty: isBaseLayer
36 * {Boolean} Default is true for ArcGIS93Rest layer
42 * Constructor: OpenLayers.Layer.ArcGIS93Rest
43 * Create a new ArcGIS93Rest layer object.
47 * var arcims = new OpenLayers.Layer.ArcGIS93Rest("MyName",
48 * "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer",
55 * name - {String} A name for the layer
56 * url - {String} Base url for the ArcGIS server REST service
57 * options - {Object} An object with key/value pairs representing the
58 * options and option values.
60 * format: {String} MIME type of desired image type.
61 * layers: {String} Comma-separated list of layers to display.
62 * srs: {String} Projection ID.
64 initialize: function(name, url, params, options) {
65 var newArguments = [];
67 params = OpenLayers.Util.upperCaseObject(params);
68 newArguments.push(name, url, params, options);
69 OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
70 OpenLayers.Util.applyDefaults(
72 OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
75 //layer is transparent
76 if (this.params.TRANSPARENT &&
77 this.params.TRANSPARENT.toString().toLowerCase() == "true") {
79 // unless explicitly set in options, make layer an overlay
80 if ( (options == null) || (!options.isBaseLayer) ) {
81 this.isBaseLayer = false;
84 // jpegs can never be transparent, so intelligently switch the
85 // format, depending on the browser's capabilities
86 if (this.params.FORMAT == "jpg") {
87 this.params.FORMAT = OpenLayers.Util.alphaHack() ? "gif"
99 // for now, nothing special to do here.
100 OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);
105 * Create a clone of this layer
108 * {<OpenLayers.Layer.ArcGIS93Rest>} An exact clone of this layer
110 clone: function (obj) {
113 obj = new OpenLayers.Layer.ArcGIS93Rest(this.name,
119 //get all additions from superclasses
120 obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
122 // copy/set any non-init, non-simple values here
130 * Return an image url this layer.
133 * bounds - {<OpenLayers.Bounds>} A bounds representing the bbox for the
137 * {String} A string with the map image's url.
139 getURL: function (bounds) {
140 bounds = this.adjustBounds(bounds);
142 // ArcGIS Server only wants the numeric portion of the projection ID.
143 var projWords = this.projection.getCode().split(":");
144 var srid = projWords[projWords.length - 1];
146 var imageSize = this.getImageSize();
148 'BBOX': bounds.toBBOX(),
149 'SIZE': imageSize.w + "," + imageSize.h,
150 // We always want image, the other options were json, image with a whole lotta html around it, etc.
156 // Now add the filter parameters.
157 if (this.layerDefs) {
158 var layerDefStrList = [];
160 for(layerID in this.layerDefs) {
161 if (this.layerDefs.hasOwnProperty(layerID)) {
162 if (this.layerDefs[layerID]) {
163 layerDefStrList.push(layerID);
164 layerDefStrList.push(":");
165 layerDefStrList.push(this.layerDefs[layerID]);
166 layerDefStrList.push(";");
170 if (layerDefStrList.length > 0) {
171 newParams['LAYERDEFS'] = layerDefStrList.join("");
174 var requestString = this.getFullRequestString(newParams);
175 return requestString;
179 * Method: setLayerFilter
180 * addTile creates a tile, initializes it, and adds it to the layer div.
183 * id - {String} The id of the layer to which the filter applies.
184 * queryDef - {String} A sql-ish query filter, for more detail see the ESRI
185 * documentation at http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/export.html
187 setLayerFilter: function ( id, queryDef ) {
188 if (!this.layerDefs) {
192 this.layerDefs[id] = queryDef;
194 delete this.layerDefs[id];
199 * Method: clearLayerFilter
200 * Clears layer filters, either from a specific layer,
204 * id - {String} The id of the layer from which to remove any
205 * filter. If unspecified/blank, all filters
208 clearLayerFilter: function ( id ) {
210 delete this.layerDefs[id];
212 delete this.layerDefs;
217 * APIMethod: mergeNewParams
218 * Catch changeParams and uppercase the new params to be merged in
219 * before calling changeParams on the super class.
221 * Once params have been changed, the tiles will be reloaded with
222 * the new parameters.
225 * newParams - {Object} Hashtable of new params to use
227 mergeNewParams:function(newParams) {
228 var upperParams = OpenLayers.Util.upperCaseObject(newParams);
229 var newArguments = [upperParams];
230 return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this,
236 * addTile creates a tile, initializes it, and adds it to the layer div.
239 * bounds - {<OpenLayers.Bounds>}
240 * position - {<OpenLayers.Pixel>}
243 * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
245 addTile:function(bounds,position) {
246 return new OpenLayers.Tile.Image(this, position, bounds,
247 null, this.tileSize);
251 CLASS_NAME: "OpenLayers.Layer.ArcGIS93Rest"