SHCTiledMapServiceLayer.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. var __extends = (this && this.__extends) || (function() {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({
  4. __proto__: []
  5. }
  6. instanceof Array && function(d, b) {
  7. d.__proto__ = b;
  8. }) ||
  9. function(d, b) {
  10. for (var p in b)
  11. if (b.hasOwnProperty(p)) d[p] = b[p];
  12. };
  13. return function(d, b) {
  14. extendStatics(d, b);
  15. function __() {
  16. this.constructor = d;
  17. }
  18. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  19. };
  20. })();
  21. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  22. var c = arguments.length,
  23. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  24. d;
  25. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  26. else
  27. for (var i = decorators.length - 1; i >= 0; i--)
  28. if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  29. return c > 3 && r && Object.defineProperty(target, key, r), r;
  30. };
  31. define([
  32. "require",
  33. "exports",
  34. "esri/core/tsSupport/declareExtendsHelper",
  35. "esri/core/tsSupport/decorateHelper",
  36. "esri/core/accessorSupport/decorators",
  37. "esri/geometry/Extent",
  38. "esri/layers/BaseTileLayer",
  39. "esri/layers/support/TileInfo",
  40. "esri/geometry/SpatialReference",
  41. "dojo/promise/all",
  42. "esri/request"
  43. ], function(require, exports, __extends, __decorate, decorators, Extent, BaseTileLayer, TileInfo, SpatialReference, all, esriRequest) {
  44. "use strict";
  45. return function(_super) {
  46. function SHCTiledMapServiceLayer() {
  47. var _self = _super.call(this) || this;
  48. _self.url = null;
  49. _self.fullExtent = null;
  50. _self.token = null;
  51. _self.spatialReference = SpatialReference.WebMercator;
  52. _self.tileInfo =
  53. new TileInfo({
  54. "dpi": 96,
  55. "format": "png",
  56. "spatialReference": SpatialReference.WebMercator,
  57. "size": [512, 512],
  58. "size2": [512, 512],
  59. "origin": {
  60. "x": -66000,
  61. "y": 75000
  62. },
  63. "origin2": {
  64. "x": -66000,
  65. "y": 75000
  66. },
  67. "lods": [{
  68. "level": 0,
  69. "resolution": 270.93387520108377,
  70. "scale": 1024000
  71. }, {
  72. "level": 1,
  73. "resolution": 135.46693760054188,
  74. "scale": 512000
  75. }, {
  76. "level": 2,
  77. "resolution": 67.73346880027094,
  78. "scale": 256000
  79. }, {
  80. "level": 3,
  81. "resolution": 33.86673440013547,
  82. "scale": 128000
  83. }, {
  84. "level": 4,
  85. "resolution": 16.933367200067735,
  86. "scale": 64000
  87. }, {
  88. "level": 5,
  89. "resolution": 8.466683600033868,
  90. "scale": 32000
  91. }, {
  92. "level": 6,
  93. "resolution": 4.233341800016934,
  94. "scale": 16000
  95. }, {
  96. "level": 7,
  97. "resolution": 2.116670900008467,
  98. "scale": 8000
  99. }, {
  100. "level": 8,
  101. "resolution": 1.0583354500042335,
  102. "scale": 4000
  103. }, {
  104. "level": 9,
  105. "resolution": 0.5291677250021167,
  106. "scale": 2000
  107. }, {
  108. "level": 10,
  109. "resolution": 0.26458386250105836,
  110. "scale": 1000
  111. }, {
  112. "level": 11,
  113. "resolution": 0.13229193125052918,
  114. "scale": 500
  115. }],
  116. "lods2": [{
  117. "level": 0,
  118. "resolution": 132.2919312505292,
  119. "scale": 500000
  120. }, {
  121. "level": 1,
  122. "resolution": 52.91677250021167,
  123. "scale": 200000
  124. }, {
  125. "level": 2,
  126. "resolution": 26.458386250105836,
  127. "scale": 100000
  128. }, {
  129. "level": 3,
  130. "resolution": 13.229193125052918,
  131. "scale": 50000
  132. }, {
  133. "level": 4,
  134. "resolution": 5.291677250021167,
  135. "scale": 20000
  136. }, {
  137. "level": 5,
  138. "resolution": 2.6458386250105836,
  139. "scale": 10000
  140. }, {
  141. "level": 6,
  142. "resolution": 1.3229193125052918,
  143. "scale": 5000
  144. }, {
  145. "level": 7,
  146. "resolution": 0.5291677250021167,
  147. "scale": 2000
  148. }, {
  149. "level": 8,
  150. "resolution": 0.26458386250105836,
  151. "scale": 1000
  152. }, {
  153. "level": 9,
  154. "resolution": 0.13229193125052918,
  155. "scale": 500
  156. }],
  157. "lodsLevelMapping": {
  158. "0": 0, //500000, //1024000
  159. "1": 0, //500000, //512000
  160. "2": 1, //200000, //256000
  161. "3": 2, //100000, //128000
  162. "4": 3, //50000, //64000
  163. "5": 4, //20000, //32000
  164. "6": 5, //10000, //16000
  165. "7": 5, //10000, //8000
  166. "8": 6, //5000, //4000
  167. "9": 7, //2000, //2000
  168. "10": 8, //1000//1000
  169. "11": 9 //500//500
  170. }
  171. });
  172. return _self;
  173. };
  174. __extends(SHCTiledMapServiceLayer, _super);
  175. SHCTiledMapServiceLayer.prototype._getTile = function(level, row, col, options) {
  176. var lt_x = this.tileInfo.origin.x + col * this.tileInfo.lods[level].resolution * this.tileInfo.size[0];
  177. var lt_y = this.tileInfo.origin.y - (row * this.tileInfo.lods[level].resolution * this.tileInfo.size[1]);
  178. var rb_x = this.tileInfo.origin.x + (col + 1) * this.tileInfo.lods[level].resolution * this.tileInfo.size[0];
  179. var rb_y = this.tileInfo.origin.y - ((row + 1) * this.tileInfo.lods[level].resolution * this.tileInfo.size[1]);
  180. var _level = this.tileInfo.lodsLevelMapping[level.toString()];
  181. var mapdistance = this.tileInfo.lods2[_level].resolution * this.tileInfo.size2[0];
  182. var scaleRatio = this.tileInfo.lods[level].scale / this.tileInfo.lods2[_level].scale;
  183. var fromCol = Math.floor((lt_x - this.tileInfo.origin2.x) / mapdistance);
  184. var fromRow = Math.floor((this.tileInfo.origin2.y - lt_y) / mapdistance);
  185. var toCol = Math.floor((rb_x - this.tileInfo.origin2.x) / mapdistance);
  186. var toRow = Math.floor((this.tileInfo.origin2.y - rb_y) / mapdistance);
  187. var cols = (toCol - fromCol + 1);
  188. var rows = (toRow - fromRow + 1);
  189. var bigCanvas = document.createElement("canvas");
  190. var bigContext = bigCanvas.getContext("2d");
  191. bigCanvas.width = this.tileInfo.size[0] * cols;;
  192. bigCanvas.height = this.tileInfo.size[0] * rows;
  193. var imageSize = this.tileInfo.size[0];
  194. var fetchTileImageDef = function(url, row, col, options) {
  195. if (level < 2) {
  196. return esriRequest(url, {
  197. responseType: "image",
  198. allowImageDataAccess: true,
  199. signal: options.signal
  200. }).then(function(response) {
  201. var tileImage = response.data;
  202. bigContext.drawImage(tileImage, col * imageSize, row * imageSize, imageSize, imageSize);
  203. }, function(error) {
  204. return null;
  205. });
  206. }
  207. else {
  208. return esriRequest(url, {
  209. responseType: "image",
  210. allowImageDataAccess: true,
  211. signal: options.signal
  212. }).then(function(response) {
  213. var tileImage = response.data;
  214. bigContext.drawImage(tileImage, col * imageSize, row * imageSize, imageSize, imageSize);
  215. });
  216. }
  217. }
  218. var tileUrls = [];
  219. var fetchTileImageDefs = [];
  220. for (var jRow = fromRow; jRow <= toRow; jRow++) {
  221. tileUrls[jRow - fromRow] = [];
  222. for (var iCol = fromCol; iCol <= toCol; iCol++) {
  223. var _url = this.url + "/tile/" + _level + "/" + jRow + "/" + iCol;
  224. if (this.token != null)
  225. _url += "?token=" + this.token;
  226. tileUrls[jRow - fromRow][iCol - fromCol] = _url
  227. fetchTileImageDefs.push(fetchTileImageDef(_url, jRow - fromRow, iCol - fromCol, options));
  228. }
  229. }
  230. return all(fetchTileImageDefs).then(function(results) {
  231. var _xRatio = (lt_x - this.tileInfo.origin2.x) / mapdistance - Math.floor((lt_x - this.tileInfo.origin2.x) / mapdistance);
  232. var _yRatio = (this.tileInfo.origin2.y - lt_y) / mapdistance - Math.floor((this.tileInfo.origin2.y - lt_y) / mapdistance);
  233. var _x = Math.round(_xRatio * this.tileInfo.size[0]);
  234. var _y = Math.round(_yRatio * this.tileInfo.size[0]);
  235. var smallCanvas = document.createElement("canvas");
  236. var smallContext = smallCanvas.getContext("2d");
  237. smallCanvas.width = this.tileInfo.size[0];
  238. smallCanvas.height = this.tileInfo.size[0];
  239. var _imageSize = Math.round(imageSize * scaleRatio);
  240. smallContext.drawImage(bigCanvas, _x, _y, _imageSize, _imageSize, 0, 0, imageSize, imageSize);
  241. return smallCanvas;
  242. }.bind(this));
  243. };
  244. SHCTiledMapServiceLayer.prototype.fetchTile = function(level, row, col, options) {
  245. if (level <= 11) {
  246. return this._getTile(level, row, col, options);
  247. }
  248. };
  249. Object.defineProperty(SHCTiledMapServiceLayer.prototype, "copyright", {
  250. get: function() {
  251. return "Powered by Fandango";
  252. },
  253. enumerable: false,
  254. configurable: false
  255. });
  256. __decorate([decorators.property({
  257. type: String,
  258. readOnly: true,
  259. json: {
  260. read: false,
  261. write: false
  262. }
  263. })], SHCTiledMapServiceLayer.prototype, "copyright", null);
  264. return SHCTiledMapServiceLayer = __decorate([decorators.subclass("SHCTiledMapServiceLayer")], SHCTiledMapServiceLayer);
  265. }(decorators.declared(BaseTileLayer));
  266. });