]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Layer/ArcGIS93Rest.js
update german translation
[syp.git] / openlayers / lib / OpenLayers / Layer / ArcGIS93Rest.js
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. */
4
5
6 /**
7  * @requires OpenLayers/Layer/Grid.js
8  * @requires OpenLayers/Tile/Image.js
9  */
10
11 /**
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 
20  * 
21  * Inherits from:
22  *  - <OpenLayers.Layer.Grid>
23  */
24 OpenLayers.Layer.ArcGIS93Rest = OpenLayers.Class(OpenLayers.Layer.Grid, {
25
26     /**
27      * Constant: DEFAULT_PARAMS
28      * {Object} Hashtable of default parameter key/value pairs 
29      */
30     DEFAULT_PARAMS: { 
31       format: "png"
32     },
33         
34     /**
35      * APIProperty: isBaseLayer
36      * {Boolean} Default is true for ArcGIS93Rest layer
37      */
38     isBaseLayer: true,
39  
40  
41     /**
42      * Constructor: OpenLayers.Layer.ArcGIS93Rest
43      * Create a new ArcGIS93Rest layer object.
44      *
45      * Example:
46      * (code)
47      * var arcims = new OpenLayers.Layer.ArcGIS93Rest("MyName",
48      *                                    "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer", 
49      *                                    {
50      *                                      layers: "0,1,2"
51      *                                    });
52      * (end)
53      *
54      * Parameters:
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.
59      * Valid Options:
60      *        format: {String} MIME type of desired image type.
61      *        layers: {String} Comma-separated list of layers to display.
62      *        srs: {String} Projection ID.
63      */
64     initialize: function(name, url, params, options) {
65         var newArguments = [];
66         //uppercase params
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(
71                        this.params, 
72                        OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
73                        );
74                        
75         //layer is transparent        
76         if (this.params.TRANSPARENT && 
77             this.params.TRANSPARENT.toString().toLowerCase() == "true") {
78             
79             // unless explicitly set in options, make layer an overlay
80             if ( (options == null) || (!options.isBaseLayer) ) {
81                 this.isBaseLayer = false;
82             } 
83             
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"
88                                                                  : "png";
89             }
90         }
91     },    
92
93     
94     /**
95      * Method: destroy
96      * Destroy this layer
97      */
98     destroy: function() {
99         // for now, nothing special to do here. 
100         OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);  
101     },   
102     
103     /**
104          * Method: clone
105          * Create a clone of this layer
106          *
107          * Returns:
108          * {<OpenLayers.Layer.ArcGIS93Rest>} An exact clone of this layer
109          */
110     clone: function (obj) {
111         
112         if (obj == null) {
113             obj = new OpenLayers.Layer.ArcGIS93Rest(this.name,
114                                            this.url,
115                                            this.params,
116                                            this.options);
117         }
118
119         //get all additions from superclasses
120         obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
121
122         // copy/set any non-init, non-simple values here
123
124         return obj;
125     },
126     
127     
128     /**
129      * Method: getURL
130      * Return an image url this layer.
131      *
132      * Parameters:
133      * bounds - {<OpenLayers.Bounds>} A bounds representing the bbox for the
134      *                                request.
135      *
136      * Returns:
137      * {String} A string with the map image's url.
138      */
139     getURL: function (bounds) {
140         bounds = this.adjustBounds(bounds);
141
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];
145
146         var imageSize = this.getImageSize(); 
147         var newParams = {
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.
151             'F': "image",
152             'BBOXSR': srid,
153             'IMAGESR': srid
154         };
155
156         // Now add the filter parameters.
157         if (this.layerDefs) {
158             var layerDefStrList = [];
159             var layerID;
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(";");
167                     }
168                 }
169             }
170             if (layerDefStrList.length > 0) {
171                 newParams['LAYERDEFS'] = layerDefStrList.join("");
172             }
173         }
174         var requestString = this.getFullRequestString(newParams);
175         return requestString;
176     },
177     
178     /**
179      * Method: setLayerFilter
180      * addTile creates a tile, initializes it, and adds it to the layer div. 
181      *
182      * Parameters:
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
186      */
187     setLayerFilter: function ( id, queryDef ) {
188         if (!this.layerDefs) {
189             this.layerDefs = {};
190         }
191         if (queryDef) {
192             this.layerDefs[id] = queryDef;
193         } else {
194             delete this.layerDefs[id];
195         }
196     },
197     
198     /**
199      * Method: clearLayerFilter
200      * Clears layer filters, either from a specific layer,
201      * or all of them.
202      *
203      * Parameters:
204      * id - {String} The id of the layer from which to remove any
205      *               filter.  If unspecified/blank, all filters
206      *               will be removed.
207      */
208     clearLayerFilter: function ( id ) {
209         if (id) {
210             delete this.layerDefs[id];
211         } else {
212             delete this.layerDefs;
213         }
214     },
215     
216     /**
217      * APIMethod: mergeNewParams
218      * Catch changeParams and uppercase the new params to be merged in
219      *     before calling changeParams on the super class.
220      * 
221      *     Once params have been changed, the tiles will be reloaded with
222      *     the new parameters.
223      * 
224      * Parameters:
225      * newParams - {Object} Hashtable of new params to use
226      */
227     mergeNewParams:function(newParams) {
228         var upperParams = OpenLayers.Util.upperCaseObject(newParams);
229         var newArguments = [upperParams];
230         return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, 
231                                                              newArguments);
232     },
233
234     /**
235      * Method: addTile
236      * addTile creates a tile, initializes it, and adds it to the layer div. 
237      *
238      * Parameters:
239      * bounds - {<OpenLayers.Bounds>}
240      * position - {<OpenLayers.Pixel>}
241      * 
242      * Returns:
243      * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
244      */
245     addTile:function(bounds,position) {
246         return new OpenLayers.Tile.Image(this, position, bounds, 
247                                          null, this.tileSize);
248     },
249
250     
251     CLASS_NAME: "OpenLayers.Layer.ArcGIS93Rest"
252 });