1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
---|
2 | * full list of contributors). Published under the Clear BSD license. |
---|
3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
---|
4 | * full text of the license. */ |
---|
5 | |
---|
6 | |
---|
7 | /** |
---|
8 | * @requires OpenLayers/Layer/Grid.js |
---|
9 | * @requires OpenLayers/Tile/Image.js |
---|
10 | */ |
---|
11 | |
---|
12 | /** |
---|
13 | * Class: OpenLayers.Layer.ArcGIS93Rest |
---|
14 | * Instances of OpenLayers.Layer.ArcGIS93Rest are used to display data from |
---|
15 | * ESRI ArcGIS Server 9.3 (and up?) Mapping Services using the REST API. |
---|
16 | * Create a new ArcGIS93Rest layer with the <OpenLayers.Layer.ArcGIS93Rest> |
---|
17 | * constructor. More detail on the REST API is available at |
---|
18 | * http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/index.html ; |
---|
19 | * specifically, the URL provided to this layer should be an export service |
---|
20 | * URL: http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/export.html |
---|
21 | * |
---|
22 | * Inherits from: |
---|
23 | * - <OpenLayers.Layer.Grid> |
---|
24 | */ |
---|
25 | OpenLayers.Layer.ArcGIS93Rest = OpenLayers.Class(OpenLayers.Layer.Grid, { |
---|
26 | |
---|
27 | /** |
---|
28 | * Constant: DEFAULT_PARAMS |
---|
29 | * {Object} Hashtable of default parameter key/value pairs |
---|
30 | */ |
---|
31 | DEFAULT_PARAMS: { |
---|
32 | format: "png" |
---|
33 | }, |
---|
34 | |
---|
35 | /** |
---|
36 | * APIProperty: isBaseLayer |
---|
37 | * {Boolean} Default is true for ArcGIS93Rest layer |
---|
38 | */ |
---|
39 | isBaseLayer: true, |
---|
40 | |
---|
41 | |
---|
42 | /** |
---|
43 | * Constructor: OpenLayers.Layer.ArcGIS93Rest |
---|
44 | * Create a new ArcGIS93Rest layer object. |
---|
45 | * |
---|
46 | * Example: |
---|
47 | * (code) |
---|
48 | * var arcims = new OpenLayers.Layer.ArcGIS93Rest("MyName", |
---|
49 | * "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export", |
---|
50 | * { |
---|
51 | * layers: "0,1,2" |
---|
52 | * }); |
---|
53 | * (end) |
---|
54 | * |
---|
55 | * Parameters: |
---|
56 | * name - {String} A name for the layer |
---|
57 | * url - {String} Base url for the ArcGIS server REST service |
---|
58 | * options - {Object} An object with key/value pairs representing the |
---|
59 | * options and option values. |
---|
60 | * Valid Options: |
---|
61 | * format: {String} MIME type of desired image type. |
---|
62 | * layers: {String} Comma-separated list of layers to display. |
---|
63 | * srs: {String} Projection ID. |
---|
64 | */ |
---|
65 | initialize: function(name, url, params, options) { |
---|
66 | var newArguments = []; |
---|
67 | //uppercase params |
---|
68 | params = OpenLayers.Util.upperCaseObject(params); |
---|
69 | newArguments.push(name, url, params, options); |
---|
70 | OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); |
---|
71 | OpenLayers.Util.applyDefaults( |
---|
72 | this.params, |
---|
73 | OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS) |
---|
74 | ); |
---|
75 | |
---|
76 | //layer is transparent |
---|
77 | if (this.params.TRANSPARENT && |
---|
78 | this.params.TRANSPARENT.toString().toLowerCase() == "true") { |
---|
79 | |
---|
80 | // unless explicitly set in options, make layer an overlay |
---|
81 | if ( (options == null) || (!options.isBaseLayer) ) { |
---|
82 | this.isBaseLayer = false; |
---|
83 | } |
---|
84 | |
---|
85 | // jpegs can never be transparent, so intelligently switch the |
---|
86 | // format, depending on the browser's capabilities |
---|
87 | if (this.params.FORMAT == "jpg") { |
---|
88 | this.params.FORMAT = OpenLayers.Util.alphaHack() ? "gif" |
---|
89 | : "png"; |
---|
90 | } |
---|
91 | } |
---|
92 | }, |
---|
93 | |
---|
94 | |
---|
95 | /** |
---|
96 | * Method: destroy |
---|
97 | * Destroy this layer |
---|
98 | */ |
---|
99 | destroy: function() { |
---|
100 | // for now, nothing special to do here. |
---|
101 | OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments); |
---|
102 | }, |
---|
103 | |
---|
104 | /** |
---|
105 | * Method: clone |
---|
106 | * Create a clone of this layer |
---|
107 | * |
---|
108 | * Returns: |
---|
109 | * {<OpenLayers.Layer.ArcGIS93Rest>} An exact clone of this layer |
---|
110 | */ |
---|
111 | clone: function (obj) { |
---|
112 | |
---|
113 | if (obj == null) { |
---|
114 | obj = new OpenLayers.Layer.ArcGIS93Rest(this.name, |
---|
115 | this.url, |
---|
116 | this.params, |
---|
117 | this.getOptions()); |
---|
118 | } |
---|
119 | |
---|
120 | //get all additions from superclasses |
---|
121 | obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); |
---|
122 | |
---|
123 | // copy/set any non-init, non-simple values here |
---|
124 | |
---|
125 | return obj; |
---|
126 | }, |
---|
127 | |
---|
128 | |
---|
129 | /** |
---|
130 | * Method: getURL |
---|
131 | * Return an image url this layer. |
---|
132 | * |
---|
133 | * Parameters: |
---|
134 | * bounds - {<OpenLayers.Bounds>} A bounds representing the bbox for the |
---|
135 | * request. |
---|
136 | * |
---|
137 | * Returns: |
---|
138 | * {String} A string with the map image's url. |
---|
139 | */ |
---|
140 | getURL: function (bounds) { |
---|
141 | bounds = this.adjustBounds(bounds); |
---|
142 | |
---|
143 | // ArcGIS Server only wants the numeric portion of the projection ID. |
---|
144 | var projWords = this.projection.getCode().split(":"); |
---|
145 | var srid = projWords[projWords.length - 1]; |
---|
146 | |
---|
147 | var imageSize = this.getImageSize(); |
---|
148 | var newParams = { |
---|
149 | 'BBOX': bounds.toBBOX(), |
---|
150 | 'SIZE': imageSize.w + "," + imageSize.h, |
---|
151 | // We always want image, the other options were json, image with a whole lotta html around it, etc. |
---|
152 | 'F': "image", |
---|
153 | 'BBOXSR': srid, |
---|
154 | 'IMAGESR': srid |
---|
155 | }; |
---|
156 | |
---|
157 | // Now add the filter parameters. |
---|
158 | if (this.layerDefs) { |
---|
159 | var layerDefStrList = []; |
---|
160 | var layerID; |
---|
161 | for(layerID in this.layerDefs) { |
---|
162 | if (this.layerDefs.hasOwnProperty(layerID)) { |
---|
163 | if (this.layerDefs[layerID]) { |
---|
164 | layerDefStrList.push(layerID); |
---|
165 | layerDefStrList.push(":"); |
---|
166 | layerDefStrList.push(this.layerDefs[layerID]); |
---|
167 | layerDefStrList.push(";"); |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | if (layerDefStrList.length > 0) { |
---|
172 | newParams['LAYERDEFS'] = layerDefStrList.join(""); |
---|
173 | } |
---|
174 | } |
---|
175 | var requestString = this.getFullRequestString(newParams); |
---|
176 | return requestString; |
---|
177 | }, |
---|
178 | |
---|
179 | /** |
---|
180 | * Method: setLayerFilter |
---|
181 | * addTile creates a tile, initializes it, and adds it to the layer div. |
---|
182 | * |
---|
183 | * Parameters: |
---|
184 | * id - {String} The id of the layer to which the filter applies. |
---|
185 | * queryDef - {String} A sql-ish query filter, for more detail see the ESRI |
---|
186 | * documentation at http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/export.html |
---|
187 | */ |
---|
188 | setLayerFilter: function ( id, queryDef ) { |
---|
189 | if (!this.layerDefs) { |
---|
190 | this.layerDefs = {}; |
---|
191 | } |
---|
192 | if (queryDef) { |
---|
193 | this.layerDefs[id] = queryDef; |
---|
194 | } else { |
---|
195 | delete this.layerDefs[id]; |
---|
196 | } |
---|
197 | }, |
---|
198 | |
---|
199 | /** |
---|
200 | * Method: clearLayerFilter |
---|
201 | * Clears layer filters, either from a specific layer, |
---|
202 | * or all of them. |
---|
203 | * |
---|
204 | * Parameters: |
---|
205 | * id - {String} The id of the layer from which to remove any |
---|
206 | * filter. If unspecified/blank, all filters |
---|
207 | * will be removed. |
---|
208 | */ |
---|
209 | clearLayerFilter: function ( id ) { |
---|
210 | if (id) { |
---|
211 | delete this.layerDefs[id]; |
---|
212 | } else { |
---|
213 | delete this.layerDefs; |
---|
214 | } |
---|
215 | }, |
---|
216 | |
---|
217 | /** |
---|
218 | * APIMethod: mergeNewParams |
---|
219 | * Catch changeParams and uppercase the new params to be merged in |
---|
220 | * before calling changeParams on the super class. |
---|
221 | * |
---|
222 | * Once params have been changed, the tiles will be reloaded with |
---|
223 | * the new parameters. |
---|
224 | * |
---|
225 | * Parameters: |
---|
226 | * newParams - {Object} Hashtable of new params to use |
---|
227 | */ |
---|
228 | mergeNewParams:function(newParams) { |
---|
229 | var upperParams = OpenLayers.Util.upperCaseObject(newParams); |
---|
230 | var newArguments = [upperParams]; |
---|
231 | return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, |
---|
232 | newArguments); |
---|
233 | }, |
---|
234 | |
---|
235 | /** |
---|
236 | * Method: addTile |
---|
237 | * addTile creates a tile, initializes it, and adds it to the layer div. |
---|
238 | * |
---|
239 | * Parameters: |
---|
240 | * bounds - {<OpenLayers.Bounds>} |
---|
241 | * position - {<OpenLayers.Pixel>} |
---|
242 | * |
---|
243 | * Returns: |
---|
244 | * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image |
---|
245 | */ |
---|
246 | addTile:function(bounds,position) { |
---|
247 | return new OpenLayers.Tile.Image(this, position, bounds, |
---|
248 | null, this.tileSize); |
---|
249 | }, |
---|
250 | |
---|
251 | |
---|
252 | CLASS_NAME: "OpenLayers.Layer.ArcGIS93Rest" |
---|
253 | }); |
---|