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

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/cd866071-e986-4027-89f6-9a70b6e25ed3.json +1 -0
  79. package/lib/cjs/test/coverage/.nyc_output/processinfo/4c93adb3-7e95-4a63-9814-a25d79ab4680.json +1 -0
  80. package/lib/cjs/test/coverage/.nyc_output/processinfo/cd866071-e986-4027-89f6-9a70b6e25ed3.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 +44 -44
  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 → 4c93adb3-7e95-4a63-9814-a25d79ab4680.json} +0 -0
@@ -1,679 +1,678 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- import { Base64EncodedString, Cartographic, ImageMapLayerSettings, ImageSourceFormat, ServerError } from "@itwin/core-common";
6
- import * as chai from "chai";
7
- import * as chaiAsPromised from "chai-as-promised";
8
- import { ArcGisFeatureMapLayerFormat } from "../../ArcGisFeature/ArcGisFeatureFormat";
9
- import { ArcGisFeatureProvider } from "../../map-layers-formats";
10
- import * as sinon from "sinon";
11
- import { ArcGISImageryProvider, ArcGisUtilities, MapLayerImageryProviderStatus, QuadId } from "@itwin/core-frontend";
12
- import { NewYorkDataset } from "./NewYorkDataset";
13
- import { base64StringToUint8Array, ByteStream, Logger } from "@itwin/core-bentley";
14
- import { PhillyLandmarksDataset } from "./PhillyLandmarksDataset";
15
- import { ArcGisFeatureResponse } from "../../ArcGisFeature/ArcGisFeatureResponse";
16
- import { Point3d } from "@itwin/core-geometry";
17
- import { ArcGisFeaturePBF } from "../../ArcGisFeature/ArcGisFeaturePBF";
18
- import { ArcGisFeatureJSON } from "../../ArcGisFeature/ArcGisFeatureJSON";
19
- const expect = chai.expect;
20
- chai.use(chaiAsPromised);
21
- const esriFeatureSampleSource = { name: "dummyFeatureLayer", url: "https://dummy.com", formatId: ArcGisFeatureMapLayerFormat.formatId };
22
- const pngTransparent1x1 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==";
23
- describe("ArcGisFeatureProvider", () => {
24
- const sandbox = sinon.createSandbox();
25
- afterEach(async () => {
26
- sandbox.restore();
27
- });
28
- it("should initialize with valid data", async () => {
29
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
30
- return { accessTokenRequired: false, content: NewYorkDataset.serviceCapabilities };
31
- });
32
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function _(_layerId) {
33
- return NewYorkDataset.streetsLayerCapabilities;
34
- });
35
- const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
36
- const provider = new ArcGisFeatureProvider(settings);
37
- await provider.initialize();
38
- expect(provider._minDepthFromLod).to.equals(11);
39
- expect(provider._maxDepthFromLod).to.equals(22);
40
- });
41
- it("should not initialize with no service metadata", async () => {
42
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
43
- return undefined;
44
- });
45
- const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
46
- const provider = new ArcGisFeatureProvider(settings);
47
- await expect(provider.initialize()).to.be.rejectedWith(ServerError);
48
- });
49
- it("should update status when invalid token error from service", async () => {
50
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
51
- return { accessTokenRequired: false, content: { error: { code: 499 } } };
52
- });
53
- const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
54
- const provider = new ArcGisFeatureProvider(settings);
55
- const raiseEventSpy = sandbox.spy(provider.onStatusChanged, "raiseEvent");
56
- await provider.initialize();
57
- expect(provider.status).to.equals(MapLayerImageryProviderStatus.RequireAuth);
58
- expect(raiseEventSpy.calledOnceWith(provider)).to.be.true;
59
- });
60
- it("should throw query capability not supported", async () => {
61
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
62
- return { accessTokenRequired: false, content: { capabilities: "Test" } };
63
- });
64
- const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
65
- const provider = new ArcGisFeatureProvider(settings);
66
- await expect(provider.initialize()).to.be.rejectedWith(ServerError);
67
- });
68
- it("should pick the first visible sub-layer when multiple visible sub-layers", async () => {
69
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
70
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
71
- });
72
- const settings = ImageMapLayerSettings.fromJSON({
73
- ...esriFeatureSampleSource,
74
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
75
- });
76
- const provider = new ArcGisFeatureProvider(settings);
77
- provider._format = "JSON";
78
- await provider.initialize();
79
- expect(provider._layerId).to.equals(settings.subLayers[0].id);
80
- });
81
- it("should pick sub-layers from service metadata if none provided on layer settings", async () => {
82
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
83
- return { accessTokenRequired: false, content: { capabilities: "Query",
84
- layers: [
85
- {
86
- id: 0,
87
- },
88
- {
89
- id: 1,
90
- },
91
- ] },
92
- };
93
- });
94
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (id) {
95
- if (id === 1) {
96
- return { defaultVisibility: true };
97
- }
98
- return undefined;
99
- });
100
- const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
101
- const provider = new ArcGisFeatureProvider(settings);
102
- provider._format = "JSON";
103
- await provider.initialize();
104
- expect(provider._layerId).to.equals(1);
105
- expect(provider._layerMetadata).to.eql({ defaultVisibility: true });
106
- });
107
- it("should throw error if no layers in capabilities", async () => {
108
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
109
- return { accessTokenRequired: false, content: { capabilities: "Query", layers: [] } };
110
- });
111
- const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
112
- const provider = new ArcGisFeatureProvider(settings);
113
- await expect(provider.initialize()).to.be.rejectedWith(ServerError);
114
- });
115
- it("should throw if no layer metadata from service", async () => {
116
- const settings = ImageMapLayerSettings.fromJSON({
117
- ...esriFeatureSampleSource,
118
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
119
- });
120
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
121
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
122
- });
123
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
124
- return undefined;
125
- });
126
- const provider = new ArcGisFeatureProvider(settings);
127
- await expect(provider.initialize()).to.be.rejectedWith(ServerError);
128
- });
129
- it("should read supported supported format", async () => {
130
- const settings = ImageMapLayerSettings.fromJSON({
131
- ...esriFeatureSampleSource,
132
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
133
- });
134
- let getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
135
- return { defaultVisibility: true, supportedQueryFormats: "PBF, JSON" };
136
- });
137
- const getServiceJsonStub = sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
138
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
139
- });
140
- let provider = new ArcGisFeatureProvider(settings);
141
- await provider.initialize();
142
- expect(provider.format).to.equals("JSON");
143
- // PBF requires 'supportsCoordinatesQuantization'
144
- getServiceJsonStub.restore();
145
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
146
- return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
147
- });
148
- getLayerMetadataStub.restore();
149
- getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
150
- return { defaultVisibility: true, supportsCoordinatesQuantization: true, supportedQueryFormats: "PBF, JSON" };
151
- });
152
- provider = new ArcGisFeatureProvider(settings);
153
- await provider.initialize();
154
- expect(provider.format).to.equals("PBF");
155
- getLayerMetadataStub.restore();
156
- getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
157
- return { defaultVisibility: true, supportedQueryFormats: "JSON" };
158
- });
159
- getServiceJsonStub.restore();
160
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
161
- return { accessTokenRequired: false, content: { currentVersion: 10.91, capabilities: "Query", supportsCoordinatesQuantization: true } };
162
- });
163
- provider = new ArcGisFeatureProvider(settings);
164
- await provider.initialize();
165
- expect(provider.format).to.equals("JSON");
166
- getLayerMetadataStub.restore();
167
- getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
168
- return { defaultVisibility: true, supportedQueryFormats: "JSON" };
169
- });
170
- provider = new ArcGisFeatureProvider(settings);
171
- await provider.initialize();
172
- expect(provider.format).to.equals("JSON");
173
- getLayerMetadataStub.restore();
174
- getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
175
- return { defaultVisibility: true, supportedQueryFormats: "" };
176
- });
177
- provider = new ArcGisFeatureProvider(settings);
178
- await expect(provider.initialize()).to.be.rejectedWith(ServerError);
179
- });
180
- it("should compute minLod/maxLod", async () => {
181
- const settings = ImageMapLayerSettings.fromJSON({
182
- ...esriFeatureSampleSource,
183
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
184
- });
185
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
186
- return {
187
- defaultVisibility: true,
188
- supportedQueryFormats: "PBF, JSON",
189
- minScale: 600000,
190
- maxScale: 5000,
191
- };
192
- });
193
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
194
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
195
- });
196
- const provider = new ArcGisFeatureProvider(settings);
197
- await provider.initialize();
198
- expect(provider._minDepthFromLod).to.equals(9);
199
- expect(provider._maxDepthFromLod).to.equals(15);
200
- });
201
- it("should construct empty url", async () => {
202
- const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
203
- const provider = new ArcGisFeatureProvider(settings);
204
- const url = await provider.constructUrl(0, 0, 0);
205
- expect(url).to.equals("");
206
- });
207
- it("should construct feature query url", async () => {
208
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
209
- const settings = ImageMapLayerSettings.fromJSON({
210
- ...esriFeatureSampleSource,
211
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
212
- });
213
- let getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
214
- return {
215
- defaultVisibility: true,
216
- supportedQueryFormats: "PBF, JSON",
217
- };
218
- });
219
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
220
- return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
221
- });
222
- const provider = new ArcGisFeatureProvider(settings);
223
- await provider.initialize();
224
- let url = provider.constructFeatureUrl(0, 0, 0, "PBF");
225
- const extent = {
226
- xmin: -20037508.34,
227
- ymin: -20037508.33,
228
- xmax: 20037508.34,
229
- ymax: 20037508.34,
230
- spatialReference: {
231
- wkid: 102100,
232
- latestWkid: 3857,
233
- },
234
- };
235
- expect(url === null || url === void 0 ? void 0 : url.url).to.equals(`https://dummy.com/0/query?f=PBF&resultType=tile&maxRecordCountFactor=3&returnExceededLimitFeatures=false&outSR=102100&geometryType=esriGeometryEnvelope&geometry=%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D&units=esriSRUnit_Meter&inSR=102100`);
236
- expect((_a = url === null || url === void 0 ? void 0 : url.envelope) === null || _a === void 0 ? void 0 : _a.xmin).to.be.closeTo(extent.xmin, 0.01);
237
- expect((_b = url === null || url === void 0 ? void 0 : url.envelope) === null || _b === void 0 ? void 0 : _b.ymin).to.be.closeTo(extent.ymin, 0.01);
238
- expect((_c = url === null || url === void 0 ? void 0 : url.envelope) === null || _c === void 0 ? void 0 : _c.xmax).to.be.closeTo(extent.xmax, 0.01);
239
- expect((_d = url === null || url === void 0 ? void 0 : url.envelope) === null || _d === void 0 ? void 0 : _d.ymax).to.be.closeTo(extent.ymax, 0.01);
240
- expect((_e = url === null || url === void 0 ? void 0 : url.envelope) === null || _e === void 0 ? void 0 : _e.spatialReference.wkid).to.be.equal(102100);
241
- expect((_f = url === null || url === void 0 ? void 0 : url.envelope) === null || _f === void 0 ? void 0 : _f.spatialReference.latestWkid).to.be.equal(3857);
242
- // Now turn ON 'supportsCoordinatesQuantization' to ON
243
- getLayerMetadataStub.restore();
244
- getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
245
- return {
246
- defaultVisibility: true,
247
- supportedQueryFormats: "PBF, JSON",
248
- supportsCoordinatesQuantization: true,
249
- };
250
- });
251
- const provider2 = new ArcGisFeatureProvider(settings);
252
- await provider2.initialize();
253
- url = provider2.constructFeatureUrl(0, 0, 0, "PBF");
254
- expect(url === null || url === void 0 ? void 0 : url.url).to.equals(`https://dummy.com/0/query?f=PBF&resultType=tile&maxRecordCountFactor=3&returnExceededLimitFeatures=false&outSR=102100&geometryType=esriGeometryEnvelope&geometry=%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D&units=esriSRUnit_Meter&inSR=102100&quantizationParameters=%7B%22mode%22%3A%22view%22%2C%22originPosition%22%3A%22upperLeft%22%2C%22tolerance%22%3A78271.516953125%2C%22extent%22%3A%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D%7D`);
255
- expect((_g = url === null || url === void 0 ? void 0 : url.envelope) === null || _g === void 0 ? void 0 : _g.xmin).to.be.closeTo(extent.xmin, 0.01);
256
- expect((_h = url === null || url === void 0 ? void 0 : url.envelope) === null || _h === void 0 ? void 0 : _h.ymin).to.be.closeTo(extent.ymin, 0.01);
257
- expect((_j = url === null || url === void 0 ? void 0 : url.envelope) === null || _j === void 0 ? void 0 : _j.xmax).to.be.closeTo(extent.xmax, 0.01);
258
- expect((_k = url === null || url === void 0 ? void 0 : url.envelope) === null || _k === void 0 ? void 0 : _k.ymax).to.be.closeTo(extent.ymax, 0.01);
259
- expect((_l = url === null || url === void 0 ? void 0 : url.envelope) === null || _l === void 0 ? void 0 : _l.spatialReference.wkid).to.be.equal(extent.spatialReference.wkid);
260
- expect((_m = url === null || url === void 0 ? void 0 : url.envelope) === null || _m === void 0 ? void 0 : _m.spatialReference.latestWkid).to.be.equal(extent.spatialReference.latestWkid);
261
- // Test passing an override geometry
262
- const overrideGeom = {
263
- type: "esriGeometryEnvelope",
264
- geom: {
265
- xmin: -50,
266
- ymin: -50,
267
- xmax: 50,
268
- ymax: 50,
269
- spatialReference: {
270
- wkid: 102100,
271
- latestWkid: 3857,
272
- },
273
- },
274
- };
275
- const provider3 = new ArcGisFeatureProvider(settings);
276
- await provider3.initialize();
277
- url = provider3.constructFeatureUrl(0, 0, 0, "PBF", overrideGeom);
278
- expect(url === null || url === void 0 ? void 0 : url.url).to.equals(`https://dummy.com/0/query?f=PBF&resultType=tile&maxRecordCountFactor=3&returnExceededLimitFeatures=false&outSR=102100&geometryType=esriGeometryEnvelope&geometry=%7B%22xmin%22%3A-50%2C%22ymin%22%3A-50%2C%22xmax%22%3A50%2C%22ymax%22%3A50%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D&units=esriSRUnit_Meter&inSR=102100&quantizationParameters=%7B%22mode%22%3A%22view%22%2C%22originPosition%22%3A%22upperLeft%22%2C%22tolerance%22%3A78271.516953125%2C%22extent%22%3A%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D%7D`);
279
- expect((_o = url === null || url === void 0 ? void 0 : url.envelope) === null || _o === void 0 ? void 0 : _o.xmin).to.be.closeTo(overrideGeom.geom.xmin, 0.01);
280
- expect((_p = url === null || url === void 0 ? void 0 : url.envelope) === null || _p === void 0 ? void 0 : _p.ymin).to.be.closeTo(overrideGeom.geom.ymin, 0.01);
281
- expect((_q = url === null || url === void 0 ? void 0 : url.envelope) === null || _q === void 0 ? void 0 : _q.xmax).to.be.closeTo(overrideGeom.geom.xmax, 0.01);
282
- expect((_r = url === null || url === void 0 ? void 0 : url.envelope) === null || _r === void 0 ? void 0 : _r.ymax).to.be.closeTo(overrideGeom.geom.ymax, 0.01);
283
- expect((_s = url === null || url === void 0 ? void 0 : url.envelope) === null || _s === void 0 ? void 0 : _s.spatialReference.wkid).to.be.equal(overrideGeom.geom.spatialReference.wkid);
284
- expect((_t = url === null || url === void 0 ? void 0 : url.envelope) === null || _t === void 0 ? void 0 : _t.spatialReference.latestWkid).to.be.equal(overrideGeom.geom.spatialReference.latestWkid);
285
- // Now test with a different tolerance value
286
- url = provider3.constructFeatureUrl(0, 0, 0, "PBF", overrideGeom, undefined, 10);
287
- expect(url === null || url === void 0 ? void 0 : url.url).to.equals(`https://dummy.com/0/query?f=PBF&resultType=tile&maxRecordCountFactor=3&returnExceededLimitFeatures=false&outSR=102100&geometryType=esriGeometryEnvelope&geometry=%7B%22xmin%22%3A-50%2C%22ymin%22%3A-50%2C%22xmax%22%3A50%2C%22ymax%22%3A50%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D&units=esriSRUnit_Meter&inSR=102100&quantizationParameters=%7B%22mode%22%3A%22view%22%2C%22originPosition%22%3A%22upperLeft%22%2C%22tolerance%22%3A78271.516953125%2C%22extent%22%3A%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D%7D&distance=782715.16953125`);
288
- expect((_u = url === null || url === void 0 ? void 0 : url.envelope) === null || _u === void 0 ? void 0 : _u.xmin).to.be.closeTo(overrideGeom.geom.xmin, 0.01);
289
- expect((_v = url === null || url === void 0 ? void 0 : url.envelope) === null || _v === void 0 ? void 0 : _v.ymin).to.be.closeTo(overrideGeom.geom.ymin, 0.01);
290
- expect((_w = url === null || url === void 0 ? void 0 : url.envelope) === null || _w === void 0 ? void 0 : _w.xmax).to.be.closeTo(overrideGeom.geom.xmax, 0.01);
291
- expect((_x = url === null || url === void 0 ? void 0 : url.envelope) === null || _x === void 0 ? void 0 : _x.ymax).to.be.closeTo(overrideGeom.geom.ymax, 0.01);
292
- expect((_y = url === null || url === void 0 ? void 0 : url.envelope) === null || _y === void 0 ? void 0 : _y.spatialReference.wkid).to.be.equal(overrideGeom.geom.spatialReference.wkid);
293
- expect((_z = url === null || url === void 0 ? void 0 : url.envelope) === null || _z === void 0 ? void 0 : _z.spatialReference.latestWkid).to.be.equal(overrideGeom.geom.spatialReference.latestWkid);
294
- });
295
- it("should log error when getFeatureInfo cannot be performed", async () => {
296
- const settings = ImageMapLayerSettings.fromJSON({
297
- ...esriFeatureSampleSource,
298
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
299
- });
300
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
301
- return {
302
- defaultVisibility: true,
303
- supportedQueryFormats: "PBF, JSON",
304
- minScale: 600000,
305
- maxScale: 5000,
306
- };
307
- });
308
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
309
- return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
310
- });
311
- sandbox.stub(ArcGisFeatureProvider.prototype, "constructFeatureUrl").callsFake(function _(_row, _column, _zoomLevel, _format, _geomOverride, _outFields, _tolerance, _returnGeometry) {
312
- return undefined;
313
- });
314
- const provider = new ArcGisFeatureProvider(settings);
315
- await provider.initialize();
316
- const featureInfos = [];
317
- const logErrorSpy = sandbox.spy(Logger, "logError");
318
- await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
319
- expect(featureInfos.length).to.equals(0);
320
- expect(logErrorSpy.called).to.be.true;
321
- });
322
- it("should process data in getFeatureInfo", async () => {
323
- const settings = ImageMapLayerSettings.fromJSON({
324
- ...esriFeatureSampleSource,
325
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
326
- });
327
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
328
- return {
329
- defaultVisibility: true,
330
- supportedQueryFormats: "PBF, JSON",
331
- supportsCoordinatesQuantization: true,
332
- minScale: 600000,
333
- maxScale: 5000,
334
- };
335
- });
336
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
337
- return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
338
- });
339
- sandbox.stub(ArcGISImageryProvider.prototype, "fetch").callsFake(async function _(_url, _options) {
340
- const test = {
341
- headers: { "content-type": "pbf" },
342
- arrayBuffer: async () => {
343
- const byteArray = Base64EncodedString.toUint8Array(PhillyLandmarksDataset.phillyTransportationGetFeatureInfoQueryEncodedPbf);
344
- return Promise.resolve(byteArray ? ByteStream.fromUint8Array(byteArray).arrayBuffer : undefined);
345
- },
346
- status: 200,
347
- }; // By using unknown type, I can define parts of Response I really need
348
- return test;
349
- });
350
- const provider = new ArcGisFeatureProvider(settings);
351
- await provider.initialize();
352
- const featureInfos = [];
353
- const logErrorSpy = sandbox.spy(Logger, "logError");
354
- await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
355
- expect(featureInfos.length).to.equals(1);
356
- expect(logErrorSpy.calledOnce).to.be.false;
357
- });
358
- it("should log error when exceed transfert limit", async () => {
359
- const settings = ImageMapLayerSettings.fromJSON({
360
- ...esriFeatureSampleSource,
361
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
362
- });
363
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
364
- return {
365
- defaultVisibility: true,
366
- supportedQueryFormats: "PBF, JSON",
367
- minScale: 600000,
368
- maxScale: 5000,
369
- };
370
- });
371
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
372
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
373
- });
374
- sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
375
- return { exceedTransferLimit: true, data: undefined };
376
- });
377
- const provider = new ArcGisFeatureProvider(settings);
378
- await provider.initialize();
379
- const featureInfos = [];
380
- const logErrorSpy = sandbox.spy(Logger, "logError");
381
- await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
382
- expect(featureInfos.length).to.equals(0);
383
- expect(logErrorSpy.calledOnce).to.be.true;
384
- });
385
- it("should log error when exceed exception thrown limit", async () => {
386
- const settings = ImageMapLayerSettings.fromJSON({
387
- ...esriFeatureSampleSource,
388
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
389
- });
390
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
391
- return {
392
- defaultVisibility: true,
393
- supportedQueryFormats: "PBF, JSON",
394
- minScale: 600000,
395
- maxScale: 5000,
396
- };
397
- });
398
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
399
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
400
- });
401
- sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
402
- throw new Error();
403
- });
404
- const provider = new ArcGisFeatureProvider(settings);
405
- await provider.initialize();
406
- const featureInfos = [];
407
- const logErrorSpy = sandbox.spy(Logger, "logError");
408
- await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
409
- expect(featureInfos.length).to.equals(0);
410
- expect(logErrorSpy.calledOnce).to.be.true;
411
- });
412
- it("should debug Feature Geom", async () => {
413
- const settings = ImageMapLayerSettings.fromJSON({
414
- ...esriFeatureSampleSource,
415
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
416
- });
417
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
418
- return {
419
- defaultVisibility: true,
420
- supportedQueryFormats: "PBF, JSON",
421
- minScale: 600000,
422
- maxScale: 5000,
423
- };
424
- });
425
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
426
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
427
- });
428
- sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
429
- return { data: {
430
- toObject: () => undefined,
431
- } };
432
- });
433
- const provider = new ArcGisFeatureProvider(settings);
434
- await provider.initialize();
435
- provider._debugFeatureGeom = true;
436
- const featureInfos = [];
437
- const logInfoSpy = sandbox.spy(Logger, "logInfo");
438
- await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
439
- expect(featureInfos.length).to.equals(0);
440
- expect(logInfoSpy.callCount).to.equals(2);
441
- });
442
- it("should compute computeTileWorld2CanvasTransform", async () => {
443
- const settings = ImageMapLayerSettings.fromJSON({
444
- ...esriFeatureSampleSource,
445
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
446
- });
447
- const worldSize = 100;
448
- const canvasSize = 10;
449
- const provider = new ArcGisFeatureProvider(settings);
450
- const getEPSG3857ExtentStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getEPSG3857Extent").callsFake(function (_row, _column, _zoomLevel) {
451
- return { left: 0, right: worldSize, bottom: 0, top: worldSize };
452
- });
453
- sandbox.stub(provider, "tileSize").get(function () {
454
- return canvasSize; // return a size of 10 to simplicity
455
- });
456
- let transform = provider.computeTileWorld2CanvasTransform(0, 0, 0);
457
- let worldPoint = Point3d.createFrom({ x: worldSize * 0.5, y: worldSize * 0.5, z: 0 });
458
- let transformedPoint = transform === null || transform === void 0 ? void 0 : transform.multiplyPoint3d(worldPoint);
459
- // Make sure center point remains in the center
460
- expect(transformedPoint).to.not.undefined;
461
- expect(transformedPoint.x).to.equals(canvasSize * 0.5);
462
- expect(transformedPoint.y).to.equals(canvasSize * 0.5);
463
- expect(transformedPoint.z).to.equals(0);
464
- // Check that y-axis get flipped
465
- worldPoint = Point3d.createFrom({ x: 0, y: 10, z: 0 });
466
- transformedPoint = transform === null || transform === void 0 ? void 0 : transform.multiplyPoint3d(worldPoint);
467
- expect(transformedPoint.x).to.equals(0);
468
- expect(transformedPoint.y).to.equals(9);
469
- expect(transformedPoint.z).to.equals(0);
470
- // Now check translation has been applied (origin shift)
471
- getEPSG3857ExtentStub.restore();
472
- sandbox.stub(ArcGisFeatureProvider.prototype, "getEPSG3857Extent").callsFake(function (_row, _column, _zoomLevel) {
473
- return { left: worldSize, right: worldSize * 2, bottom: worldSize, top: worldSize * 2 };
474
- });
475
- worldPoint = Point3d.createFrom({ x: worldSize, y: worldSize, z: 0 });
476
- transform = provider.computeTileWorld2CanvasTransform(0, 0, 0);
477
- transformedPoint = transform === null || transform === void 0 ? void 0 : transform.multiplyPoint3d(worldPoint);
478
- expect(transformedPoint).to.not.undefined;
479
- expect(transformedPoint.x).to.equals(0);
480
- expect(transformedPoint.y).to.equals(10);
481
- expect(transformedPoint.z).to.equals(0);
482
- });
483
- it("should loadTile from PBF request", async () => {
484
- const settings = ImageMapLayerSettings.fromJSON({
485
- ...esriFeatureSampleSource,
486
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
487
- });
488
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
489
- return {
490
- defaultVisibility: true,
491
- supportedQueryFormats: "PBF",
492
- supportsCoordinatesQuantization: true,
493
- };
494
- });
495
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
496
- return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
497
- });
498
- sandbox.stub(HTMLCanvasElement.prototype, "getContext").callsFake(function _(_contextId, _options) {
499
- return {};
500
- });
501
- sandbox.stub(HTMLCanvasElement.prototype, "toDataURL").callsFake(function _(_type, _quality) {
502
- return `data:image/png;base64,${pngTransparent1x1}`;
503
- });
504
- const providerStub = sandbox.stub(ArcGisFeatureProvider.prototype, "fetchTile").callsFake(async function _() {
505
- return new ArcGisFeatureResponse("PBF", Promise.resolve({}));
506
- });
507
- sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
508
- return {
509
- exceedTransferLimit: false,
510
- data: { toObject: () => undefined },
511
- };
512
- });
513
- // toDataURL string;
514
- const readAndRenderSpy = sandbox.spy(ArcGisFeaturePBF.prototype, "readAndRender");
515
- const computeTransfoSpy = sandbox.spy(ArcGisFeatureProvider.prototype, "computeTileWorld2CanvasTransform");
516
- const provider = new ArcGisFeatureProvider(settings);
517
- await provider.initialize();
518
- const tileData = await provider.loadTile(0, 0, 0);
519
- expect(tileData).to.not.undefined;
520
- expect((tileData === null || tileData === void 0 ? void 0 : tileData.data) instanceof Uint8Array).to.be.true;
521
- expect(tileData === null || tileData === void 0 ? void 0 : tileData.data).to.eqls(base64StringToUint8Array(pngTransparent1x1));
522
- expect(tileData === null || tileData === void 0 ? void 0 : tileData.format).to.equals(ImageSourceFormat.Png);
523
- expect(providerStub.calledOnce).to.be.true;
524
- expect(readAndRenderSpy.calledOnce).to.be.true;
525
- expect(computeTransfoSpy.calledOnce).to.be.false; // Should not be called since we have supportsCoordinatesQuantization in layer metadata
526
- });
527
- it("should loadTile from JSON request", async () => {
528
- const settings = ImageMapLayerSettings.fromJSON({
529
- ...esriFeatureSampleSource,
530
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
531
- });
532
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
533
- return {
534
- defaultVisibility: true,
535
- supportedQueryFormats: "JSON",
536
- };
537
- });
538
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
539
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
540
- });
541
- sandbox.stub(HTMLCanvasElement.prototype, "getContext").callsFake(function _(_contextId, _options) {
542
- return {};
543
- });
544
- sandbox.stub(HTMLCanvasElement.prototype, "toDataURL").callsFake(function _(_type, _quality) {
545
- return `data:image/png;base64,${pngTransparent1x1}`;
546
- });
547
- const providerStub = sandbox.stub(ArcGisFeatureProvider.prototype, "fetchTile").callsFake(async function _() {
548
- return new ArcGisFeatureResponse("JSON", Promise.resolve({}));
549
- });
550
- sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
551
- return {
552
- exceedTransferLimit: false,
553
- data: { toObject: () => undefined },
554
- };
555
- });
556
- const readAndRenderSpy = sandbox.spy(ArcGisFeatureJSON.prototype, "readAndRender");
557
- const computeTransfoSpy = sandbox.spy(ArcGisFeatureProvider.prototype, "computeTileWorld2CanvasTransform");
558
- const provider = new ArcGisFeatureProvider(settings);
559
- await provider.initialize();
560
- const tileData = await provider.loadTile(0, 0, 0);
561
- expect(tileData).to.not.undefined;
562
- expect((tileData === null || tileData === void 0 ? void 0 : tileData.data) instanceof Uint8Array).to.be.true;
563
- expect(tileData === null || tileData === void 0 ? void 0 : tileData.data).to.eqls(base64StringToUint8Array(pngTransparent1x1));
564
- expect(tileData === null || tileData === void 0 ? void 0 : tileData.format).to.equals(ImageSourceFormat.Png);
565
- expect(providerStub.calledOnce).to.be.true;
566
- expect(readAndRenderSpy.calledOnce).to.be.true;
567
- expect(computeTransfoSpy.calledOnce).to.be.true; // Should be called since we dont have _supportsCoordinatesQuantization in layer metadata
568
- });
569
- it("should make sub request if loadtile request return 'exceedTransferLimit'", async () => {
570
- const settings = ImageMapLayerSettings.fromJSON({
571
- ...esriFeatureSampleSource,
572
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
573
- });
574
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
575
- return {
576
- defaultVisibility: true,
577
- supportedQueryFormats: "JSON",
578
- };
579
- });
580
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
581
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
582
- });
583
- sandbox.stub(HTMLCanvasElement.prototype, "getContext").callsFake(function _(_contextId, _options) {
584
- return {};
585
- });
586
- sandbox.stub(HTMLCanvasElement.prototype, "toDataURL").callsFake(function _(_type, _quality) {
587
- return `data:image/png;base64,${pngTransparent1x1}`;
588
- });
589
- const extentSize = 100;
590
- const fetchTileStub = sandbox.stub(ArcGisFeatureProvider.prototype, "fetchTile").callsFake(async function _() {
591
- const envelope = {
592
- xmin: 0,
593
- ymin: 0,
594
- xmax: extentSize,
595
- ymax: extentSize,
596
- spatialReference: {
597
- wkid: 102100,
598
- latestWkid: 3857,
599
- }
600
- };
601
- return new ArcGisFeatureResponse("JSON", Promise.resolve({}), envelope);
602
- });
603
- let firstCall = true;
604
- sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
605
- const exceed = firstCall === true;
606
- firstCall = false;
607
- return {
608
- exceedTransferLimit: exceed,
609
- data: { toObject: () => undefined },
610
- };
611
- });
612
- const readAndRenderSpy = sandbox.spy(ArcGisFeatureJSON.prototype, "readAndRender");
613
- const provider = new ArcGisFeatureProvider(settings);
614
- await provider.initialize();
615
- await provider.loadTile(0, 0, 0);
616
- // We should have 5 calls:
617
- // Call #1 : initial call for 0,0,0 and it returns 'exceedTransferLimit'
618
- // Calls #2-5: Four calls which represent a call for each sub-envelope (initial extent divided by 4)
619
- expect(fetchTileStub.getCalls().length).to.equals(5);
620
- expect(fetchTileStub.getCalls()[1].args[3]).to.eqls({
621
- xmin: 0, ymin: 0, xmax: extentSize * 0.5, ymax: extentSize * 0.5,
622
- spatialReference: { wkid: 102100, latestWkid: 3857,
623
- }
624
- });
625
- expect(fetchTileStub.getCalls()[2].args[3]).to.eqls({
626
- xmin: 0, ymin: extentSize * 0.5, xmax: extentSize * 0.5, ymax: extentSize,
627
- spatialReference: { wkid: 102100, latestWkid: 3857,
628
- }
629
- });
630
- expect(fetchTileStub.getCalls()[3].args[3]).to.eqls({
631
- xmin: extentSize * 0.5, ymin: 0, xmax: extentSize, ymax: extentSize * 0.5,
632
- spatialReference: { wkid: 102100, latestWkid: 3857,
633
- }
634
- });
635
- expect(fetchTileStub.getCalls()[4].args[3]).to.eqls({
636
- xmin: extentSize * 0.5, ymin: extentSize * 0.5, xmax: extentSize, ymax: extentSize,
637
- spatialReference: { wkid: 102100, latestWkid: 3857,
638
- }
639
- });
640
- expect(readAndRenderSpy.getCalls().length).to.equals(4);
641
- });
642
- it("fetchTile should return undefined when to format defined", async () => {
643
- const settings = ImageMapLayerSettings.fromJSON({
644
- ...esriFeatureSampleSource,
645
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
646
- });
647
- const provider = new ArcGisFeatureProvider(settings);
648
- // make a first request with init, should return undefined because of missing format
649
- const tileData = await provider.fetchTile(0, 0, 0);
650
- expect(tileData).to.be.undefined;
651
- });
652
- it("fetchTile should call fetch with the proper URL", async () => {
653
- const settings = ImageMapLayerSettings.fromJSON({
654
- ...esriFeatureSampleSource,
655
- subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
656
- });
657
- sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
658
- return {
659
- defaultVisibility: true,
660
- supportedQueryFormats: "JSON",
661
- };
662
- });
663
- sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
664
- return { accessTokenRequired: false, content: { capabilities: "Query" } };
665
- });
666
- const fetchStub = sandbox.stub(ArcGISImageryProvider.prototype, "fetch");
667
- sandbox.stub(ArcGisFeatureProvider.prototype, "constructFeatureUrl").callsFake(function _(_row, _column, _zoomLevel, _format, _geomOverride, _outFields, _tolerance, _returnGeometry) {
668
- return { url: settings.url };
669
- });
670
- const provider = new ArcGisFeatureProvider(settings);
671
- await provider.initialize();
672
- const response = await provider.fetchTile(0, 0, 0);
673
- expect(response).to.not.undefined;
674
- expect(fetchStub.calledOnce).to.be.true;
675
- const test1 = fetchStub.getCall(0).firstArg;
676
- expect(test1.toString()).to.equals(new URL(settings.url).toString());
677
- });
678
- });
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { Base64EncodedString, Cartographic, ImageMapLayerSettings, ImageSourceFormat, ServerError } from "@itwin/core-common";
6
+ import * as chai from "chai";
7
+ import * as chaiAsPromised from "chai-as-promised";
8
+ import { ArcGisFeatureMapLayerFormat } from "../../ArcGisFeature/ArcGisFeatureFormat";
9
+ import { ArcGisFeatureProvider } from "../../map-layers-formats";
10
+ import * as sinon from "sinon";
11
+ import { ArcGISImageryProvider, ArcGisUtilities, MapLayerImageryProviderStatus, QuadId } from "@itwin/core-frontend";
12
+ import { NewYorkDataset } from "./NewYorkDataset";
13
+ import { base64StringToUint8Array, ByteStream, Logger } from "@itwin/core-bentley";
14
+ import { PhillyLandmarksDataset } from "./PhillyLandmarksDataset";
15
+ import { ArcGisFeatureResponse } from "../../ArcGisFeature/ArcGisFeatureResponse";
16
+ import { Point3d } from "@itwin/core-geometry";
17
+ import { ArcGisFeaturePBF } from "../../ArcGisFeature/ArcGisFeaturePBF";
18
+ import { ArcGisFeatureJSON } from "../../ArcGisFeature/ArcGisFeatureJSON";
19
+ const expect = chai.expect;
20
+ chai.use(chaiAsPromised);
21
+ const esriFeatureSampleSource = { name: "dummyFeatureLayer", url: "https://dummy.com", formatId: ArcGisFeatureMapLayerFormat.formatId };
22
+ const pngTransparent1x1 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==";
23
+ describe("ArcGisFeatureProvider", () => {
24
+ const sandbox = sinon.createSandbox();
25
+ afterEach(async () => {
26
+ sandbox.restore();
27
+ });
28
+ it("should initialize with valid data", async () => {
29
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
30
+ return { accessTokenRequired: false, content: NewYorkDataset.serviceCapabilities };
31
+ });
32
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function _(_layerId) {
33
+ return NewYorkDataset.streetsLayerCapabilities;
34
+ });
35
+ const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
36
+ const provider = new ArcGisFeatureProvider(settings);
37
+ await provider.initialize();
38
+ expect(provider._minDepthFromLod).to.equals(11);
39
+ expect(provider._maxDepthFromLod).to.equals(22);
40
+ });
41
+ it("should not initialize with no service metadata", async () => {
42
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
43
+ return undefined;
44
+ });
45
+ const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
46
+ const provider = new ArcGisFeatureProvider(settings);
47
+ await expect(provider.initialize()).to.be.rejectedWith(ServerError);
48
+ });
49
+ it("should update status when invalid token error from service", async () => {
50
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
51
+ return { accessTokenRequired: false, content: { error: { code: 499 } } };
52
+ });
53
+ const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
54
+ const provider = new ArcGisFeatureProvider(settings);
55
+ const raiseEventSpy = sandbox.spy(provider.onStatusChanged, "raiseEvent");
56
+ await provider.initialize();
57
+ expect(provider.status).to.equals(MapLayerImageryProviderStatus.RequireAuth);
58
+ expect(raiseEventSpy.calledOnceWith(provider)).to.be.true;
59
+ });
60
+ it("should throw query capability not supported", async () => {
61
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
62
+ return { accessTokenRequired: false, content: { capabilities: "Test" } };
63
+ });
64
+ const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
65
+ const provider = new ArcGisFeatureProvider(settings);
66
+ await expect(provider.initialize()).to.be.rejectedWith(ServerError);
67
+ });
68
+ it("should pick the first visible sub-layer when multiple visible sub-layers", async () => {
69
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
70
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
71
+ });
72
+ const settings = ImageMapLayerSettings.fromJSON({
73
+ ...esriFeatureSampleSource,
74
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
75
+ });
76
+ const provider = new ArcGisFeatureProvider(settings);
77
+ provider._format = "JSON";
78
+ await provider.initialize();
79
+ expect(provider._layerId).to.equals(settings.subLayers[0].id);
80
+ });
81
+ it("should pick sub-layers from service metadata if none provided on layer settings", async () => {
82
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
83
+ return { accessTokenRequired: false, content: { capabilities: "Query",
84
+ layers: [
85
+ {
86
+ id: 0,
87
+ },
88
+ {
89
+ id: 1,
90
+ },
91
+ ] },
92
+ };
93
+ });
94
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (id) {
95
+ if (id === 1) {
96
+ return { defaultVisibility: true };
97
+ }
98
+ return undefined;
99
+ });
100
+ const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
101
+ const provider = new ArcGisFeatureProvider(settings);
102
+ provider._format = "JSON";
103
+ await provider.initialize();
104
+ expect(provider._layerId).to.equals(1);
105
+ expect(provider._layerMetadata).to.eql({ defaultVisibility: true });
106
+ });
107
+ it("should throw error if no layers in capabilities", async () => {
108
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
109
+ return { accessTokenRequired: false, content: { capabilities: "Query", layers: [] } };
110
+ });
111
+ const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
112
+ const provider = new ArcGisFeatureProvider(settings);
113
+ await expect(provider.initialize()).to.be.rejectedWith(ServerError);
114
+ });
115
+ it("should throw if no layer metadata from service", async () => {
116
+ const settings = ImageMapLayerSettings.fromJSON({
117
+ ...esriFeatureSampleSource,
118
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
119
+ });
120
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
121
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
122
+ });
123
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
124
+ return undefined;
125
+ });
126
+ const provider = new ArcGisFeatureProvider(settings);
127
+ await expect(provider.initialize()).to.be.rejectedWith(ServerError);
128
+ });
129
+ it("should read supported supported format", async () => {
130
+ const settings = ImageMapLayerSettings.fromJSON({
131
+ ...esriFeatureSampleSource,
132
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
133
+ });
134
+ let getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
135
+ return { defaultVisibility: true, supportedQueryFormats: "PBF, JSON" };
136
+ });
137
+ const getServiceJsonStub = sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
138
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
139
+ });
140
+ let provider = new ArcGisFeatureProvider(settings);
141
+ await provider.initialize();
142
+ expect(provider.format).to.equals("JSON");
143
+ // PBF requires 'supportsCoordinatesQuantization'
144
+ getServiceJsonStub.restore();
145
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
146
+ return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
147
+ });
148
+ getLayerMetadataStub.restore();
149
+ getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
150
+ return { defaultVisibility: true, supportsCoordinatesQuantization: true, supportedQueryFormats: "PBF, JSON" };
151
+ });
152
+ provider = new ArcGisFeatureProvider(settings);
153
+ await provider.initialize();
154
+ expect(provider.format).to.equals("PBF");
155
+ getLayerMetadataStub.restore();
156
+ getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
157
+ return { defaultVisibility: true, supportedQueryFormats: "JSON" };
158
+ });
159
+ getServiceJsonStub.restore();
160
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
161
+ return { accessTokenRequired: false, content: { currentVersion: 10.91, capabilities: "Query", supportsCoordinatesQuantization: true } };
162
+ });
163
+ provider = new ArcGisFeatureProvider(settings);
164
+ await provider.initialize();
165
+ expect(provider.format).to.equals("JSON");
166
+ getLayerMetadataStub.restore();
167
+ getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
168
+ return { defaultVisibility: true, supportedQueryFormats: "JSON" };
169
+ });
170
+ provider = new ArcGisFeatureProvider(settings);
171
+ await provider.initialize();
172
+ expect(provider.format).to.equals("JSON");
173
+ getLayerMetadataStub.restore();
174
+ getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
175
+ return { defaultVisibility: true, supportedQueryFormats: "" };
176
+ });
177
+ provider = new ArcGisFeatureProvider(settings);
178
+ await expect(provider.initialize()).to.be.rejectedWith(ServerError);
179
+ });
180
+ it("should compute minLod/maxLod", async () => {
181
+ const settings = ImageMapLayerSettings.fromJSON({
182
+ ...esriFeatureSampleSource,
183
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
184
+ });
185
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
186
+ return {
187
+ defaultVisibility: true,
188
+ supportedQueryFormats: "PBF, JSON",
189
+ minScale: 600000,
190
+ maxScale: 5000,
191
+ };
192
+ });
193
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
194
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
195
+ });
196
+ const provider = new ArcGisFeatureProvider(settings);
197
+ await provider.initialize();
198
+ expect(provider._minDepthFromLod).to.equals(9);
199
+ expect(provider._maxDepthFromLod).to.equals(15);
200
+ });
201
+ it("should construct empty url", async () => {
202
+ const settings = ImageMapLayerSettings.fromJSON(esriFeatureSampleSource);
203
+ const provider = new ArcGisFeatureProvider(settings);
204
+ const url = await provider.constructUrl(0, 0, 0);
205
+ expect(url).to.equals("");
206
+ });
207
+ it("should construct feature query url", async () => {
208
+ const settings = ImageMapLayerSettings.fromJSON({
209
+ ...esriFeatureSampleSource,
210
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
211
+ });
212
+ let getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
213
+ return {
214
+ defaultVisibility: true,
215
+ supportedQueryFormats: "PBF, JSON",
216
+ };
217
+ });
218
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
219
+ return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
220
+ });
221
+ const provider = new ArcGisFeatureProvider(settings);
222
+ await provider.initialize();
223
+ let url = provider.constructFeatureUrl(0, 0, 0, "PBF");
224
+ const extent = {
225
+ xmin: -20037508.34,
226
+ ymin: -20037508.33,
227
+ xmax: 20037508.34,
228
+ ymax: 20037508.34,
229
+ spatialReference: {
230
+ wkid: 102100,
231
+ latestWkid: 3857,
232
+ },
233
+ };
234
+ expect(url?.url).to.equals(`https://dummy.com/0/query?f=PBF&resultType=tile&maxRecordCountFactor=3&returnExceededLimitFeatures=false&outSR=102100&geometryType=esriGeometryEnvelope&geometry=%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D&units=esriSRUnit_Meter&inSR=102100`);
235
+ expect(url?.envelope?.xmin).to.be.closeTo(extent.xmin, 0.01);
236
+ expect(url?.envelope?.ymin).to.be.closeTo(extent.ymin, 0.01);
237
+ expect(url?.envelope?.xmax).to.be.closeTo(extent.xmax, 0.01);
238
+ expect(url?.envelope?.ymax).to.be.closeTo(extent.ymax, 0.01);
239
+ expect(url?.envelope?.spatialReference.wkid).to.be.equal(102100);
240
+ expect(url?.envelope?.spatialReference.latestWkid).to.be.equal(3857);
241
+ // Now turn ON 'supportsCoordinatesQuantization' to ON
242
+ getLayerMetadataStub.restore();
243
+ getLayerMetadataStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
244
+ return {
245
+ defaultVisibility: true,
246
+ supportedQueryFormats: "PBF, JSON",
247
+ supportsCoordinatesQuantization: true,
248
+ };
249
+ });
250
+ const provider2 = new ArcGisFeatureProvider(settings);
251
+ await provider2.initialize();
252
+ url = provider2.constructFeatureUrl(0, 0, 0, "PBF");
253
+ expect(url?.url).to.equals(`https://dummy.com/0/query?f=PBF&resultType=tile&maxRecordCountFactor=3&returnExceededLimitFeatures=false&outSR=102100&geometryType=esriGeometryEnvelope&geometry=%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D&units=esriSRUnit_Meter&inSR=102100&quantizationParameters=%7B%22mode%22%3A%22view%22%2C%22originPosition%22%3A%22upperLeft%22%2C%22tolerance%22%3A78271.516953125%2C%22extent%22%3A%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D%7D`);
254
+ expect(url?.envelope?.xmin).to.be.closeTo(extent.xmin, 0.01);
255
+ expect(url?.envelope?.ymin).to.be.closeTo(extent.ymin, 0.01);
256
+ expect(url?.envelope?.xmax).to.be.closeTo(extent.xmax, 0.01);
257
+ expect(url?.envelope?.ymax).to.be.closeTo(extent.ymax, 0.01);
258
+ expect(url?.envelope?.spatialReference.wkid).to.be.equal(extent.spatialReference.wkid);
259
+ expect(url?.envelope?.spatialReference.latestWkid).to.be.equal(extent.spatialReference.latestWkid);
260
+ // Test passing an override geometry
261
+ const overrideGeom = {
262
+ type: "esriGeometryEnvelope",
263
+ geom: {
264
+ xmin: -50,
265
+ ymin: -50,
266
+ xmax: 50,
267
+ ymax: 50,
268
+ spatialReference: {
269
+ wkid: 102100,
270
+ latestWkid: 3857,
271
+ },
272
+ },
273
+ };
274
+ const provider3 = new ArcGisFeatureProvider(settings);
275
+ await provider3.initialize();
276
+ url = provider3.constructFeatureUrl(0, 0, 0, "PBF", overrideGeom);
277
+ expect(url?.url).to.equals(`https://dummy.com/0/query?f=PBF&resultType=tile&maxRecordCountFactor=3&returnExceededLimitFeatures=false&outSR=102100&geometryType=esriGeometryEnvelope&geometry=%7B%22xmin%22%3A-50%2C%22ymin%22%3A-50%2C%22xmax%22%3A50%2C%22ymax%22%3A50%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D&units=esriSRUnit_Meter&inSR=102100&quantizationParameters=%7B%22mode%22%3A%22view%22%2C%22originPosition%22%3A%22upperLeft%22%2C%22tolerance%22%3A78271.516953125%2C%22extent%22%3A%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D%7D`);
278
+ expect(url?.envelope?.xmin).to.be.closeTo(overrideGeom.geom.xmin, 0.01);
279
+ expect(url?.envelope?.ymin).to.be.closeTo(overrideGeom.geom.ymin, 0.01);
280
+ expect(url?.envelope?.xmax).to.be.closeTo(overrideGeom.geom.xmax, 0.01);
281
+ expect(url?.envelope?.ymax).to.be.closeTo(overrideGeom.geom.ymax, 0.01);
282
+ expect(url?.envelope?.spatialReference.wkid).to.be.equal(overrideGeom.geom.spatialReference.wkid);
283
+ expect(url?.envelope?.spatialReference.latestWkid).to.be.equal(overrideGeom.geom.spatialReference.latestWkid);
284
+ // Now test with a different tolerance value
285
+ url = provider3.constructFeatureUrl(0, 0, 0, "PBF", overrideGeom, undefined, 10);
286
+ expect(url?.url).to.equals(`https://dummy.com/0/query?f=PBF&resultType=tile&maxRecordCountFactor=3&returnExceededLimitFeatures=false&outSR=102100&geometryType=esriGeometryEnvelope&geometry=%7B%22xmin%22%3A-50%2C%22ymin%22%3A-50%2C%22xmax%22%3A50%2C%22ymax%22%3A50%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D&units=esriSRUnit_Meter&inSR=102100&quantizationParameters=%7B%22mode%22%3A%22view%22%2C%22originPosition%22%3A%22upperLeft%22%2C%22tolerance%22%3A78271.516953125%2C%22extent%22%3A%7B%22xmin%22%3A-20037508.34%2C%22ymin%22%3A-20037508.339999996%2C%22xmax%22%3A20037508.34%2C%22ymax%22%3A20037508.340000004%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D%7D&distance=782715.16953125`);
287
+ expect(url?.envelope?.xmin).to.be.closeTo(overrideGeom.geom.xmin, 0.01);
288
+ expect(url?.envelope?.ymin).to.be.closeTo(overrideGeom.geom.ymin, 0.01);
289
+ expect(url?.envelope?.xmax).to.be.closeTo(overrideGeom.geom.xmax, 0.01);
290
+ expect(url?.envelope?.ymax).to.be.closeTo(overrideGeom.geom.ymax, 0.01);
291
+ expect(url?.envelope?.spatialReference.wkid).to.be.equal(overrideGeom.geom.spatialReference.wkid);
292
+ expect(url?.envelope?.spatialReference.latestWkid).to.be.equal(overrideGeom.geom.spatialReference.latestWkid);
293
+ });
294
+ it("should log error when getFeatureInfo cannot be performed", async () => {
295
+ const settings = ImageMapLayerSettings.fromJSON({
296
+ ...esriFeatureSampleSource,
297
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
298
+ });
299
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
300
+ return {
301
+ defaultVisibility: true,
302
+ supportedQueryFormats: "PBF, JSON",
303
+ minScale: 600000,
304
+ maxScale: 5000,
305
+ };
306
+ });
307
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
308
+ return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
309
+ });
310
+ sandbox.stub(ArcGisFeatureProvider.prototype, "constructFeatureUrl").callsFake(function _(_row, _column, _zoomLevel, _format, _geomOverride, _outFields, _tolerance, _returnGeometry) {
311
+ return undefined;
312
+ });
313
+ const provider = new ArcGisFeatureProvider(settings);
314
+ await provider.initialize();
315
+ const featureInfos = [];
316
+ const logErrorSpy = sandbox.spy(Logger, "logError");
317
+ await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
318
+ expect(featureInfos.length).to.equals(0);
319
+ expect(logErrorSpy.called).to.be.true;
320
+ });
321
+ it("should process data in getFeatureInfo", async () => {
322
+ const settings = ImageMapLayerSettings.fromJSON({
323
+ ...esriFeatureSampleSource,
324
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
325
+ });
326
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
327
+ return {
328
+ defaultVisibility: true,
329
+ supportedQueryFormats: "PBF, JSON",
330
+ supportsCoordinatesQuantization: true,
331
+ minScale: 600000,
332
+ maxScale: 5000,
333
+ };
334
+ });
335
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
336
+ return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
337
+ });
338
+ sandbox.stub(ArcGISImageryProvider.prototype, "fetch").callsFake(async function _(_url, _options) {
339
+ const test = {
340
+ headers: { "content-type": "pbf" },
341
+ arrayBuffer: async () => {
342
+ const byteArray = Base64EncodedString.toUint8Array(PhillyLandmarksDataset.phillyTransportationGetFeatureInfoQueryEncodedPbf);
343
+ return Promise.resolve(byteArray ? ByteStream.fromUint8Array(byteArray).arrayBuffer : undefined);
344
+ },
345
+ status: 200,
346
+ }; // By using unknown type, I can define parts of Response I really need
347
+ return test;
348
+ });
349
+ const provider = new ArcGisFeatureProvider(settings);
350
+ await provider.initialize();
351
+ const featureInfos = [];
352
+ const logErrorSpy = sandbox.spy(Logger, "logError");
353
+ await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
354
+ expect(featureInfos.length).to.equals(1);
355
+ expect(logErrorSpy.calledOnce).to.be.false;
356
+ });
357
+ it("should log error when exceed transfert limit", async () => {
358
+ const settings = ImageMapLayerSettings.fromJSON({
359
+ ...esriFeatureSampleSource,
360
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
361
+ });
362
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
363
+ return {
364
+ defaultVisibility: true,
365
+ supportedQueryFormats: "PBF, JSON",
366
+ minScale: 600000,
367
+ maxScale: 5000,
368
+ };
369
+ });
370
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
371
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
372
+ });
373
+ sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
374
+ return { exceedTransferLimit: true, data: undefined };
375
+ });
376
+ const provider = new ArcGisFeatureProvider(settings);
377
+ await provider.initialize();
378
+ const featureInfos = [];
379
+ const logErrorSpy = sandbox.spy(Logger, "logError");
380
+ await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
381
+ expect(featureInfos.length).to.equals(0);
382
+ expect(logErrorSpy.calledOnce).to.be.true;
383
+ });
384
+ it("should log error when exceed exception thrown limit", async () => {
385
+ const settings = ImageMapLayerSettings.fromJSON({
386
+ ...esriFeatureSampleSource,
387
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
388
+ });
389
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
390
+ return {
391
+ defaultVisibility: true,
392
+ supportedQueryFormats: "PBF, JSON",
393
+ minScale: 600000,
394
+ maxScale: 5000,
395
+ };
396
+ });
397
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
398
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
399
+ });
400
+ sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
401
+ throw new Error();
402
+ });
403
+ const provider = new ArcGisFeatureProvider(settings);
404
+ await provider.initialize();
405
+ const featureInfos = [];
406
+ const logErrorSpy = sandbox.spy(Logger, "logError");
407
+ await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
408
+ expect(featureInfos.length).to.equals(0);
409
+ expect(logErrorSpy.calledOnce).to.be.true;
410
+ });
411
+ it("should debug Feature Geom", async () => {
412
+ const settings = ImageMapLayerSettings.fromJSON({
413
+ ...esriFeatureSampleSource,
414
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
415
+ });
416
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
417
+ return {
418
+ defaultVisibility: true,
419
+ supportedQueryFormats: "PBF, JSON",
420
+ minScale: 600000,
421
+ maxScale: 5000,
422
+ };
423
+ });
424
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
425
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
426
+ });
427
+ sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
428
+ return { data: {
429
+ toObject: () => undefined,
430
+ } };
431
+ });
432
+ const provider = new ArcGisFeatureProvider(settings);
433
+ await provider.initialize();
434
+ provider._debugFeatureGeom = true;
435
+ const featureInfos = [];
436
+ const logInfoSpy = sandbox.spy(Logger, "logInfo");
437
+ await provider.getFeatureInfo(featureInfos, new QuadId(0, 0, 0), Cartographic.fromDegrees({ latitude: 46, longitude: -71 }), undefined);
438
+ expect(featureInfos.length).to.equals(0);
439
+ expect(logInfoSpy.callCount).to.equals(2);
440
+ });
441
+ it("should compute computeTileWorld2CanvasTransform", async () => {
442
+ const settings = ImageMapLayerSettings.fromJSON({
443
+ ...esriFeatureSampleSource,
444
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
445
+ });
446
+ const worldSize = 100;
447
+ const canvasSize = 10;
448
+ const provider = new ArcGisFeatureProvider(settings);
449
+ const getEPSG3857ExtentStub = sandbox.stub(ArcGisFeatureProvider.prototype, "getEPSG3857Extent").callsFake(function (_row, _column, _zoomLevel) {
450
+ return { left: 0, right: worldSize, bottom: 0, top: worldSize };
451
+ });
452
+ sandbox.stub(provider, "tileSize").get(function () {
453
+ return canvasSize; // return a size of 10 to simplicity
454
+ });
455
+ let transform = provider.computeTileWorld2CanvasTransform(0, 0, 0);
456
+ let worldPoint = Point3d.createFrom({ x: worldSize * 0.5, y: worldSize * 0.5, z: 0 });
457
+ let transformedPoint = transform?.multiplyPoint3d(worldPoint);
458
+ // Make sure center point remains in the center
459
+ expect(transformedPoint).to.not.undefined;
460
+ expect(transformedPoint.x).to.equals(canvasSize * 0.5);
461
+ expect(transformedPoint.y).to.equals(canvasSize * 0.5);
462
+ expect(transformedPoint.z).to.equals(0);
463
+ // Check that y-axis get flipped
464
+ worldPoint = Point3d.createFrom({ x: 0, y: 10, z: 0 });
465
+ transformedPoint = transform?.multiplyPoint3d(worldPoint);
466
+ expect(transformedPoint.x).to.equals(0);
467
+ expect(transformedPoint.y).to.equals(9);
468
+ expect(transformedPoint.z).to.equals(0);
469
+ // Now check translation has been applied (origin shift)
470
+ getEPSG3857ExtentStub.restore();
471
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getEPSG3857Extent").callsFake(function (_row, _column, _zoomLevel) {
472
+ return { left: worldSize, right: worldSize * 2, bottom: worldSize, top: worldSize * 2 };
473
+ });
474
+ worldPoint = Point3d.createFrom({ x: worldSize, y: worldSize, z: 0 });
475
+ transform = provider.computeTileWorld2CanvasTransform(0, 0, 0);
476
+ transformedPoint = transform?.multiplyPoint3d(worldPoint);
477
+ expect(transformedPoint).to.not.undefined;
478
+ expect(transformedPoint.x).to.equals(0);
479
+ expect(transformedPoint.y).to.equals(10);
480
+ expect(transformedPoint.z).to.equals(0);
481
+ });
482
+ it("should loadTile from PBF request", async () => {
483
+ const settings = ImageMapLayerSettings.fromJSON({
484
+ ...esriFeatureSampleSource,
485
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
486
+ });
487
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
488
+ return {
489
+ defaultVisibility: true,
490
+ supportedQueryFormats: "PBF",
491
+ supportsCoordinatesQuantization: true,
492
+ };
493
+ });
494
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
495
+ return { accessTokenRequired: false, content: { currentVersion: 11, capabilities: "Query" } };
496
+ });
497
+ sandbox.stub(HTMLCanvasElement.prototype, "getContext").callsFake(function _(_contextId, _options) {
498
+ return {};
499
+ });
500
+ sandbox.stub(HTMLCanvasElement.prototype, "toDataURL").callsFake(function _(_type, _quality) {
501
+ return `data:image/png;base64,${pngTransparent1x1}`;
502
+ });
503
+ const providerStub = sandbox.stub(ArcGisFeatureProvider.prototype, "fetchTile").callsFake(async function _() {
504
+ return new ArcGisFeatureResponse("PBF", Promise.resolve({}));
505
+ });
506
+ sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
507
+ return {
508
+ exceedTransferLimit: false,
509
+ data: { toObject: () => undefined },
510
+ };
511
+ });
512
+ // toDataURL string;
513
+ const readAndRenderSpy = sandbox.spy(ArcGisFeaturePBF.prototype, "readAndRender");
514
+ const computeTransfoSpy = sandbox.spy(ArcGisFeatureProvider.prototype, "computeTileWorld2CanvasTransform");
515
+ const provider = new ArcGisFeatureProvider(settings);
516
+ await provider.initialize();
517
+ const tileData = await provider.loadTile(0, 0, 0);
518
+ expect(tileData).to.not.undefined;
519
+ expect(tileData?.data instanceof Uint8Array).to.be.true;
520
+ expect(tileData?.data).to.eqls(base64StringToUint8Array(pngTransparent1x1));
521
+ expect(tileData?.format).to.equals(ImageSourceFormat.Png);
522
+ expect(providerStub.calledOnce).to.be.true;
523
+ expect(readAndRenderSpy.calledOnce).to.be.true;
524
+ expect(computeTransfoSpy.calledOnce).to.be.false; // Should not be called since we have supportsCoordinatesQuantization in layer metadata
525
+ });
526
+ it("should loadTile from JSON request", async () => {
527
+ const settings = ImageMapLayerSettings.fromJSON({
528
+ ...esriFeatureSampleSource,
529
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
530
+ });
531
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
532
+ return {
533
+ defaultVisibility: true,
534
+ supportedQueryFormats: "JSON",
535
+ };
536
+ });
537
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
538
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
539
+ });
540
+ sandbox.stub(HTMLCanvasElement.prototype, "getContext").callsFake(function _(_contextId, _options) {
541
+ return {};
542
+ });
543
+ sandbox.stub(HTMLCanvasElement.prototype, "toDataURL").callsFake(function _(_type, _quality) {
544
+ return `data:image/png;base64,${pngTransparent1x1}`;
545
+ });
546
+ const providerStub = sandbox.stub(ArcGisFeatureProvider.prototype, "fetchTile").callsFake(async function _() {
547
+ return new ArcGisFeatureResponse("JSON", Promise.resolve({}));
548
+ });
549
+ sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
550
+ return {
551
+ exceedTransferLimit: false,
552
+ data: { toObject: () => undefined },
553
+ };
554
+ });
555
+ const readAndRenderSpy = sandbox.spy(ArcGisFeatureJSON.prototype, "readAndRender");
556
+ const computeTransfoSpy = sandbox.spy(ArcGisFeatureProvider.prototype, "computeTileWorld2CanvasTransform");
557
+ const provider = new ArcGisFeatureProvider(settings);
558
+ await provider.initialize();
559
+ const tileData = await provider.loadTile(0, 0, 0);
560
+ expect(tileData).to.not.undefined;
561
+ expect(tileData?.data instanceof Uint8Array).to.be.true;
562
+ expect(tileData?.data).to.eqls(base64StringToUint8Array(pngTransparent1x1));
563
+ expect(tileData?.format).to.equals(ImageSourceFormat.Png);
564
+ expect(providerStub.calledOnce).to.be.true;
565
+ expect(readAndRenderSpy.calledOnce).to.be.true;
566
+ expect(computeTransfoSpy.calledOnce).to.be.true; // Should be called since we dont have _supportsCoordinatesQuantization in layer metadata
567
+ });
568
+ it("should make sub request if loadtile request return 'exceedTransferLimit'", async () => {
569
+ const settings = ImageMapLayerSettings.fromJSON({
570
+ ...esriFeatureSampleSource,
571
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
572
+ });
573
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
574
+ return {
575
+ defaultVisibility: true,
576
+ supportedQueryFormats: "JSON",
577
+ };
578
+ });
579
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
580
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
581
+ });
582
+ sandbox.stub(HTMLCanvasElement.prototype, "getContext").callsFake(function _(_contextId, _options) {
583
+ return {};
584
+ });
585
+ sandbox.stub(HTMLCanvasElement.prototype, "toDataURL").callsFake(function _(_type, _quality) {
586
+ return `data:image/png;base64,${pngTransparent1x1}`;
587
+ });
588
+ const extentSize = 100;
589
+ const fetchTileStub = sandbox.stub(ArcGisFeatureProvider.prototype, "fetchTile").callsFake(async function _() {
590
+ const envelope = {
591
+ xmin: 0,
592
+ ymin: 0,
593
+ xmax: extentSize,
594
+ ymax: extentSize,
595
+ spatialReference: {
596
+ wkid: 102100,
597
+ latestWkid: 3857,
598
+ }
599
+ };
600
+ return new ArcGisFeatureResponse("JSON", Promise.resolve({}), envelope);
601
+ });
602
+ let firstCall = true;
603
+ sandbox.stub(ArcGisFeatureResponse.prototype, "getResponseData").callsFake(async function _() {
604
+ const exceed = firstCall === true;
605
+ firstCall = false;
606
+ return {
607
+ exceedTransferLimit: exceed,
608
+ data: { toObject: () => undefined },
609
+ };
610
+ });
611
+ const readAndRenderSpy = sandbox.spy(ArcGisFeatureJSON.prototype, "readAndRender");
612
+ const provider = new ArcGisFeatureProvider(settings);
613
+ await provider.initialize();
614
+ await provider.loadTile(0, 0, 0);
615
+ // We should have 5 calls:
616
+ // Call #1 : initial call for 0,0,0 and it returns 'exceedTransferLimit'
617
+ // Calls #2-5: Four calls which represent a call for each sub-envelope (initial extent divided by 4)
618
+ expect(fetchTileStub.getCalls().length).to.equals(5);
619
+ expect(fetchTileStub.getCalls()[1].args[3]).to.eqls({
620
+ xmin: 0, ymin: 0, xmax: extentSize * 0.5, ymax: extentSize * 0.5,
621
+ spatialReference: { wkid: 102100, latestWkid: 3857,
622
+ }
623
+ });
624
+ expect(fetchTileStub.getCalls()[2].args[3]).to.eqls({
625
+ xmin: 0, ymin: extentSize * 0.5, xmax: extentSize * 0.5, ymax: extentSize,
626
+ spatialReference: { wkid: 102100, latestWkid: 3857,
627
+ }
628
+ });
629
+ expect(fetchTileStub.getCalls()[3].args[3]).to.eqls({
630
+ xmin: extentSize * 0.5, ymin: 0, xmax: extentSize, ymax: extentSize * 0.5,
631
+ spatialReference: { wkid: 102100, latestWkid: 3857,
632
+ }
633
+ });
634
+ expect(fetchTileStub.getCalls()[4].args[3]).to.eqls({
635
+ xmin: extentSize * 0.5, ymin: extentSize * 0.5, xmax: extentSize, ymax: extentSize,
636
+ spatialReference: { wkid: 102100, latestWkid: 3857,
637
+ }
638
+ });
639
+ expect(readAndRenderSpy.getCalls().length).to.equals(4);
640
+ });
641
+ it("fetchTile should return undefined when to format defined", async () => {
642
+ const settings = ImageMapLayerSettings.fromJSON({
643
+ ...esriFeatureSampleSource,
644
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
645
+ });
646
+ const provider = new ArcGisFeatureProvider(settings);
647
+ // make a first request with init, should return undefined because of missing format
648
+ const tileData = await provider.fetchTile(0, 0, 0);
649
+ expect(tileData).to.be.undefined;
650
+ });
651
+ it("fetchTile should call fetch with the proper URL", async () => {
652
+ const settings = ImageMapLayerSettings.fromJSON({
653
+ ...esriFeatureSampleSource,
654
+ subLayers: [{ id: 0, name: "layer1", visible: true }, { id: 2, name: "layer2", visible: true }]
655
+ });
656
+ sandbox.stub(ArcGisFeatureProvider.prototype, "getLayerMetadata").callsFake(async function (_id) {
657
+ return {
658
+ defaultVisibility: true,
659
+ supportedQueryFormats: "JSON",
660
+ };
661
+ });
662
+ sandbox.stub(ArcGisUtilities, "getServiceJson").callsFake(async function _(_url, _formatId, _userName, _password, _ignoreCache, _requireToken) {
663
+ return { accessTokenRequired: false, content: { capabilities: "Query" } };
664
+ });
665
+ const fetchStub = sandbox.stub(ArcGISImageryProvider.prototype, "fetch");
666
+ sandbox.stub(ArcGisFeatureProvider.prototype, "constructFeatureUrl").callsFake(function _(_row, _column, _zoomLevel, _format, _geomOverride, _outFields, _tolerance, _returnGeometry) {
667
+ return { url: settings.url };
668
+ });
669
+ const provider = new ArcGisFeatureProvider(settings);
670
+ await provider.initialize();
671
+ const response = await provider.fetchTile(0, 0, 0);
672
+ expect(response).to.not.undefined;
673
+ expect(fetchStub.calledOnce).to.be.true;
674
+ const test1 = fetchStub.getCall(0).firstArg;
675
+ expect(test1.toString()).to.equals(new URL(settings.url).toString());
676
+ });
677
+ });
679
678
  //# sourceMappingURL=ArcGisFeatureProvider.test.js.map