@itwin/map-layers-formats 4.0.0-dev.51 → 4.0.0-dev.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/.rush/temp/a8c23e019445581f5d72733a882cf95a9917fdfd.log +10 -0
  2. package/.rush/temp/operation/build_ci/state.json +1 -1
  3. package/.rush/temp/operation/cover/state.json +1 -1
  4. package/.rush/temp/operation/docs/state.json +1 -1
  5. package/.rush/temp/package-deps_cover.json +3 -3
  6. package/.rush/temp/package-deps_docs.json +3 -3
  7. package/.rush/temp/shrinkwrap-deps.json +43 -50
  8. package/lib/cjs/ArcGisFeature/ArcGisFeatureFormat.d.ts +8 -8
  9. package/lib/cjs/ArcGisFeature/ArcGisFeatureFormat.js +14 -14
  10. package/lib/cjs/ArcGisFeature/ArcGisFeatureFormat.js.map +1 -1
  11. package/lib/cjs/ArcGisFeature/ArcGisFeatureJSON.d.ts +14 -14
  12. package/lib/cjs/ArcGisFeature/ArcGisFeatureJSON.js +132 -132
  13. package/lib/cjs/ArcGisFeature/ArcGisFeatureJSON.js.map +1 -1
  14. package/lib/cjs/ArcGisFeature/ArcGisFeaturePBF.d.ts +14 -14
  15. package/lib/cjs/ArcGisFeature/ArcGisFeaturePBF.js +200 -200
  16. package/lib/cjs/ArcGisFeature/ArcGisFeaturePBF.js.map +1 -1
  17. package/lib/cjs/ArcGisFeature/ArcGisFeatureProvider.d.ts +44 -44
  18. package/lib/cjs/ArcGisFeature/ArcGisFeatureProvider.js +421 -421
  19. package/lib/cjs/ArcGisFeature/ArcGisFeatureProvider.js.map +1 -1
  20. package/lib/cjs/ArcGisFeature/ArcGisFeatureQuery.d.ts +92 -92
  21. package/lib/cjs/ArcGisFeature/ArcGisFeatureQuery.d.ts.map +1 -1
  22. package/lib/cjs/ArcGisFeature/ArcGisFeatureQuery.js +82 -82
  23. package/lib/cjs/ArcGisFeature/ArcGisFeatureQuery.js.map +1 -1
  24. package/lib/cjs/ArcGisFeature/ArcGisFeatureReader.d.ts +17 -17
  25. package/lib/cjs/ArcGisFeature/ArcGisFeatureReader.js +33 -33
  26. package/lib/cjs/ArcGisFeature/ArcGisFeatureReader.js.map +1 -1
  27. package/lib/cjs/ArcGisFeature/ArcGisFeatureRenderer.d.ts +32 -32
  28. package/lib/cjs/ArcGisFeature/ArcGisFeatureRenderer.js +142 -142
  29. package/lib/cjs/ArcGisFeature/ArcGisFeatureRenderer.js.map +1 -1
  30. package/lib/cjs/ArcGisFeature/ArcGisFeatureResponse.d.ts +16 -16
  31. package/lib/cjs/ArcGisFeature/ArcGisFeatureResponse.d.ts.map +1 -1
  32. package/lib/cjs/ArcGisFeature/ArcGisFeatureResponse.js +42 -42
  33. package/lib/cjs/ArcGisFeature/ArcGisFeatureResponse.js.map +1 -1
  34. package/lib/cjs/ArcGisFeature/ArcGisSymbologyRenderer.d.ts +85 -85
  35. package/lib/cjs/ArcGisFeature/ArcGisSymbologyRenderer.d.ts.map +1 -1
  36. package/lib/cjs/ArcGisFeature/ArcGisSymbologyRenderer.js +189 -189
  37. package/lib/cjs/ArcGisFeature/ArcGisSymbologyRenderer.js.map +1 -1
  38. package/lib/cjs/ArcGisFeature/esriPBuffer.gen.d.ts +1063 -1063
  39. package/lib/cjs/ArcGisFeature/esriPBuffer.gen.js +2270 -2270
  40. package/lib/cjs/ArcGisFeature/esriPBuffer.gen.js.map +1 -1
  41. package/lib/cjs/map-layers-formats.d.ts +8 -8
  42. package/lib/cjs/map-layers-formats.js +28 -24
  43. package/lib/cjs/map-layers-formats.js.map +1 -1
  44. package/lib/cjs/mapLayersFormats.d.ts +10 -10
  45. package/lib/cjs/mapLayersFormats.js +28 -28
  46. package/lib/cjs/mapLayersFormats.js.map +1 -1
  47. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureFeatureFormats.test.d.ts +1 -1
  48. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureFeatureFormats.test.js +34 -34
  49. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureFeatureFormats.test.js.map +1 -1
  50. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureJSON.test.d.ts +1 -1
  51. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureJSON.test.js +161 -161
  52. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureJSON.test.js.map +1 -1
  53. package/lib/cjs/test/ArcGisFeature/ArcGisFeaturePBF.test.d.ts +1 -1
  54. package/lib/cjs/test/ArcGisFeature/ArcGisFeaturePBF.test.js +167 -167
  55. package/lib/cjs/test/ArcGisFeature/ArcGisFeaturePBF.test.js.map +1 -1
  56. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureProvider.test.d.ts +1 -1
  57. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureProvider.test.js +679 -679
  58. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureProvider.test.js.map +1 -1
  59. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureQuery.test.d.ts +1 -1
  60. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureQuery.test.js +103 -103
  61. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureQuery.test.js.map +1 -1
  62. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureRenderer.test.d.ts +1 -1
  63. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureRenderer.test.js +214 -214
  64. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureRenderer.test.js.map +1 -1
  65. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureResponse.test.d.ts +1 -1
  66. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureResponse.test.js +94 -94
  67. package/lib/cjs/test/ArcGisFeature/ArcGisFeatureResponse.test.js.map +1 -1
  68. package/lib/cjs/test/ArcGisFeature/ArcGisSymbologyRenderer.test.d.ts +1 -1
  69. package/lib/cjs/test/ArcGisFeature/ArcGisSymbologyRenderer.test.js +59 -59
  70. package/lib/cjs/test/ArcGisFeature/ArcGisSymbologyRenderer.test.js.map +1 -1
  71. package/lib/cjs/test/ArcGisFeature/Mocks.d.ts +6 -6
  72. package/lib/cjs/test/ArcGisFeature/Mocks.js +18 -18
  73. package/lib/cjs/test/ArcGisFeature/Mocks.js.map +1 -1
  74. package/lib/cjs/test/ArcGisFeature/NewYorkDataset.d.ts +55 -55
  75. package/lib/cjs/test/ArcGisFeature/NewYorkDataset.js +419 -419
  76. package/lib/cjs/test/ArcGisFeature/NewYorkDataset.js.map +1 -1
  77. package/lib/cjs/test/ArcGisFeature/PhillyLandmarksDataset.d.ts +1042 -1042
  78. package/lib/cjs/test/ArcGisFeature/PhillyLandmarksDataset.js +426 -426
  79. package/lib/cjs/test/ArcGisFeature/PhillyLandmarksDataset.js.map +1 -1
  80. package/lib/cjs/test/coverage/.nyc_output/ebb32643-cc7e-45e5-85fa-6677a4e8655d.json +1 -0
  81. package/lib/cjs/test/coverage/.nyc_output/processinfo/4b88e819-fa82-47fe-ba3f-d8d412881c57.json +1 -0
  82. package/lib/cjs/test/coverage/.nyc_output/processinfo/{b5bab329-e30c-4d54-833d-0f3805415aca.json → ebb32643-cc7e-45e5-85fa-6677a4e8655d.json} +1 -1
  83. package/lib/cjs/test/coverage/.nyc_output/processinfo/index.json +1 -1
  84. package/lib/cjs/test/coverage/cobertura-coverage.xml +38 -38
  85. package/lib/cjs/test/coverage/lcov-report/index.html +1 -1
  86. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/ArcGisFeatureFormat.ts.html +1 -1
  87. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/ArcGisFeatureJSON.ts.html +1 -1
  88. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/ArcGisFeaturePBF.ts.html +1 -1
  89. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/ArcGisFeatureProvider.ts.html +1 -1
  90. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/ArcGisFeatureQuery.ts.html +1 -1
  91. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/ArcGisFeatureReader.ts.html +1 -1
  92. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/ArcGisFeatureRenderer.ts.html +1 -1
  93. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/ArcGisFeatureResponse.ts.html +1 -1
  94. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/ArcGisSymbologyRenderer.ts.html +1 -1
  95. package/lib/cjs/test/coverage/lcov-report/src/ArcGisFeature/index.html +1 -1
  96. package/lib/cjs/test/coverage/lcov-report/src/index.html +1 -1
  97. package/lib/cjs/test/coverage/lcov-report/src/map-layers-formats.ts.html +1 -1
  98. package/lib/cjs/test/coverage/lcov-report/src/mapLayersFormats.ts.html +1 -1
  99. package/lib/cjs/test/coverage/lcov.info +47 -47
  100. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  101. package/lib/esm/ArcGisFeature/ArcGisFeatureFormat.d.ts +8 -8
  102. package/lib/esm/ArcGisFeature/ArcGisFeatureFormat.js +11 -10
  103. package/lib/esm/ArcGisFeature/ArcGisFeatureFormat.js.map +1 -1
  104. package/lib/esm/ArcGisFeature/ArcGisFeatureJSON.d.ts +14 -14
  105. package/lib/esm/ArcGisFeature/ArcGisFeatureJSON.js +128 -128
  106. package/lib/esm/ArcGisFeature/ArcGisFeatureJSON.js.map +1 -1
  107. package/lib/esm/ArcGisFeature/ArcGisFeaturePBF.d.ts +14 -14
  108. package/lib/esm/ArcGisFeature/ArcGisFeaturePBF.js +196 -196
  109. package/lib/esm/ArcGisFeature/ArcGisFeaturePBF.js.map +1 -1
  110. package/lib/esm/ArcGisFeature/ArcGisFeatureProvider.d.ts +44 -44
  111. package/lib/esm/ArcGisFeature/ArcGisFeatureProvider.js +418 -417
  112. package/lib/esm/ArcGisFeature/ArcGisFeatureProvider.js.map +1 -1
  113. package/lib/esm/ArcGisFeature/ArcGisFeatureQuery.d.ts +92 -92
  114. package/lib/esm/ArcGisFeature/ArcGisFeatureQuery.d.ts.map +1 -1
  115. package/lib/esm/ArcGisFeature/ArcGisFeatureQuery.js +78 -78
  116. package/lib/esm/ArcGisFeature/ArcGisFeatureQuery.js.map +1 -1
  117. package/lib/esm/ArcGisFeature/ArcGisFeatureReader.d.ts +17 -17
  118. package/lib/esm/ArcGisFeature/ArcGisFeatureReader.js +29 -29
  119. package/lib/esm/ArcGisFeature/ArcGisFeatureReader.js.map +1 -1
  120. package/lib/esm/ArcGisFeature/ArcGisFeatureRenderer.d.ts +32 -32
  121. package/lib/esm/ArcGisFeature/ArcGisFeatureRenderer.js +138 -138
  122. package/lib/esm/ArcGisFeature/ArcGisFeatureRenderer.js.map +1 -1
  123. package/lib/esm/ArcGisFeature/ArcGisFeatureResponse.d.ts +16 -16
  124. package/lib/esm/ArcGisFeature/ArcGisFeatureResponse.d.ts.map +1 -1
  125. package/lib/esm/ArcGisFeature/ArcGisFeatureResponse.js +38 -38
  126. package/lib/esm/ArcGisFeature/ArcGisFeatureResponse.js.map +1 -1
  127. package/lib/esm/ArcGisFeature/ArcGisSymbologyRenderer.d.ts +85 -85
  128. package/lib/esm/ArcGisFeature/ArcGisSymbologyRenderer.d.ts.map +1 -1
  129. package/lib/esm/ArcGisFeature/ArcGisSymbologyRenderer.js +183 -182
  130. package/lib/esm/ArcGisFeature/ArcGisSymbologyRenderer.js.map +1 -1
  131. package/lib/esm/ArcGisFeature/esriPBuffer.gen.d.ts +1063 -1063
  132. package/lib/esm/ArcGisFeature/esriPBuffer.gen.js +2267 -2267
  133. package/lib/esm/ArcGisFeature/esriPBuffer.gen.js.map +1 -1
  134. package/lib/esm/map-layers-formats.d.ts +8 -8
  135. package/lib/esm/map-layers-formats.js +12 -12
  136. package/lib/esm/map-layers-formats.js.map +1 -1
  137. package/lib/esm/mapLayersFormats.d.ts +10 -10
  138. package/lib/esm/mapLayersFormats.js +24 -24
  139. package/lib/esm/mapLayersFormats.js.map +1 -1
  140. package/lib/esm/test/ArcGisFeature/ArcGisFeatureFeatureFormats.test.d.ts +1 -1
  141. package/lib/esm/test/ArcGisFeature/ArcGisFeatureFeatureFormats.test.js +32 -32
  142. package/lib/esm/test/ArcGisFeature/ArcGisFeatureFeatureFormats.test.js.map +1 -1
  143. package/lib/esm/test/ArcGisFeature/ArcGisFeatureJSON.test.d.ts +1 -1
  144. package/lib/esm/test/ArcGisFeature/ArcGisFeatureJSON.test.js +159 -159
  145. package/lib/esm/test/ArcGisFeature/ArcGisFeatureJSON.test.js.map +1 -1
  146. package/lib/esm/test/ArcGisFeature/ArcGisFeaturePBF.test.d.ts +1 -1
  147. package/lib/esm/test/ArcGisFeature/ArcGisFeaturePBF.test.js +165 -165
  148. package/lib/esm/test/ArcGisFeature/ArcGisFeaturePBF.test.js.map +1 -1
  149. package/lib/esm/test/ArcGisFeature/ArcGisFeatureProvider.test.d.ts +1 -1
  150. package/lib/esm/test/ArcGisFeature/ArcGisFeatureProvider.test.js +677 -677
  151. package/lib/esm/test/ArcGisFeature/ArcGisFeatureProvider.test.js.map +1 -1
  152. package/lib/esm/test/ArcGisFeature/ArcGisFeatureQuery.test.d.ts +1 -1
  153. package/lib/esm/test/ArcGisFeature/ArcGisFeatureQuery.test.js +101 -101
  154. package/lib/esm/test/ArcGisFeature/ArcGisFeatureQuery.test.js.map +1 -1
  155. package/lib/esm/test/ArcGisFeature/ArcGisFeatureRenderer.test.d.ts +1 -1
  156. package/lib/esm/test/ArcGisFeature/ArcGisFeatureRenderer.test.js +212 -212
  157. package/lib/esm/test/ArcGisFeature/ArcGisFeatureRenderer.test.js.map +1 -1
  158. package/lib/esm/test/ArcGisFeature/ArcGisFeatureResponse.test.d.ts +1 -1
  159. package/lib/esm/test/ArcGisFeature/ArcGisFeatureResponse.test.js +92 -92
  160. package/lib/esm/test/ArcGisFeature/ArcGisFeatureResponse.test.js.map +1 -1
  161. package/lib/esm/test/ArcGisFeature/ArcGisSymbologyRenderer.test.d.ts +1 -1
  162. package/lib/esm/test/ArcGisFeature/ArcGisSymbologyRenderer.test.js +57 -57
  163. package/lib/esm/test/ArcGisFeature/ArcGisSymbologyRenderer.test.js.map +1 -1
  164. package/lib/esm/test/ArcGisFeature/Mocks.d.ts +6 -6
  165. package/lib/esm/test/ArcGisFeature/Mocks.js +15 -15
  166. package/lib/esm/test/ArcGisFeature/Mocks.js.map +1 -1
  167. package/lib/esm/test/ArcGisFeature/NewYorkDataset.d.ts +55 -55
  168. package/lib/esm/test/ArcGisFeature/NewYorkDataset.js +416 -415
  169. package/lib/esm/test/ArcGisFeature/NewYorkDataset.js.map +1 -1
  170. package/lib/esm/test/ArcGisFeature/PhillyLandmarksDataset.d.ts +1042 -1042
  171. package/lib/esm/test/ArcGisFeature/PhillyLandmarksDataset.js +423 -422
  172. package/lib/esm/test/ArcGisFeature/PhillyLandmarksDataset.js.map +1 -1
  173. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  174. package/lib/test/junit_results.xml +48 -48
  175. package/package.json +13 -13
  176. package/src/test/ArcGisFeature/ArcGisFeatureProvider.test.ts +21 -21
  177. package/.rush/temp/package-deps_build_ci.json +0 -36
  178. package/lib/cjs/test/coverage/.nyc_output/b5bab329-e30c-4d54-833d-0f3805415aca.json +0 -1
  179. package/lib/cjs/test/coverage/.nyc_output/processinfo/eb18b24f-e841-458a-a146-1d39857d2964.json +0 -1
  180. /package/lib/cjs/test/coverage/.nyc_output/{eb18b24f-e841-458a-a146-1d39857d2964.json → 4b88e819-fa82-47fe-ba3f-d8d412881c57.json} +0 -0
@@ -1,422 +1,422 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ArcGisFeatureProvider = void 0;
8
- const core_common_1 = require("@itwin/core-common");
9
- const core_bentley_1 = require("@itwin/core-bentley");
10
- const core_geometry_1 = require("@itwin/core-geometry");
11
- const core_frontend_1 = require("@itwin/core-frontend");
12
- const ArcGisSymbologyRenderer_1 = require("./ArcGisSymbologyRenderer");
13
- const ArcGisFeatureQuery_1 = require("./ArcGisFeatureQuery");
14
- const ArcGisFeatureRenderer_1 = require("./ArcGisFeatureRenderer");
15
- const ArcGisFeaturePBF_1 = require("./ArcGisFeaturePBF");
16
- const ArcGisFeatureJSON_1 = require("./ArcGisFeatureJSON");
17
- const ArcGisFeatureResponse_1 = require("./ArcGisFeatureResponse");
18
- const loggerCategory = "MapLayersFormats.ArcGISFeature";
19
- /** Provide tiles from a ESRI ArcGIS Feature service
20
- * @internal
21
- */
22
- class ArcGisFeatureProvider extends core_frontend_1.ArcGISImageryProvider {
23
- constructor(settings) {
24
- super(settings, true);
25
- // Debug flags, should always be commited to FALSE !
26
- this._drawDebugInfo = false;
27
- this._debugFeatureGeom = false;
28
- this._supportsCoordinatesQuantization = false;
29
- this._querySupported = false;
30
- this._layerId = 0;
31
- this._outSR = 102100;
32
- this._maxDepthFromLod = 0;
33
- this._minDepthFromLod = 0;
34
- }
35
- get minimumZoomLevel() { return this._minDepthFromLod; }
36
- get maximumZoomLevel() { return this._maxDepthFromLod; }
37
- async initialize() {
38
- const metadata = await this.getServiceJson();
39
- const json = metadata?.content;
40
- if (json === undefined) {
41
- core_bentley_1.Logger.logError(loggerCategory, "Could not get service JSON");
42
- throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
43
- }
44
- if (json?.error?.code === core_frontend_1.ArcGisErrorCode.TokenRequired || json?.error?.code === core_frontend_1.ArcGisErrorCode.InvalidToken) {
45
- // Check again layer status, it might have change during await.
46
- if (this.status === core_frontend_1.MapLayerImageryProviderStatus.Valid) {
47
- this.setStatus(core_frontend_1.MapLayerImageryProviderStatus.RequireAuth);
48
- return;
49
- }
50
- }
51
- if (json.capabilities) {
52
- this._querySupported = json.capabilities.indexOf("Query") >= 0;
53
- if (!this._querySupported)
54
- throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
55
- }
56
- this.serviceJson = json;
57
- let foundVisibleSubLayer = false;
58
- if (this._settings.subLayers.length >= 0) {
59
- // There is more than sub-layer for this layer, pick the first visible one.
60
- for (const layer of this._settings.subLayers) {
61
- if (layer.visible && typeof layer.id === "number") {
62
- this._layerId = layer.id;
63
- foundVisibleSubLayer = true;
64
- break;
65
- }
66
- }
67
- }
68
- if (!foundVisibleSubLayer && json !== undefined) {
69
- // No suitable sublayer was specified on the layerSettings object, lets find a default one in the capabilities
70
- // Check layer metadata
71
- if (Array.isArray(this.serviceJson.layers) && this.serviceJson.layers.length >= 1) {
72
- const hasDefaultVisibility = Object.keys(this.serviceJson.layers[0]).includes("defaultVisibility");
73
- if (hasDefaultVisibility) {
74
- for (const layer of this.serviceJson.layers) {
75
- if (layer.defaultVisibility) {
76
- this._layerId = layer.id;
77
- }
78
- }
79
- }
80
- else {
81
- // On some older servers, the default visiblity is on the layer capabilities (i.e. not the service capabilities)
82
- for (const layer of this.serviceJson.layers) {
83
- const layerJson = await this.getLayerMetadata(layer.id);
84
- if (!layerJson) {
85
- continue;
86
- }
87
- if (layerJson.defaultVisibility) {
88
- this._layerId = layer.id;
89
- this._layerMetadata = layerJson;
90
- break;
91
- }
92
- }
93
- }
94
- }
95
- else {
96
- // There is no layer to publish? Something is off with this server..
97
- throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
98
- }
99
- }
100
- // Make sure we cache layer info (i.e. rendering info)
101
- if (!this._layerMetadata) {
102
- this._layerMetadata = await this.getLayerMetadata(this._layerId);
103
- if (!this._layerMetadata) {
104
- core_bentley_1.Logger.logError(loggerCategory, "Could not layer metadata");
105
- throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
106
- }
107
- }
108
- // Parse server version
109
- let majorVersion;
110
- if (this.serviceJson?.currentVersion) {
111
- try {
112
- majorVersion = Math.trunc(this.serviceJson?.currentVersion);
113
- }
114
- catch {
115
- }
116
- }
117
- // Coordinates Quantization: If supported, server will transform for us the coordinates in the Tile coordinate space (pixels, origin = upper left corner
118
- // If not supported, transformation will be applied client side.
119
- // Note: For some reasons, even though 'supportsCoordinatesQuantization' is set to 'true' on the layer metadata, server will give an error message for server version < 11
120
- if (majorVersion && majorVersion >= 11 && this._layerMetadata.supportsCoordinatesQuantization) {
121
- this._supportsCoordinatesQuantization = true;
122
- }
123
- // Check supported query formats: JSON and PBF are currently implemented by this provider
124
- // Note: needs to be checked on the layer metadata, service metadata advertises a different set of formats
125
- // Also, since PBF format does not support floating points, there is no point using this format if supportsCoordinatesQuantization is not available.
126
- if (this._layerMetadata.supportedQueryFormats) {
127
- const formats = this._layerMetadata.supportedQueryFormats.split(", ");
128
- if (formats.includes("PBF") && this._supportsCoordinatesQuantization) {
129
- this._format = "PBF";
130
- }
131
- else if (formats.includes("JSON")) {
132
- this._format = "JSON";
133
- }
134
- }
135
- if (!this._format) {
136
- core_bentley_1.Logger.logError(loggerCategory, "Could not get request format from service JSON");
137
- throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
138
- }
139
- // Read range using full extent from service metadata
140
- if (json.fullExtent) {
141
- if (json.fullExtent.spatialReference.latestWkid === 3857 || json.fullExtent.spatialReference.wkid === 102100) {
142
- const range3857 = core_geometry_1.Range2d.createFrom({
143
- low: { x: json.fullExtent.xmin, y: json.fullExtent.ymin },
144
- high: { x: json.fullExtent.xmax, y: json.fullExtent.ymax }
145
- });
146
- const west = this.getEPSG4326Lon(range3857.xLow);
147
- const south = this.getEPSG4326Lat(range3857.yLow);
148
- const east = this.getEPSG4326Lon(range3857.xHigh);
149
- const north = this.getEPSG4326Lat(range3857.yHigh);
150
- this.cartoRange = core_frontend_1.MapCartoRectangle.fromDegrees(west, south, east, north);
151
- }
152
- }
153
- // Check for minScale / max scale
154
- const minScale = this._layerMetadata?.minScale || undefined; // undefined, 0 -> undefined
155
- const maxScale = this._layerMetadata?.maxScale || undefined; // undefined, 0 -> undefined
156
- const scales = core_frontend_1.ArcGisUtilities.getZoomLevelsScales(this.defaultMaximumZoomLevel, this.tileSize, minScale, maxScale, 1.0);
157
- if (scales.minLod)
158
- this._minDepthFromLod = scales.minLod;
159
- // Some servers advertises a max LOD of 0, it should be interpreted as 'not defined' (otherwise a max lod of 0 would would mean never display anything)
160
- this._maxDepthFromLod = (scales.maxLod ? scales.maxLod : this.defaultMaximumZoomLevel);
161
- this._symbologyRenderer = new ArcGisSymbologyRenderer_1.ArcGisSymbologyRenderer(this._layerMetadata?.geometryType, this._layerMetadata?.drawingInfo?.renderer);
162
- }
163
- async getLayerMetadata(layerId) {
164
- let metadata;
165
- try {
166
- const url = new URL(this._settings.url);
167
- url.pathname = `${url.pathname}/${layerId}`;
168
- metadata = await core_frontend_1.ArcGisUtilities.getServiceJson(url.toString(), this._settings.formatId, this._settings.userName, this._settings.password, this._accessTokenRequired);
169
- }
170
- catch {
171
- }
172
- return metadata?.content;
173
- }
174
- get tileSize() { return 512; }
175
- get format() { return this._format; }
176
- // We don't use this method inside this provider (see constructFeatureUrl), but since this is an abstract method, we need to define something
177
- async constructUrl(_row, _column, _zoomLevel) {
178
- return "";
179
- }
180
- constructFeatureUrl(row, column, zoomLevel, format, geomOverride, outFields, tolerance, returnGeometry) {
181
- const tileExtent = this.getEPSG3857Extent(row, column, zoomLevel);
182
- const tileEnvelope = {
183
- xmin: tileExtent.left, ymin: tileExtent.bottom,
184
- xmax: tileExtent.right, ymax: tileExtent.top,
185
- spatialReference: { wkid: 102100, latestWkid: 3857 },
186
- };
187
- // Actual spatial filter.
188
- // By default, we request the tile extent. If 'cartoPoint' is specified,
189
- // we restrict the spatial to specific point. (i.e. GetFeatureInfo requests)
190
- // If envelope is provided, it has the priority over 'cartoPoint'
191
- let geometry;
192
- if (geomOverride) {
193
- geometry = geomOverride;
194
- }
195
- else {
196
- geometry = { geom: tileEnvelope, type: "esriGeometryEnvelope" };
197
- }
198
- let quantizationParameters;
199
- const toleranceWorld = (tileExtent.top - tileExtent.bottom) / this.tileSize;
200
- if (this._supportsCoordinatesQuantization) {
201
- quantizationParameters = {
202
- mode: "view",
203
- originPosition: "upperLeft",
204
- tolerance: toleranceWorld,
205
- extent: tileEnvelope,
206
- };
207
- }
208
- const url = new ArcGisFeatureQuery_1.ArcGisFeatureQuery(this._settings.url, this._layerId, format, this._outSR, { geometry,
209
- geometryType: "esriGeometryEnvelope",
210
- returnExceededLimitFeatures: false,
211
- maxRecordCountFactor: 3,
212
- resultType: "tile",
213
- quantizationParameters,
214
- outFields,
215
- returnGeometry,
216
- distance: (tolerance ? tolerance * toleranceWorld : undefined) });
217
- let envelope;
218
- if (geomOverride && geomOverride.type === "esriGeometryEnvelope") {
219
- envelope = geomOverride.geom;
220
- }
221
- else {
222
- envelope = tileEnvelope;
223
- }
224
- return { url: url.toString(), envelope };
225
- }
226
- // Makes an identify request to ESRI MapService , and return it as a list MapLayerFeatureInfo object
227
- async getFeatureInfo(featureInfos, quadId, carto, _tree) {
228
- if (!this._querySupported || this.format === undefined)
229
- return;
230
- const cartoPoint = {
231
- x: this.getEPSG3857X(carto.longitudeDegrees),
232
- y: this.getEPSG3857Y(carto.latitudeDegrees),
233
- spatialReference: { wkid: 102100, latestWkid: 3857 },
234
- };
235
- const doFeatureInfoQuery = async (format, outFields, returnGeometry) => {
236
- const infoUrl = this.constructFeatureUrl(quadId.row, quadId.column, quadId.level, format, { geom: cartoPoint, type: "esriGeometryPoint" }, outFields, 3 /* tolerance in pixel*/, returnGeometry);
237
- if (!infoUrl || infoUrl.url.length === 0) {
238
- core_bentley_1.Logger.logError(loggerCategory, `Could not construct feature info query URL`);
239
- return undefined;
240
- }
241
- const response = this.fetch(new URL(infoUrl.url), { method: "GET" });
242
- const featureResponse = new ArcGisFeatureResponse_1.ArcGisFeatureResponse(format, response);
243
- return featureResponse.getResponseData();
244
- };
245
- if (this._debugFeatureGeom) {
246
- try {
247
- let responseData = await doFeatureInfoQuery("PBF", "", true);
248
- if (responseData) {
249
- core_bentley_1.Logger.logInfo(loggerCategory, JSON.stringify(responseData.data.toObject()));
250
- }
251
- responseData = await doFeatureInfoQuery("JSON", "", true);
252
- if (responseData) {
253
- core_bentley_1.Logger.logInfo(loggerCategory, JSON.stringify(responseData.data));
254
- }
255
- }
256
- catch (e) {
257
- core_bentley_1.Logger.logInfo(loggerCategory, `Error occured with debug FeatureInfo: ${e}`);
258
- }
259
- }
260
- try {
261
- const responseData = await doFeatureInfoQuery(this.format, "*", false);
262
- if (!responseData) {
263
- core_bentley_1.Logger.logError(loggerCategory, `Could not get feature info data`);
264
- return;
265
- }
266
- if (responseData.exceedTransferLimit) {
267
- core_bentley_1.Logger.logError(loggerCategory, `Could not get feature info : transfert limit exeeded.`);
268
- return;
269
- }
270
- const featureReader = this.format === "PBF" ? new ArcGisFeaturePBF_1.ArcGisFeaturePBF(this._settings, this._layerMetadata) : new ArcGisFeatureJSON_1.ArcGisFeatureJSON(this._settings, this._layerMetadata);
271
- featureReader.readFeatureInfo(responseData, featureInfos);
272
- }
273
- catch (e) {
274
- core_bentley_1.Logger.logError(loggerCategory, `Exception occured while loading feature info data : ${e}`);
275
- return;
276
- }
277
- return;
278
- }
279
- async fetchTile(row, column, zoomLevel, refineEnvelope) {
280
- if (!this.format) {
281
- return undefined;
282
- }
283
- const geomOverride = (refineEnvelope ? { geom: refineEnvelope, type: "esriGeometryEnvelope" } : undefined);
284
- const tileUrl = this.constructFeatureUrl(row, column, zoomLevel, this.format, geomOverride);
285
- if (!tileUrl || tileUrl.url.length === 0) {
286
- core_bentley_1.Logger.logError(loggerCategory, `Could not construct feature query URL for tile ${zoomLevel}/${row}/${column}`);
287
- return undefined;
288
- }
289
- const response = this.fetch(new URL(tileUrl.url), { method: "GET" });
290
- return new ArcGisFeatureResponse_1.ArcGisFeatureResponse(this.format, response, tileUrl.envelope);
291
- }
292
- drawTileDebugInfo(row, column, zoomLevel, context) {
293
- context.fillStyle = "cyan";
294
- context.strokeRect(0, 0, this.tileSize, this.tileSize);
295
- context.font = "30px Arial";
296
- context.lineWidth = 5;
297
- context.fillText(`${zoomLevel}-${row}-${column}`, 10, 50);
298
- }
299
- // Compute transform that provides coordinates in the canvas coordinate system (pixels, origin = top-left)
300
- // from coordinate in world (i.e EPSG:3857)
301
- computeTileWorld2CanvasTransform(row, column, zoomLevel) {
302
- const tileExtentWorld3857 = this.getEPSG3857Extent(row, column, zoomLevel);
303
- const worldTileWidth = tileExtentWorld3857.right - tileExtentWorld3857.left;
304
- const canvasTileWidth = this.tileSize;
305
- const world2CanvasRatio = canvasTileWidth / worldTileWidth;
306
- const worldTileOrigin = core_geometry_1.Point3d.create(tileExtentWorld3857.left, tileExtentWorld3857.bottom);
307
- const worldTileExtent = core_geometry_1.Point3d.create(tileExtentWorld3857.right, tileExtentWorld3857.top);
308
- const canvasTileOriginOffset = worldTileOrigin.clone();
309
- const canvasTileExtentOffset = worldTileExtent.clone();
310
- canvasTileOriginOffset.scaleInPlace(world2CanvasRatio);
311
- canvasTileExtentOffset.scaleInPlace(world2CanvasRatio);
312
- const xTranslate = -1 * canvasTileOriginOffset.x;
313
- // Canvas origin is uppler left corner, so we need to flip the y axsis
314
- const yTranslate = canvasTileExtentOffset.y; // y-axis flip
315
- const yWorld2CanvasRatio = -1 * world2CanvasRatio; // y-axis flip
316
- const matrix = core_geometry_1.Matrix4d.createTranslationAndScaleXYZ(xTranslate, yTranslate, 0, world2CanvasRatio, yWorld2CanvasRatio, 1);
317
- return matrix.asTransform;
318
- }
319
- async loadTile(row, column, zoomLevel) {
320
- if ((this.status === core_frontend_1.MapLayerImageryProviderStatus.RequireAuth)) {
321
- return undefined;
322
- }
323
- const canvas = document.createElement("canvas");
324
- canvas.width = this.tileSize;
325
- canvas.height = this.tileSize;
326
- const ctx = canvas.getContext("2d");
327
- if (ctx == null) {
328
- core_bentley_1.Logger.logError(loggerCategory, "No canvas context available for loading tile.");
329
- return undefined;
330
- }
331
- if (!this._symbologyRenderer) {
332
- core_bentley_1.Logger.logError(loggerCategory, "No symbology renderer available for loading tile.");
333
- return undefined;
334
- }
335
- try {
336
- // Compute transform if CoordinatesQuantization is not supported by service
337
- let transfo;
338
- if (!this._supportsCoordinatesQuantization) {
339
- transfo = this.computeTileWorld2CanvasTransform(row, column, zoomLevel);
340
- if (!transfo) {
341
- core_bentley_1.Logger.logError(loggerCategory, `Could not compute data transformation for tile (${zoomLevel}/${row}/${column})`);
342
- }
343
- }
344
- const renderer = new ArcGisFeatureRenderer_1.ArcGisFeatureRenderer(ctx, this._symbologyRenderer, transfo);
345
- const featureReader = this.format === "PBF" ? new ArcGisFeaturePBF_1.ArcGisFeaturePBF(this._settings, this._layerMetadata) : new ArcGisFeatureJSON_1.ArcGisFeatureJSON(this._settings, this._layerMetadata);
346
- const getSubEnvelopes = (envelope) => {
347
- const dx = (envelope.xmax - envelope.xmin) * 0.5;
348
- const dy = (envelope.xmax - envelope.xmin) * 0.5;
349
- const subEnvelopes = [];
350
- for (let posX = 0; posX < ArcGisFeatureProvider._nbSubTiles; posX++) {
351
- for (let posY = 0; posY < ArcGisFeatureProvider._nbSubTiles; posY++) {
352
- subEnvelopes.push({
353
- xmin: envelope.xmin + (dx * posX), ymin: envelope.ymin + (dy * posY),
354
- xmax: envelope.xmin + (dx * (posX + 1)), ymax: envelope.ymin + (dy * (posY + 1)),
355
- spatialReference: { wkid: 102100, latestWkid: 3857 },
356
- });
357
- }
358
- }
359
- return subEnvelopes;
360
- };
361
- // The strategy here is simple: we make a request for an area that represents the current tile (i.e envelope),
362
- // the server will either return the requested data OR a 'exceedTransferLimit' message (too much data to transfers).
363
- // In the latter case, we subdivide the previous request envelope in for 4 sub-envelopes,
364
- // and repeat again until we get data.
365
- const renderData = async (envelope) => {
366
- let response;
367
- let responseData;
368
- try {
369
- response = await this.fetchTile(row, column, zoomLevel, envelope);
370
- if (!response) {
371
- core_bentley_1.Logger.logError(loggerCategory, `Error occurred while fetching tile (${zoomLevel}/${row}/${column})`);
372
- return;
373
- }
374
- responseData = await response.getResponseData();
375
- if (!responseData) {
376
- core_bentley_1.Logger.logError(loggerCategory, `Could not get response data for tile (${zoomLevel}/${row}/${column})`);
377
- return;
378
- }
379
- }
380
- catch (e) {
381
- core_bentley_1.Logger.logError(loggerCategory, `Exception occurred while loading tile (${zoomLevel}/${row}/${column}) : ${e}`);
382
- return;
383
- }
384
- if (responseData.exceedTransferLimit) {
385
- if (response.envelope) {
386
- const subEnvelopes = getSubEnvelopes(response.envelope);
387
- const renderPromises = [];
388
- for (const subEnvelope of subEnvelopes) {
389
- renderPromises.push(renderData(subEnvelope));
390
- }
391
- await Promise.all(renderPromises);
392
- }
393
- else {
394
- core_bentley_1.Logger.logError(loggerCategory, `Request exceeded transfer limit, could not refine request`);
395
- }
396
- }
397
- else {
398
- featureReader.readAndRender(responseData, renderer);
399
- }
400
- };
401
- await renderData();
402
- if (this._drawDebugInfo)
403
- this.drawTileDebugInfo(row, column, zoomLevel, ctx);
404
- }
405
- catch (e) {
406
- core_bentley_1.Logger.logError(loggerCategory, `Exception occurred while loading tile (${zoomLevel}/${row}/${column}) : ${e}`);
407
- }
408
- try {
409
- const dataUrl = canvas.toDataURL("image/png");
410
- const header = "data:image/png;base64,";
411
- const dataUrl2 = dataUrl.substring(header.length);
412
- return new core_common_1.ImageSource((0, core_bentley_1.base64StringToUint8Array)(dataUrl2), core_common_1.ImageSourceFormat.Png);
413
- }
414
- catch (e) {
415
- core_bentley_1.Logger.logError(loggerCategory, `Exception occurred while rendering tile (${zoomLevel}/${row}/${column}) : ${e}.`);
416
- }
417
- return undefined;
418
- }
419
- }
420
- exports.ArcGisFeatureProvider = ArcGisFeatureProvider;
421
- ArcGisFeatureProvider._nbSubTiles = 2;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ArcGisFeatureProvider = void 0;
8
+ const core_common_1 = require("@itwin/core-common");
9
+ const core_bentley_1 = require("@itwin/core-bentley");
10
+ const core_geometry_1 = require("@itwin/core-geometry");
11
+ const core_frontend_1 = require("@itwin/core-frontend");
12
+ const ArcGisSymbologyRenderer_1 = require("./ArcGisSymbologyRenderer");
13
+ const ArcGisFeatureQuery_1 = require("./ArcGisFeatureQuery");
14
+ const ArcGisFeatureRenderer_1 = require("./ArcGisFeatureRenderer");
15
+ const ArcGisFeaturePBF_1 = require("./ArcGisFeaturePBF");
16
+ const ArcGisFeatureJSON_1 = require("./ArcGisFeatureJSON");
17
+ const ArcGisFeatureResponse_1 = require("./ArcGisFeatureResponse");
18
+ const loggerCategory = "MapLayersFormats.ArcGISFeature";
19
+ /** Provide tiles from a ESRI ArcGIS Feature service
20
+ * @internal
21
+ */
22
+ class ArcGisFeatureProvider extends core_frontend_1.ArcGISImageryProvider {
23
+ get minimumZoomLevel() { return this._minDepthFromLod; }
24
+ get maximumZoomLevel() { return this._maxDepthFromLod; }
25
+ constructor(settings) {
26
+ super(settings, true);
27
+ // Debug flags, should always be commited to FALSE !
28
+ this._drawDebugInfo = false;
29
+ this._debugFeatureGeom = false;
30
+ this._supportsCoordinatesQuantization = false;
31
+ this._querySupported = false;
32
+ this._layerId = 0;
33
+ this._outSR = 102100;
34
+ this._maxDepthFromLod = 0;
35
+ this._minDepthFromLod = 0;
36
+ }
37
+ async initialize() {
38
+ const metadata = await this.getServiceJson();
39
+ const json = metadata?.content;
40
+ if (json === undefined) {
41
+ core_bentley_1.Logger.logError(loggerCategory, "Could not get service JSON");
42
+ throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
43
+ }
44
+ if (json?.error?.code === core_frontend_1.ArcGisErrorCode.TokenRequired || json?.error?.code === core_frontend_1.ArcGisErrorCode.InvalidToken) {
45
+ // Check again layer status, it might have change during await.
46
+ if (this.status === core_frontend_1.MapLayerImageryProviderStatus.Valid) {
47
+ this.setStatus(core_frontend_1.MapLayerImageryProviderStatus.RequireAuth);
48
+ return;
49
+ }
50
+ }
51
+ if (json.capabilities) {
52
+ this._querySupported = json.capabilities.indexOf("Query") >= 0;
53
+ if (!this._querySupported)
54
+ throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
55
+ }
56
+ this.serviceJson = json;
57
+ let foundVisibleSubLayer = false;
58
+ if (this._settings.subLayers.length >= 0) {
59
+ // There is more than sub-layer for this layer, pick the first visible one.
60
+ for (const layer of this._settings.subLayers) {
61
+ if (layer.visible && typeof layer.id === "number") {
62
+ this._layerId = layer.id;
63
+ foundVisibleSubLayer = true;
64
+ break;
65
+ }
66
+ }
67
+ }
68
+ if (!foundVisibleSubLayer && json !== undefined) {
69
+ // No suitable sublayer was specified on the layerSettings object, lets find a default one in the capabilities
70
+ // Check layer metadata
71
+ if (Array.isArray(this.serviceJson.layers) && this.serviceJson.layers.length >= 1) {
72
+ const hasDefaultVisibility = Object.keys(this.serviceJson.layers[0]).includes("defaultVisibility");
73
+ if (hasDefaultVisibility) {
74
+ for (const layer of this.serviceJson.layers) {
75
+ if (layer.defaultVisibility) {
76
+ this._layerId = layer.id;
77
+ }
78
+ }
79
+ }
80
+ else {
81
+ // On some older servers, the default visiblity is on the layer capabilities (i.e. not the service capabilities)
82
+ for (const layer of this.serviceJson.layers) {
83
+ const layerJson = await this.getLayerMetadata(layer.id);
84
+ if (!layerJson) {
85
+ continue;
86
+ }
87
+ if (layerJson.defaultVisibility) {
88
+ this._layerId = layer.id;
89
+ this._layerMetadata = layerJson;
90
+ break;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ else {
96
+ // There is no layer to publish? Something is off with this server..
97
+ throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
98
+ }
99
+ }
100
+ // Make sure we cache layer info (i.e. rendering info)
101
+ if (!this._layerMetadata) {
102
+ this._layerMetadata = await this.getLayerMetadata(this._layerId);
103
+ if (!this._layerMetadata) {
104
+ core_bentley_1.Logger.logError(loggerCategory, "Could not layer metadata");
105
+ throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
106
+ }
107
+ }
108
+ // Parse server version
109
+ let majorVersion;
110
+ if (this.serviceJson?.currentVersion) {
111
+ try {
112
+ majorVersion = Math.trunc(this.serviceJson?.currentVersion);
113
+ }
114
+ catch {
115
+ }
116
+ }
117
+ // Coordinates Quantization: If supported, server will transform for us the coordinates in the Tile coordinate space (pixels, origin = upper left corner
118
+ // If not supported, transformation will be applied client side.
119
+ // Note: For some reasons, even though 'supportsCoordinatesQuantization' is set to 'true' on the layer metadata, server will give an error message for server version < 11
120
+ if (majorVersion && majorVersion >= 11 && this._layerMetadata.supportsCoordinatesQuantization) {
121
+ this._supportsCoordinatesQuantization = true;
122
+ }
123
+ // Check supported query formats: JSON and PBF are currently implemented by this provider
124
+ // Note: needs to be checked on the layer metadata, service metadata advertises a different set of formats
125
+ // Also, since PBF format does not support floating points, there is no point using this format if supportsCoordinatesQuantization is not available.
126
+ if (this._layerMetadata.supportedQueryFormats) {
127
+ const formats = this._layerMetadata.supportedQueryFormats.split(", ");
128
+ if (formats.includes("PBF") && this._supportsCoordinatesQuantization) {
129
+ this._format = "PBF";
130
+ }
131
+ else if (formats.includes("JSON")) {
132
+ this._format = "JSON";
133
+ }
134
+ }
135
+ if (!this._format) {
136
+ core_bentley_1.Logger.logError(loggerCategory, "Could not get request format from service JSON");
137
+ throw new core_common_1.ServerError(core_bentley_1.IModelStatus.ValidationFailed, "");
138
+ }
139
+ // Read range using full extent from service metadata
140
+ if (json.fullExtent) {
141
+ if (json.fullExtent.spatialReference.latestWkid === 3857 || json.fullExtent.spatialReference.wkid === 102100) {
142
+ const range3857 = core_geometry_1.Range2d.createFrom({
143
+ low: { x: json.fullExtent.xmin, y: json.fullExtent.ymin },
144
+ high: { x: json.fullExtent.xmax, y: json.fullExtent.ymax }
145
+ });
146
+ const west = this.getEPSG4326Lon(range3857.xLow);
147
+ const south = this.getEPSG4326Lat(range3857.yLow);
148
+ const east = this.getEPSG4326Lon(range3857.xHigh);
149
+ const north = this.getEPSG4326Lat(range3857.yHigh);
150
+ this.cartoRange = core_frontend_1.MapCartoRectangle.fromDegrees(west, south, east, north);
151
+ }
152
+ }
153
+ // Check for minScale / max scale
154
+ const minScale = this._layerMetadata?.minScale || undefined; // undefined, 0 -> undefined
155
+ const maxScale = this._layerMetadata?.maxScale || undefined; // undefined, 0 -> undefined
156
+ const scales = core_frontend_1.ArcGisUtilities.getZoomLevelsScales(this.defaultMaximumZoomLevel, this.tileSize, minScale, maxScale, 1.0);
157
+ if (scales.minLod)
158
+ this._minDepthFromLod = scales.minLod;
159
+ // Some servers advertises a max LOD of 0, it should be interpreted as 'not defined' (otherwise a max lod of 0 would would mean never display anything)
160
+ this._maxDepthFromLod = (scales.maxLod ? scales.maxLod : this.defaultMaximumZoomLevel);
161
+ this._symbologyRenderer = new ArcGisSymbologyRenderer_1.ArcGisSymbologyRenderer(this._layerMetadata?.geometryType, this._layerMetadata?.drawingInfo?.renderer);
162
+ }
163
+ async getLayerMetadata(layerId) {
164
+ let metadata;
165
+ try {
166
+ const url = new URL(this._settings.url);
167
+ url.pathname = `${url.pathname}/${layerId}`;
168
+ metadata = await core_frontend_1.ArcGisUtilities.getServiceJson(url.toString(), this._settings.formatId, this._settings.userName, this._settings.password, this._accessTokenRequired);
169
+ }
170
+ catch {
171
+ }
172
+ return metadata?.content;
173
+ }
174
+ get tileSize() { return 512; }
175
+ get format() { return this._format; }
176
+ // We don't use this method inside this provider (see constructFeatureUrl), but since this is an abstract method, we need to define something
177
+ async constructUrl(_row, _column, _zoomLevel) {
178
+ return "";
179
+ }
180
+ constructFeatureUrl(row, column, zoomLevel, format, geomOverride, outFields, tolerance, returnGeometry) {
181
+ const tileExtent = this.getEPSG3857Extent(row, column, zoomLevel);
182
+ const tileEnvelope = {
183
+ xmin: tileExtent.left, ymin: tileExtent.bottom,
184
+ xmax: tileExtent.right, ymax: tileExtent.top,
185
+ spatialReference: { wkid: 102100, latestWkid: 3857 },
186
+ };
187
+ // Actual spatial filter.
188
+ // By default, we request the tile extent. If 'cartoPoint' is specified,
189
+ // we restrict the spatial to specific point. (i.e. GetFeatureInfo requests)
190
+ // If envelope is provided, it has the priority over 'cartoPoint'
191
+ let geometry;
192
+ if (geomOverride) {
193
+ geometry = geomOverride;
194
+ }
195
+ else {
196
+ geometry = { geom: tileEnvelope, type: "esriGeometryEnvelope" };
197
+ }
198
+ let quantizationParameters;
199
+ const toleranceWorld = (tileExtent.top - tileExtent.bottom) / this.tileSize;
200
+ if (this._supportsCoordinatesQuantization) {
201
+ quantizationParameters = {
202
+ mode: "view",
203
+ originPosition: "upperLeft",
204
+ tolerance: toleranceWorld,
205
+ extent: tileEnvelope,
206
+ };
207
+ }
208
+ const url = new ArcGisFeatureQuery_1.ArcGisFeatureQuery(this._settings.url, this._layerId, format, this._outSR, { geometry,
209
+ geometryType: "esriGeometryEnvelope",
210
+ returnExceededLimitFeatures: false,
211
+ maxRecordCountFactor: 3,
212
+ resultType: "tile",
213
+ quantizationParameters,
214
+ outFields,
215
+ returnGeometry,
216
+ distance: (tolerance ? tolerance * toleranceWorld : undefined) });
217
+ let envelope;
218
+ if (geomOverride && geomOverride.type === "esriGeometryEnvelope") {
219
+ envelope = geomOverride.geom;
220
+ }
221
+ else {
222
+ envelope = tileEnvelope;
223
+ }
224
+ return { url: url.toString(), envelope };
225
+ }
226
+ // Makes an identify request to ESRI MapService , and return it as a list MapLayerFeatureInfo object
227
+ async getFeatureInfo(featureInfos, quadId, carto, _tree) {
228
+ if (!this._querySupported || this.format === undefined)
229
+ return;
230
+ const cartoPoint = {
231
+ x: this.getEPSG3857X(carto.longitudeDegrees),
232
+ y: this.getEPSG3857Y(carto.latitudeDegrees),
233
+ spatialReference: { wkid: 102100, latestWkid: 3857 },
234
+ };
235
+ const doFeatureInfoQuery = async (format, outFields, returnGeometry) => {
236
+ const infoUrl = this.constructFeatureUrl(quadId.row, quadId.column, quadId.level, format, { geom: cartoPoint, type: "esriGeometryPoint" }, outFields, 3 /* tolerance in pixel*/, returnGeometry);
237
+ if (!infoUrl || infoUrl.url.length === 0) {
238
+ core_bentley_1.Logger.logError(loggerCategory, `Could not construct feature info query URL`);
239
+ return undefined;
240
+ }
241
+ const response = this.fetch(new URL(infoUrl.url), { method: "GET" });
242
+ const featureResponse = new ArcGisFeatureResponse_1.ArcGisFeatureResponse(format, response);
243
+ return featureResponse.getResponseData();
244
+ };
245
+ if (this._debugFeatureGeom) {
246
+ try {
247
+ let responseData = await doFeatureInfoQuery("PBF", "", true);
248
+ if (responseData) {
249
+ core_bentley_1.Logger.logInfo(loggerCategory, JSON.stringify(responseData.data.toObject()));
250
+ }
251
+ responseData = await doFeatureInfoQuery("JSON", "", true);
252
+ if (responseData) {
253
+ core_bentley_1.Logger.logInfo(loggerCategory, JSON.stringify(responseData.data));
254
+ }
255
+ }
256
+ catch (e) {
257
+ core_bentley_1.Logger.logInfo(loggerCategory, `Error occured with debug FeatureInfo: ${e}`);
258
+ }
259
+ }
260
+ try {
261
+ const responseData = await doFeatureInfoQuery(this.format, "*", false);
262
+ if (!responseData) {
263
+ core_bentley_1.Logger.logError(loggerCategory, `Could not get feature info data`);
264
+ return;
265
+ }
266
+ if (responseData.exceedTransferLimit) {
267
+ core_bentley_1.Logger.logError(loggerCategory, `Could not get feature info : transfert limit exeeded.`);
268
+ return;
269
+ }
270
+ const featureReader = this.format === "PBF" ? new ArcGisFeaturePBF_1.ArcGisFeaturePBF(this._settings, this._layerMetadata) : new ArcGisFeatureJSON_1.ArcGisFeatureJSON(this._settings, this._layerMetadata);
271
+ featureReader.readFeatureInfo(responseData, featureInfos);
272
+ }
273
+ catch (e) {
274
+ core_bentley_1.Logger.logError(loggerCategory, `Exception occured while loading feature info data : ${e}`);
275
+ return;
276
+ }
277
+ return;
278
+ }
279
+ async fetchTile(row, column, zoomLevel, refineEnvelope) {
280
+ if (!this.format) {
281
+ return undefined;
282
+ }
283
+ const geomOverride = (refineEnvelope ? { geom: refineEnvelope, type: "esriGeometryEnvelope" } : undefined);
284
+ const tileUrl = this.constructFeatureUrl(row, column, zoomLevel, this.format, geomOverride);
285
+ if (!tileUrl || tileUrl.url.length === 0) {
286
+ core_bentley_1.Logger.logError(loggerCategory, `Could not construct feature query URL for tile ${zoomLevel}/${row}/${column}`);
287
+ return undefined;
288
+ }
289
+ const response = this.fetch(new URL(tileUrl.url), { method: "GET" });
290
+ return new ArcGisFeatureResponse_1.ArcGisFeatureResponse(this.format, response, tileUrl.envelope);
291
+ }
292
+ drawTileDebugInfo(row, column, zoomLevel, context) {
293
+ context.fillStyle = "cyan";
294
+ context.strokeRect(0, 0, this.tileSize, this.tileSize);
295
+ context.font = "30px Arial";
296
+ context.lineWidth = 5;
297
+ context.fillText(`${zoomLevel}-${row}-${column}`, 10, 50);
298
+ }
299
+ // Compute transform that provides coordinates in the canvas coordinate system (pixels, origin = top-left)
300
+ // from coordinate in world (i.e EPSG:3857)
301
+ computeTileWorld2CanvasTransform(row, column, zoomLevel) {
302
+ const tileExtentWorld3857 = this.getEPSG3857Extent(row, column, zoomLevel);
303
+ const worldTileWidth = tileExtentWorld3857.right - tileExtentWorld3857.left;
304
+ const canvasTileWidth = this.tileSize;
305
+ const world2CanvasRatio = canvasTileWidth / worldTileWidth;
306
+ const worldTileOrigin = core_geometry_1.Point3d.create(tileExtentWorld3857.left, tileExtentWorld3857.bottom);
307
+ const worldTileExtent = core_geometry_1.Point3d.create(tileExtentWorld3857.right, tileExtentWorld3857.top);
308
+ const canvasTileOriginOffset = worldTileOrigin.clone();
309
+ const canvasTileExtentOffset = worldTileExtent.clone();
310
+ canvasTileOriginOffset.scaleInPlace(world2CanvasRatio);
311
+ canvasTileExtentOffset.scaleInPlace(world2CanvasRatio);
312
+ const xTranslate = -1 * canvasTileOriginOffset.x;
313
+ // Canvas origin is uppler left corner, so we need to flip the y axsis
314
+ const yTranslate = canvasTileExtentOffset.y; // y-axis flip
315
+ const yWorld2CanvasRatio = -1 * world2CanvasRatio; // y-axis flip
316
+ const matrix = core_geometry_1.Matrix4d.createTranslationAndScaleXYZ(xTranslate, yTranslate, 0, world2CanvasRatio, yWorld2CanvasRatio, 1);
317
+ return matrix.asTransform;
318
+ }
319
+ async loadTile(row, column, zoomLevel) {
320
+ if ((this.status === core_frontend_1.MapLayerImageryProviderStatus.RequireAuth)) {
321
+ return undefined;
322
+ }
323
+ const canvas = document.createElement("canvas");
324
+ canvas.width = this.tileSize;
325
+ canvas.height = this.tileSize;
326
+ const ctx = canvas.getContext("2d");
327
+ if (ctx == null) {
328
+ core_bentley_1.Logger.logError(loggerCategory, "No canvas context available for loading tile.");
329
+ return undefined;
330
+ }
331
+ if (!this._symbologyRenderer) {
332
+ core_bentley_1.Logger.logError(loggerCategory, "No symbology renderer available for loading tile.");
333
+ return undefined;
334
+ }
335
+ try {
336
+ // Compute transform if CoordinatesQuantization is not supported by service
337
+ let transfo;
338
+ if (!this._supportsCoordinatesQuantization) {
339
+ transfo = this.computeTileWorld2CanvasTransform(row, column, zoomLevel);
340
+ if (!transfo) {
341
+ core_bentley_1.Logger.logError(loggerCategory, `Could not compute data transformation for tile (${zoomLevel}/${row}/${column})`);
342
+ }
343
+ }
344
+ const renderer = new ArcGisFeatureRenderer_1.ArcGisFeatureRenderer(ctx, this._symbologyRenderer, transfo);
345
+ const featureReader = this.format === "PBF" ? new ArcGisFeaturePBF_1.ArcGisFeaturePBF(this._settings, this._layerMetadata) : new ArcGisFeatureJSON_1.ArcGisFeatureJSON(this._settings, this._layerMetadata);
346
+ const getSubEnvelopes = (envelope) => {
347
+ const dx = (envelope.xmax - envelope.xmin) * 0.5;
348
+ const dy = (envelope.xmax - envelope.xmin) * 0.5;
349
+ const subEnvelopes = [];
350
+ for (let posX = 0; posX < ArcGisFeatureProvider._nbSubTiles; posX++) {
351
+ for (let posY = 0; posY < ArcGisFeatureProvider._nbSubTiles; posY++) {
352
+ subEnvelopes.push({
353
+ xmin: envelope.xmin + (dx * posX), ymin: envelope.ymin + (dy * posY),
354
+ xmax: envelope.xmin + (dx * (posX + 1)), ymax: envelope.ymin + (dy * (posY + 1)),
355
+ spatialReference: { wkid: 102100, latestWkid: 3857 },
356
+ });
357
+ }
358
+ }
359
+ return subEnvelopes;
360
+ };
361
+ // The strategy here is simple: we make a request for an area that represents the current tile (i.e envelope),
362
+ // the server will either return the requested data OR a 'exceedTransferLimit' message (too much data to transfers).
363
+ // In the latter case, we subdivide the previous request envelope in for 4 sub-envelopes,
364
+ // and repeat again until we get data.
365
+ const renderData = async (envelope) => {
366
+ let response;
367
+ let responseData;
368
+ try {
369
+ response = await this.fetchTile(row, column, zoomLevel, envelope);
370
+ if (!response) {
371
+ core_bentley_1.Logger.logError(loggerCategory, `Error occurred while fetching tile (${zoomLevel}/${row}/${column})`);
372
+ return;
373
+ }
374
+ responseData = await response.getResponseData();
375
+ if (!responseData) {
376
+ core_bentley_1.Logger.logError(loggerCategory, `Could not get response data for tile (${zoomLevel}/${row}/${column})`);
377
+ return;
378
+ }
379
+ }
380
+ catch (e) {
381
+ core_bentley_1.Logger.logError(loggerCategory, `Exception occurred while loading tile (${zoomLevel}/${row}/${column}) : ${e}`);
382
+ return;
383
+ }
384
+ if (responseData.exceedTransferLimit) {
385
+ if (response.envelope) {
386
+ const subEnvelopes = getSubEnvelopes(response.envelope);
387
+ const renderPromises = [];
388
+ for (const subEnvelope of subEnvelopes) {
389
+ renderPromises.push(renderData(subEnvelope));
390
+ }
391
+ await Promise.all(renderPromises);
392
+ }
393
+ else {
394
+ core_bentley_1.Logger.logError(loggerCategory, `Request exceeded transfer limit, could not refine request`);
395
+ }
396
+ }
397
+ else {
398
+ featureReader.readAndRender(responseData, renderer);
399
+ }
400
+ };
401
+ await renderData();
402
+ if (this._drawDebugInfo)
403
+ this.drawTileDebugInfo(row, column, zoomLevel, ctx);
404
+ }
405
+ catch (e) {
406
+ core_bentley_1.Logger.logError(loggerCategory, `Exception occurred while loading tile (${zoomLevel}/${row}/${column}) : ${e}`);
407
+ }
408
+ try {
409
+ const dataUrl = canvas.toDataURL("image/png");
410
+ const header = "data:image/png;base64,";
411
+ const dataUrl2 = dataUrl.substring(header.length);
412
+ return new core_common_1.ImageSource((0, core_bentley_1.base64StringToUint8Array)(dataUrl2), core_common_1.ImageSourceFormat.Png);
413
+ }
414
+ catch (e) {
415
+ core_bentley_1.Logger.logError(loggerCategory, `Exception occurred while rendering tile (${zoomLevel}/${row}/${column}) : ${e}.`);
416
+ }
417
+ return undefined;
418
+ }
419
+ }
420
+ ArcGisFeatureProvider._nbSubTiles = 2;
421
+ exports.ArcGisFeatureProvider = ArcGisFeatureProvider;
422
422
  //# sourceMappingURL=ArcGisFeatureProvider.js.map