@itwin/map-layers-formats 4.0.0-dev.8 → 4.0.0-dev.80

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