ArcGIS93Rest.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /**
  2. * @requires SuperMap/Layer/CanvasLayer.js
  3. * @requires SuperMap/Layer/Grid.js
  4. * @requires SuperMap/Tile/Image.js
  5. */
  6. /**
  7. * Class: SuperMap.Layer.ArcGIS93Rest
  8. * ArcGIS服务图层类。
  9. * 用于显示ArcGIS Server 9.3的地图,使用<SuperMap.Layer.ArcGIS93Rest>的
  10. * 构造函数可以创建ArcGIS93Rest图层,更多信息查看:
  11. * http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/index.html ;
  12. *
  13. *
  14. *
  15. * Inherits from:
  16. * - <SuperMap.Layer.CanvasLayer>
  17. */
  18. SuperMap.Layer.ArcGIS93Rest = SuperMap.Class(SuperMap.CanvasLayer, {
  19. /**
  20. * Constant: DEFAULT_PARAMS
  21. * {Object} Hashtable of default parameter key/value pairs
  22. */
  23. DEFAULT_PARAMS: {
  24. format: "png"
  25. },
  26. /**
  27. * APIProperty: isBaseLayer
  28. * {Boolean} 是否为底图(默认为true)
  29. */
  30. isBaseLayer: true,
  31. /**
  32. * Property: attribution
  33. * {String} The layer attribution.
  34. */
  35. attribution: "Data By <a style='white-space: nowrap' target='_blank' href='http://www.arcgisonline.cn/'>ESRI</a>",
  36. /**
  37. * Constructor: SuperMap.Layer.ArcGIS93Rest
  38. * 创建ArcGIS93Rest图层
  39. *
  40. * Example:
  41. * (code)
  42. *
  43. * var arcims = new SuperMap.Layer.ArcGIS93Rest("MyName",
  44. * "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer/export",
  45. * {
  46. * layers: "show:0,1,2"
  47. * });
  48. * (end)
  49. *
  50. * Parameters:
  51. * name - {String} 图层名称
  52. * url - {String} ArcGIS的REST服务url地址,服务地址目录为http://sampleserver1.arcgisonline.com/ArcGIS/rest/services
  53. * 或者http://www.arcgisonline.cn/ArcGIS/rest/services等,在目录下可以找到需要的具体服务
  54. * params - {Object} 设置到url上的可选参数。
  55. * options - {Object} 此类及其父类开放的属性。
  56. *
  57. * Allowed params properties:
  58. * layers - {String} 设置需要出现在导出地图中的图层。有四种方法来指定哪些图层需要显示:
  59. * show(只有在此列表中指定的图层才能用于出图);
  60. * hide(除了在此列表中的所有图层都将用于出图);
  61. * include(在默认图层外,额外增加的图层);
  62. * exclude(在默认图层内部排除掉的图层);
  63. *
  64. * Allowed options properties:
  65. * useCanvas - {Boolean} 是否使用Canvas绘制
  66. */
  67. initialize: function(name, url, params, options) {
  68. var me=this,newArguments = [];
  69. //将params参数转换为大写
  70. params = SuperMap.Util.upperCaseObject(params);
  71. newArguments.push(name, url, params, options);
  72. SuperMap.CanvasLayer.prototype.initialize.apply(me, newArguments);
  73. SuperMap.Util.applyDefaults(me.params, SuperMap.Util.upperCaseObject(me.DEFAULT_PARAMS));
  74. //layer is transparent
  75. //如下代码暂不考虑
  76. if (this.params.TRANSPARENT &&
  77. this.params.TRANSPARENT.toString().toLowerCase() == "true") {
  78. // unless explicitly set in options, make layer an overlay
  79. if ( (options == null) || (!options.isBaseLayer) ) {
  80. this.isBaseLayer = false;
  81. }
  82. // jpegs can never be transparent, so intelligently switch the
  83. // format, depending on the browser's capabilities
  84. if (this.params.FORMAT == "jpg") {
  85. this.params.FORMAT = SuperMap.Util.alphaHack() ? "gif"
  86. : "png";
  87. }
  88. }
  89. },
  90. /**
  91. * APIMethod: destroy
  92. * 解构ArcGIS93Rest类,释放资源。
  93. */
  94. destroy: function() {
  95. // for now, nothing special to do here.
  96. SuperMap.CanvasLayer.prototype.destroy.apply(this, arguments);
  97. },
  98. /**
  99. * APIMethod: clone
  100. * 创建当前图层的副本
  101. * Parameters:
  102. * obj - {Object}
  103. * Returns:
  104. * {<SuperMap.Layer.ArcGIS93Rest>}
  105. */
  106. clone: function (obj) {
  107. if (obj == null) {
  108. obj = new SuperMap.Layer.ArcGIS93Rest(this.name,
  109. this.url,
  110. this.params,
  111. this.getOptions());
  112. }
  113. //get all additions from superclasses
  114. obj = SuperMap.CanvasLayer.prototype.clone.apply(this, [obj]);
  115. // copy/set any non-init, non-simple values here
  116. return obj;
  117. },
  118. /**
  119. * Method: getURL
  120. * 获取瓦片的URL。
  121. *
  122. * Parameters:
  123. * bounds - {<SuperMap.Bounds>} 瓦片的bounds。
  124. *
  125. * Returns:
  126. * {String} 瓦片的URL
  127. */
  128. getURL: function (bounds) {
  129. bounds = this.adjustBounds(bounds);
  130. // ArcGIS Server only wants the numeric portion of the projection ID.
  131. var projWords = this.projection.getCode().split(":");
  132. var srid = projWords[projWords.length - 1];
  133. var imageSize = this.getImageSize();
  134. //基于需求的考虑,很多参数都是默认的,并没有公开出来,
  135. // 以后有用得到的时候在这里修改,也可能会在此类里面添加几个属性来初始化
  136. //
  137. var newParams = {
  138. 'BBOX': bounds.toBBOX(),
  139. 'SIZE': imageSize.w + "," + imageSize.h,
  140. // We always want image, the other options were json, image with a whole lotta html around it, etc.
  141. 'F': "image",
  142. 'BBOXSR': srid,
  143. 'IMAGESR': srid
  144. };
  145. // Now add the filter parameters.
  146. //设置图层筛选参数
  147. if (this.layerDefs) {
  148. var layerDefStrList = [];
  149. var layerID;
  150. for(layerID in this.layerDefs) {
  151. if (this.layerDefs.hasOwnProperty(layerID)) {
  152. if (this.layerDefs[layerID]) {
  153. layerDefStrList.push(layerID);
  154. layerDefStrList.push(":");
  155. layerDefStrList.push(this.layerDefs[layerID]);
  156. layerDefStrList.push(";");
  157. }
  158. }
  159. }
  160. if (layerDefStrList.length > 0) {
  161. newParams['LAYERDEFS'] = layerDefStrList.join("");
  162. }
  163. }
  164. var requestString = this.getFullRequestString(newParams);
  165. return requestString;
  166. },
  167. /**
  168. * Method: setLayerFilter
  169. * 在创建瓦片的时候修改layerDefs参数
  170. * Parameters:
  171. * id - {String} 对应的图层id
  172. * queryDef - {String} 需要替代以前参数的描述,
  173. * layerDefs主要用于筛选某个图层里面的信息,
  174. * 以便确定在出图的时候确定需要显示哪些信息,详情请查看:
  175. * http://sampleserver1.arcgisonline.com/ArcGIS/SDK/REST/export.html
  176. */
  177. setLayerFilter: function ( id, queryDef ) {
  178. if (!this.layerDefs) {
  179. this.layerDefs = {};
  180. }
  181. if (queryDef) {
  182. this.layerDefs[id] = queryDef;
  183. } else {
  184. delete this.layerDefs[id];
  185. }
  186. },
  187. /**
  188. * Method: clearLayerFilter
  189. * 清除参数layerDefs
  190. *
  191. * Parameters:
  192. * id - {String} 需要清除的图层的id
  193. */
  194. clearLayerFilter: function ( id ) {
  195. if (id) {
  196. delete this.layerDefs[id];
  197. } else {
  198. delete this.layerDefs;
  199. }
  200. },
  201. /**
  202. * Method: mergeNewParams
  203. * 动态的给基类创建一个params参数转换方法
  204. *
  205. *
  206. * 当params改变时将这些参数转换为大写
  207. *
  208. * Parameters:
  209. * newParams - {Object} 新改变的params参数
  210. */
  211. mergeNewParams:function(newParams) {
  212. var upperParams = SuperMap.Util.upperCaseObject(newParams);
  213. var newArguments = [upperParams];
  214. return SuperMap.CanvasLayer.prototype.mergeNewParams.apply(this,
  215. newArguments);
  216. },
  217. CLASS_NAME: "SuperMap.Layer.ArcGIS93Rest"
  218. });