SHCMapServiceLayer.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 SHCMapServiceLayer() {
  47. var _self = _super.call(this) || this;
  48. _self.token = null;
  49. _self.tileInfo =
  50. new TileInfo({
  51. "dpi": 96,
  52. "format": "png",
  53. "spatialReference": SpatialReference.WebMercator,
  54. "size": [512, 512],
  55. "origin": {
  56. "x": -66000,
  57. "y": 75000
  58. },
  59. "lods": [{
  60. "level": 0,
  61. "resolution": 270.93387520108377,
  62. "scale": 1024000
  63. }, {
  64. "level": 1,
  65. "resolution": 135.46693760054188,
  66. "scale": 512000
  67. }, {
  68. "level": 2,
  69. "resolution": 67.73346880027094,
  70. "scale": 256000
  71. }, {
  72. "level": 3,
  73. "resolution": 33.86673440013547,
  74. "scale": 128000
  75. }, {
  76. "level": 4,
  77. "resolution": 16.933367200067735,
  78. "scale": 64000
  79. }, {
  80. "level": 5,
  81. "resolution": 8.466683600033868,
  82. "scale": 32000
  83. }, {
  84. "level": 6,
  85. "resolution": 4.233341800016934,
  86. "scale": 16000
  87. }, {
  88. "level": 7,
  89. "resolution": 2.116670900008467,
  90. "scale": 8000
  91. }, {
  92. "level": 8,
  93. "resolution": 1.0583354500042335,
  94. "scale": 4000
  95. }, {
  96. "level": 9,
  97. "resolution": 0.5291677250021167,
  98. "scale": 2000
  99. }, {
  100. "level": 10,
  101. "resolution": 0.26458386250105836,
  102. "scale": 1000
  103. }, {
  104. "level": 11,
  105. "resolution": 0.13229193125052918,
  106. "scale": 500
  107. }],
  108. });
  109. return _self;
  110. };
  111. __extends(SHCMapServiceLayer, _super);
  112. SHCMapServiceLayer.prototype._getTileUrl = function(level, row, col) {
  113. var lt_x = this.tileInfo.origin.x + col * this.tileInfo.lods[level].resolution * this.tileInfo.size[0];
  114. var lt_y = this.tileInfo.origin.y - (row * this.tileInfo.lods[level].resolution * this.tileInfo.size[1]);
  115. var rb_x = this.tileInfo.origin.x + (col + 1) * this.tileInfo.lods[level].resolution * this.tileInfo.size[0];
  116. var rb_y = this.tileInfo.origin.y - ((row + 1) * this.tileInfo.lods[level].resolution * this.tileInfo.size[1]);
  117. var bbox = lt_x + "," + rb_y + "," + rb_x + "," + lt_y
  118. return this.url + "/export?bbox=" + bbox + "&size=" + this.tileInfo.size[0] + "," + this.tileInfo.size[1]
  119. + "&bboxSR=" + "" + "&imageSR=" + ""
  120. + "&dpi=96&format=png&transparent=true&layerDefs=&time=&layerTimeOptions=&dynamicLayers=&gdbVersion=&mapScale=&f=image";
  121. if (this.token != null)
  122. _url += "?token=" + this.token;
  123. };
  124. SHCMapServiceLayer.prototype.fetchTile = function(level, row, col, options) {
  125. var url = this._getTileUrl(level, row, col);
  126. return esriRequest(url, {
  127. responseType: "image",
  128. allowImageDataAccess: true,
  129. signal: options.signal
  130. })
  131. .then(function(response) {
  132. var image = response.data;
  133. var width = this.tileInfo.size[0];
  134. var height = this.tileInfo.size[0];
  135. var canvas = document.createElement("canvas");
  136. var context = canvas.getContext("2d");
  137. canvas.width = width;
  138. canvas.height = height;
  139. context.drawImage(image, 0, 0, width, height);
  140. return canvas;
  141. }.bind(this));
  142. };
  143. return SHCMapServiceLayer = __decorate([decorators.subclass("SHCMapServiceLayer")], SHCMapServiceLayer);
  144. }(decorators.declared(BaseTileLayer));
  145. });