@honua/sdk-esri-compat 0.0.6-alpha.0

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 (289) hide show
  1. package/README.md +5 -0
  2. package/contract/edit-session.d.ts +203 -0
  3. package/contract/edit-session.d.ts.map +1 -0
  4. package/contract/edit-session.js +717 -0
  5. package/contract/index.d.ts +20 -0
  6. package/contract/index.d.ts.map +1 -0
  7. package/contract/index.js +15 -0
  8. package/contract/jobs.d.ts +115 -0
  9. package/contract/jobs.d.ts.map +1 -0
  10. package/contract/jobs.js +22 -0
  11. package/contract/source.d.ts +138 -0
  12. package/contract/source.d.ts.map +1 -0
  13. package/contract/source.js +3364 -0
  14. package/contract/spatial-aggregation.d.ts +312 -0
  15. package/contract/spatial-aggregation.d.ts.map +1 -0
  16. package/contract/spatial-aggregation.js +196 -0
  17. package/contract/types.d.ts +542 -0
  18. package/contract/types.d.ts.map +1 -0
  19. package/contract/types.js +171 -0
  20. package/core/batch.d.ts +37 -0
  21. package/core/batch.d.ts.map +1 -0
  22. package/core/batch.js +78 -0
  23. package/core/cache-state.d.ts +76 -0
  24. package/core/cache-state.d.ts.map +1 -0
  25. package/core/cache-state.js +84 -0
  26. package/core/client.d.ts +289 -0
  27. package/core/client.d.ts.map +1 -0
  28. package/core/client.js +2625 -0
  29. package/core/errors.d.ts +68 -0
  30. package/core/errors.d.ts.map +1 -0
  31. package/core/errors.js +116 -0
  32. package/core/grpc-adapter.d.ts +23 -0
  33. package/core/grpc-adapter.d.ts.map +1 -0
  34. package/core/grpc-adapter.js +704 -0
  35. package/core/odata.d.ts +347 -0
  36. package/core/odata.d.ts.map +1 -0
  37. package/core/odata.js +837 -0
  38. package/core/ogc-conformance.d.ts +35 -0
  39. package/core/ogc-conformance.d.ts.map +1 -0
  40. package/core/ogc-conformance.js +121 -0
  41. package/core/ogc-maps.d.ts +45 -0
  42. package/core/ogc-maps.d.ts.map +1 -0
  43. package/core/ogc-maps.js +53 -0
  44. package/core/ogc-processes.d.ts +92 -0
  45. package/core/ogc-processes.d.ts.map +1 -0
  46. package/core/ogc-processes.js +325 -0
  47. package/core/ogc-tiles.d.ts +55 -0
  48. package/core/ogc-tiles.d.ts.map +1 -0
  49. package/core/ogc-tiles.js +81 -0
  50. package/core/pbf-decoder.d.ts +28 -0
  51. package/core/pbf-decoder.d.ts.map +1 -0
  52. package/core/pbf-decoder.js +627 -0
  53. package/core/query-builder.d.ts +261 -0
  54. package/core/query-builder.d.ts.map +1 -0
  55. package/core/query-builder.js +538 -0
  56. package/core/spatial-filter.d.ts +93 -0
  57. package/core/spatial-filter.d.ts.map +1 -0
  58. package/core/spatial-filter.js +153 -0
  59. package/core/stac.d.ts +43 -0
  60. package/core/stac.d.ts.map +1 -0
  61. package/core/stac.js +116 -0
  62. package/core/surfaces.d.ts +464 -0
  63. package/core/surfaces.d.ts.map +1 -0
  64. package/core/surfaces.js +1322 -0
  65. package/core/types.d.ts +1238 -0
  66. package/core/types.d.ts.map +1 -0
  67. package/core/types.js +13 -0
  68. package/core/wfs-capabilities.d.ts +143 -0
  69. package/core/wfs-capabilities.d.ts.map +1 -0
  70. package/core/wfs-capabilities.js +478 -0
  71. package/core/wfs-filter.d.ts +118 -0
  72. package/core/wfs-filter.d.ts.map +1 -0
  73. package/core/wfs-filter.js +586 -0
  74. package/core/wfs.d.ts +219 -0
  75. package/core/wfs.d.ts.map +1 -0
  76. package/core/wfs.js +406 -0
  77. package/core/wms-capabilities.d.ts +110 -0
  78. package/core/wms-capabilities.d.ts.map +1 -0
  79. package/core/wms-capabilities.js +566 -0
  80. package/core/wms-types.d.ts +128 -0
  81. package/core/wms-types.d.ts.map +1 -0
  82. package/core/wms-types.js +32 -0
  83. package/core/wms.d.ts +108 -0
  84. package/core/wms.d.ts.map +1 -0
  85. package/core/wms.js +182 -0
  86. package/core/wmts-capabilities.d.ts +82 -0
  87. package/core/wmts-capabilities.d.ts.map +1 -0
  88. package/core/wmts-capabilities.js +409 -0
  89. package/core/wmts.d.ts +80 -0
  90. package/core/wmts.d.ts.map +1 -0
  91. package/core/wmts.js +173 -0
  92. package/esri-compat/basemap-gallery.d.ts +38 -0
  93. package/esri-compat/basemap-gallery.d.ts.map +1 -0
  94. package/esri-compat/basemap-gallery.js +159 -0
  95. package/esri-compat/basemap-layer-list.d.ts +35 -0
  96. package/esri-compat/basemap-layer-list.d.ts.map +1 -0
  97. package/esri-compat/basemap-layer-list.js +139 -0
  98. package/esri-compat/basemap.d.ts +32 -0
  99. package/esri-compat/basemap.d.ts.map +1 -0
  100. package/esri-compat/basemap.js +84 -0
  101. package/esri-compat/bookmarks.d.ts +36 -0
  102. package/esri-compat/bookmarks.d.ts.map +1 -0
  103. package/esri-compat/bookmarks.js +108 -0
  104. package/esri-compat/class-breaks-renderer.d.ts +50 -0
  105. package/esri-compat/class-breaks-renderer.d.ts.map +1 -0
  106. package/esri-compat/class-breaks-renderer.js +164 -0
  107. package/esri-compat/color.d.ts +22 -0
  108. package/esri-compat/color.d.ts.map +1 -0
  109. package/esri-compat/color.js +106 -0
  110. package/esri-compat/controls.d.ts +174 -0
  111. package/esri-compat/controls.d.ts.map +1 -0
  112. package/esri-compat/controls.js +479 -0
  113. package/esri-compat/coordinate-conversion.d.ts +41 -0
  114. package/esri-compat/coordinate-conversion.d.ts.map +1 -0
  115. package/esri-compat/coordinate-conversion.js +125 -0
  116. package/esri-compat/directions.d.ts +45 -0
  117. package/esri-compat/directions.d.ts.map +1 -0
  118. package/esri-compat/directions.js +123 -0
  119. package/esri-compat/editor.d.ts +47 -0
  120. package/esri-compat/editor.d.ts.map +1 -0
  121. package/esri-compat/editor.js +170 -0
  122. package/esri-compat/esri-config.d.ts +16 -0
  123. package/esri-compat/esri-config.d.ts.map +1 -0
  124. package/esri-compat/esri-config.js +23 -0
  125. package/esri-compat/esri-request.d.ts +17 -0
  126. package/esri-compat/esri-request.d.ts.map +1 -0
  127. package/esri-compat/esri-request.js +66 -0
  128. package/esri-compat/event-bus.d.ts +106 -0
  129. package/esri-compat/event-bus.d.ts.map +1 -0
  130. package/esri-compat/event-bus.js +90 -0
  131. package/esri-compat/expand.d.ts +36 -0
  132. package/esri-compat/expand.d.ts.map +1 -0
  133. package/esri-compat/expand.js +97 -0
  134. package/esri-compat/extent.d.ts +43 -0
  135. package/esri-compat/extent.d.ts.map +1 -0
  136. package/esri-compat/extent.js +140 -0
  137. package/esri-compat/feature-form.d.ts +64 -0
  138. package/esri-compat/feature-form.d.ts.map +1 -0
  139. package/esri-compat/feature-form.js +137 -0
  140. package/esri-compat/feature-layer.d.ts +173 -0
  141. package/esri-compat/feature-layer.d.ts.map +1 -0
  142. package/esri-compat/feature-layer.js +655 -0
  143. package/esri-compat/feature-set.d.ts +32 -0
  144. package/esri-compat/feature-set.d.ts.map +1 -0
  145. package/esri-compat/feature-set.js +80 -0
  146. package/esri-compat/feature-table.d.ts +141 -0
  147. package/esri-compat/feature-table.d.ts.map +1 -0
  148. package/esri-compat/feature-table.js +500 -0
  149. package/esri-compat/feature-templates.d.ts +41 -0
  150. package/esri-compat/feature-templates.d.ts.map +1 -0
  151. package/esri-compat/feature-templates.js +97 -0
  152. package/esri-compat/feature.d.ts +33 -0
  153. package/esri-compat/feature.d.ts.map +1 -0
  154. package/esri-compat/feature.js +83 -0
  155. package/esri-compat/graphic.d.ts +46 -0
  156. package/esri-compat/graphic.d.ts.map +1 -0
  157. package/esri-compat/graphic.js +103 -0
  158. package/esri-compat/graphics-layer.d.ts +49 -0
  159. package/esri-compat/graphics-layer.d.ts.map +1 -0
  160. package/esri-compat/graphics-layer.js +185 -0
  161. package/esri-compat/group-layer.d.ts +48 -0
  162. package/esri-compat/group-layer.d.ts.map +1 -0
  163. package/esri-compat/group-layer.js +212 -0
  164. package/esri-compat/identify.d.ts +71 -0
  165. package/esri-compat/identify.d.ts.map +1 -0
  166. package/esri-compat/identify.js +299 -0
  167. package/esri-compat/identity-manager.d.ts +31 -0
  168. package/esri-compat/identity-manager.d.ts.map +1 -0
  169. package/esri-compat/identity-manager.js +115 -0
  170. package/esri-compat/label-class.d.ts +31 -0
  171. package/esri-compat/label-class.d.ts.map +1 -0
  172. package/esri-compat/label-class.js +102 -0
  173. package/esri-compat/layer-list.d.ts +77 -0
  174. package/esri-compat/layer-list.d.ts.map +1 -0
  175. package/esri-compat/layer-list.js +342 -0
  176. package/esri-compat/legend.d.ts +53 -0
  177. package/esri-compat/legend.d.ts.map +1 -0
  178. package/esri-compat/legend.js +254 -0
  179. package/esri-compat/map-image-layer.d.ts +162 -0
  180. package/esri-compat/map-image-layer.d.ts.map +1 -0
  181. package/esri-compat/map-image-layer.js +704 -0
  182. package/esri-compat/map-view.d.ts +315 -0
  183. package/esri-compat/map-view.d.ts.map +1 -0
  184. package/esri-compat/map-view.js +1110 -0
  185. package/esri-compat/map.d.ts +47 -0
  186. package/esri-compat/map.d.ts.map +1 -0
  187. package/esri-compat/map.js +209 -0
  188. package/esri-compat/measurement-2d.d.ts +61 -0
  189. package/esri-compat/measurement-2d.d.ts.map +1 -0
  190. package/esri-compat/measurement-2d.js +184 -0
  191. package/esri-compat/measurement.d.ts +45 -0
  192. package/esri-compat/measurement.d.ts.map +1 -0
  193. package/esri-compat/measurement.js +193 -0
  194. package/esri-compat/oauth-info.d.ts +35 -0
  195. package/esri-compat/oauth-info.d.ts.map +1 -0
  196. package/esri-compat/oauth-info.js +115 -0
  197. package/esri-compat/picture-marker-symbol.d.ts +35 -0
  198. package/esri-compat/picture-marker-symbol.d.ts.map +1 -0
  199. package/esri-compat/picture-marker-symbol.js +126 -0
  200. package/esri-compat/point.d.ts +31 -0
  201. package/esri-compat/point.d.ts.map +1 -0
  202. package/esri-compat/point.js +102 -0
  203. package/esri-compat/polygon.d.ts +31 -0
  204. package/esri-compat/polygon.d.ts.map +1 -0
  205. package/esri-compat/polygon.js +107 -0
  206. package/esri-compat/polyline.d.ts +31 -0
  207. package/esri-compat/polyline.d.ts.map +1 -0
  208. package/esri-compat/polyline.js +107 -0
  209. package/esri-compat/popup-template.d.ts +55 -0
  210. package/esri-compat/popup-template.d.ts.map +1 -0
  211. package/esri-compat/popup-template.js +128 -0
  212. package/esri-compat/popup.d.ts +54 -0
  213. package/esri-compat/popup.d.ts.map +1 -0
  214. package/esri-compat/popup.js +312 -0
  215. package/esri-compat/print.d.ts +47 -0
  216. package/esri-compat/print.d.ts.map +1 -0
  217. package/esri-compat/print.js +105 -0
  218. package/esri-compat/query.d.ts +46 -0
  219. package/esri-compat/query.d.ts.map +1 -0
  220. package/esri-compat/query.js +119 -0
  221. package/esri-compat/reactive-utils.d.ts +23 -0
  222. package/esri-compat/reactive-utils.d.ts.map +1 -0
  223. package/esri-compat/reactive-utils.js +178 -0
  224. package/esri-compat/request.d.ts +41 -0
  225. package/esri-compat/request.d.ts.map +1 -0
  226. package/esri-compat/request.js +253 -0
  227. package/esri-compat/route-layer.d.ts +59 -0
  228. package/esri-compat/route-layer.d.ts.map +1 -0
  229. package/esri-compat/route-layer.js +223 -0
  230. package/esri-compat/route-task.d.ts +88 -0
  231. package/esri-compat/route-task.d.ts.map +1 -0
  232. package/esri-compat/route-task.js +225 -0
  233. package/esri-compat/scene-view.d.ts +41 -0
  234. package/esri-compat/scene-view.d.ts.map +1 -0
  235. package/esri-compat/scene-view.js +68 -0
  236. package/esri-compat/search.d.ts +112 -0
  237. package/esri-compat/search.d.ts.map +1 -0
  238. package/esri-compat/search.js +820 -0
  239. package/esri-compat/simple-fill-symbol.d.ts +27 -0
  240. package/esri-compat/simple-fill-symbol.d.ts.map +1 -0
  241. package/esri-compat/simple-fill-symbol.js +85 -0
  242. package/esri-compat/simple-line-symbol.d.ts +27 -0
  243. package/esri-compat/simple-line-symbol.d.ts.map +1 -0
  244. package/esri-compat/simple-line-symbol.js +85 -0
  245. package/esri-compat/simple-marker-symbol.d.ts +29 -0
  246. package/esri-compat/simple-marker-symbol.d.ts.map +1 -0
  247. package/esri-compat/simple-marker-symbol.js +92 -0
  248. package/esri-compat/simple-renderer.d.ts +29 -0
  249. package/esri-compat/simple-renderer.d.ts.map +1 -0
  250. package/esri-compat/simple-renderer.js +92 -0
  251. package/esri-compat/sketch.d.ts +64 -0
  252. package/esri-compat/sketch.d.ts.map +1 -0
  253. package/esri-compat/sketch.js +227 -0
  254. package/esri-compat/spatial-reference.d.ts +31 -0
  255. package/esri-compat/spatial-reference.d.ts.map +1 -0
  256. package/esri-compat/spatial-reference.js +102 -0
  257. package/esri-compat/swipe.d.ts +34 -0
  258. package/esri-compat/swipe.d.ts.map +1 -0
  259. package/esri-compat/swipe.js +93 -0
  260. package/esri-compat/table-list.d.ts +36 -0
  261. package/esri-compat/table-list.d.ts.map +1 -0
  262. package/esri-compat/table-list.js +126 -0
  263. package/esri-compat/text-symbol.d.ts +37 -0
  264. package/esri-compat/text-symbol.d.ts.map +1 -0
  265. package/esri-compat/text-symbol.js +123 -0
  266. package/esri-compat/tile-layer.d.ts +52 -0
  267. package/esri-compat/tile-layer.d.ts.map +1 -0
  268. package/esri-compat/tile-layer.js +167 -0
  269. package/esri-compat/time-slider.d.ts +70 -0
  270. package/esri-compat/time-slider.d.ts.map +1 -0
  271. package/esri-compat/time-slider.js +208 -0
  272. package/esri-compat/track.d.ts +51 -0
  273. package/esri-compat/track.d.ts.map +1 -0
  274. package/esri-compat/track.js +174 -0
  275. package/esri-compat/unique-value-renderer.d.ts +41 -0
  276. package/esri-compat/unique-value-renderer.d.ts.map +1 -0
  277. package/esri-compat/unique-value-renderer.js +127 -0
  278. package/esri-compat/url.d.ts +12 -0
  279. package/esri-compat/url.d.ts.map +1 -0
  280. package/esri-compat/url.js +54 -0
  281. package/esri-compat/web-map.d.ts +14 -0
  282. package/esri-compat/web-map.d.ts.map +1 -0
  283. package/esri-compat/web-map.js +24 -0
  284. package/gen/honua/v1/feature_service_pb.d.ts +918 -0
  285. package/gen/honua/v1/feature_service_pb.d.ts.map +1 -0
  286. package/gen/honua/v1/feature_service_pb.js +375 -0
  287. package/index.d.ts +130 -0
  288. package/index.js +65 -0
  289. package/package.json +22 -0
@@ -0,0 +1,704 @@
1
+ import { HonuaClient } from "../core/client.js";
2
+ import { CompatEventBus, resolveCompatEventBus, safeInvokeCompatListener } from "./event-bus.js";
3
+ import { parseMapServiceUrl } from "./url.js";
4
+ export class MapImageLayerCompat {
5
+ url;
6
+ id;
7
+ title;
8
+ serviceId;
9
+ opacity;
10
+ visible;
11
+ minScale;
12
+ maxScale;
13
+ listMode;
14
+ legendEnabled;
15
+ loaded;
16
+ loadStatus;
17
+ metadata;
18
+ eventBus;
19
+ client;
20
+ watchListeners;
21
+ eventListeners;
22
+ sublayerWrappersById;
23
+ sublayerSources;
24
+ constructor(options) {
25
+ const parsed = parseMapServiceUrl(options.url);
26
+ this.url = options.url;
27
+ this.serviceId = parsed.serviceId;
28
+ this.id = options.id ?? this.serviceId;
29
+ this.title = options.title;
30
+ this.sublayerSources = Array.isArray(options.sublayers)
31
+ ? [...options.sublayers]
32
+ : [];
33
+ this.opacity = options.opacity ?? 1;
34
+ this.visible = options.visible ?? true;
35
+ this.minScale = normalizeScale(options.minScale);
36
+ this.maxScale = normalizeScale(options.maxScale);
37
+ this.listMode = options.listMode ?? "show";
38
+ this.legendEnabled = options.legendEnabled ?? true;
39
+ this.loaded = false;
40
+ this.loadStatus = "not-loaded";
41
+ this.metadata = undefined;
42
+ this.eventBus =
43
+ options.eventBus ?? resolveCompatEventBus(options.client, options.sublayers) ?? new CompatEventBus();
44
+ this.client = options.client ?? new HonuaClient({ baseUrl: parsed.baseUrl });
45
+ this.watchListeners = new Map();
46
+ this.eventListeners = new Map();
47
+ this.sublayerWrappersById = new Map();
48
+ }
49
+ async load() {
50
+ if (!this.loaded) {
51
+ this.loadStatus = "loading";
52
+ this.notifyWatchers("loadStatus", this.loadStatus);
53
+ this.eventBus.emit("map-image-layer.loading", { serviceId: this.serviceId, id: this.id }, this);
54
+ try {
55
+ this.metadata = (await this.client.getMapServiceMetadata(this.serviceId));
56
+ this.notifyWatchers("metadata", this.metadata);
57
+ this.hydrateSublayersFromMetadataIfNeeded();
58
+ this.loaded = true;
59
+ this.notifyWatchers("loaded", this.loaded);
60
+ this.loadStatus = "loaded";
61
+ this.notifyWatchers("loadStatus", this.loadStatus);
62
+ this.eventBus.emit("map-image-layer.loaded", { serviceId: this.serviceId, id: this.id }, this);
63
+ }
64
+ catch (error) {
65
+ this.metadata = undefined;
66
+ this.notifyWatchers("metadata", this.metadata);
67
+ this.loaded = false;
68
+ this.notifyWatchers("loaded", this.loaded);
69
+ this.loadStatus = "failed";
70
+ this.notifyWatchers("loadStatus", this.loadStatus);
71
+ this.eventBus.emit("map-image-layer.failed", { serviceId: this.serviceId, id: this.id, error }, this);
72
+ throw error;
73
+ }
74
+ }
75
+ return this;
76
+ }
77
+ async when(callback) {
78
+ const layer = await this.load();
79
+ if (callback) {
80
+ callback(layer);
81
+ }
82
+ return layer;
83
+ }
84
+ refresh() {
85
+ this.loaded = false;
86
+ this.notifyWatchers("loaded", this.loaded);
87
+ this.loadStatus = "not-loaded";
88
+ this.notifyWatchers("loadStatus", this.loadStatus);
89
+ this.metadata = undefined;
90
+ this.notifyWatchers("metadata", this.metadata);
91
+ this.eventBus.emit("map-image-layer.refreshed", { serviceId: this.serviceId, id: this.id }, this);
92
+ }
93
+ watch(propertyName, listener) {
94
+ let listeners = this.watchListeners.get(propertyName);
95
+ if (!listeners) {
96
+ listeners = new Set();
97
+ this.watchListeners.set(propertyName, listeners);
98
+ }
99
+ listeners.add(listener);
100
+ return {
101
+ remove: () => {
102
+ listeners?.delete(listener);
103
+ },
104
+ };
105
+ }
106
+ get sublayers() {
107
+ void this.synchronizeSublayerWrapperCache();
108
+ const wrappers = [];
109
+ const seenIds = new Set();
110
+ for (const source of this.sublayerSources) {
111
+ const sourceId = extractSublayerId(source);
112
+ if (sourceId === undefined || seenIds.has(sourceId)) {
113
+ continue;
114
+ }
115
+ seenIds.add(sourceId);
116
+ wrappers.push(this.getOrCreateSublayerWrapper(sourceId, source));
117
+ }
118
+ return wrappers;
119
+ }
120
+ set sublayers(sublayers) {
121
+ this.setSublayers(sublayers);
122
+ }
123
+ get allSublayers() {
124
+ return this.synchronizeSublayerWrapperCache();
125
+ }
126
+ exportImage(options) {
127
+ return this.client.exportMap({
128
+ ...options,
129
+ serviceId: this.serviceId,
130
+ });
131
+ }
132
+ getLegend(options = {}) {
133
+ return this.client.getMapLegend({
134
+ ...options,
135
+ serviceId: this.serviceId,
136
+ });
137
+ }
138
+ legend(options = {}) {
139
+ return this.getLegend(options);
140
+ }
141
+ identify(options) {
142
+ return this.client.identifyMap({
143
+ ...options,
144
+ serviceId: this.serviceId,
145
+ });
146
+ }
147
+ find(options) {
148
+ return this.client.findMap({
149
+ ...options,
150
+ serviceId: this.serviceId,
151
+ });
152
+ }
153
+ createQuery(layerId) {
154
+ return {
155
+ layerId,
156
+ where: "1=1",
157
+ outFields: ["*"],
158
+ returnGeometry: true,
159
+ };
160
+ }
161
+ queryFeatures(options) {
162
+ return this.client.queryMapLayer({
163
+ ...options,
164
+ serviceId: this.serviceId,
165
+ });
166
+ }
167
+ async queryFeaturesAll(options) {
168
+ const pageSize = typeof options.pageSize === "number" && Number.isFinite(options.pageSize)
169
+ ? Math.max(1, Math.trunc(options.pageSize))
170
+ : 2000;
171
+ const maxPages = typeof options.maxPages === "number" && Number.isFinite(options.maxPages)
172
+ ? Math.max(1, Math.trunc(options.maxPages))
173
+ : 100;
174
+ const features = [];
175
+ for (let page = 0; page < maxPages; page += 1) {
176
+ const response = await this.queryFeatures({
177
+ ...options,
178
+ extraParams: {
179
+ ...(options.extraParams ?? {}),
180
+ resultOffset: page * pageSize,
181
+ resultRecordCount: pageSize,
182
+ },
183
+ });
184
+ const pageFeatures = extractFeatures(response);
185
+ if (pageFeatures.length === 0) {
186
+ break;
187
+ }
188
+ features.push(...pageFeatures);
189
+ if (pageFeatures.length < pageSize) {
190
+ break;
191
+ }
192
+ }
193
+ return features;
194
+ }
195
+ async *queryFeaturesStream(options) {
196
+ const pageSize = typeof options.pageSize === "number" && Number.isFinite(options.pageSize)
197
+ ? Math.max(1, Math.trunc(options.pageSize))
198
+ : 2000;
199
+ const maxPages = typeof options.maxPages === "number" && Number.isFinite(options.maxPages)
200
+ ? Math.max(1, Math.trunc(options.maxPages))
201
+ : 100;
202
+ for (let page = 0; page < maxPages; page += 1) {
203
+ const response = await this.queryFeatures({
204
+ ...options,
205
+ extraParams: {
206
+ ...(options.extraParams ?? {}),
207
+ resultOffset: page * pageSize,
208
+ resultRecordCount: pageSize,
209
+ },
210
+ });
211
+ const pageFeatures = extractFeatures(response);
212
+ if (pageFeatures.length === 0) {
213
+ break;
214
+ }
215
+ yield pageFeatures;
216
+ if (pageFeatures.length < pageSize) {
217
+ break;
218
+ }
219
+ }
220
+ }
221
+ async queryFeatureCount(options) {
222
+ const response = (await this.queryFeatures({
223
+ layerId: options.layerId,
224
+ where: options.where ?? "1=1",
225
+ returnGeometry: false,
226
+ outFields: "OBJECTID",
227
+ method: options.method,
228
+ extraParams: {
229
+ returnCountOnly: true,
230
+ ...options.extraParams,
231
+ },
232
+ }));
233
+ return extractFeatureCount(response);
234
+ }
235
+ async queryObjectIds(options) {
236
+ const response = (await this.queryFeatures({
237
+ layerId: options.layerId,
238
+ where: options.where ?? "1=1",
239
+ returnGeometry: false,
240
+ outFields: "OBJECTID",
241
+ method: options.method,
242
+ extraParams: {
243
+ returnIdsOnly: true,
244
+ ...options.extraParams,
245
+ },
246
+ }));
247
+ return extractObjectIds(response);
248
+ }
249
+ async queryExtent(options) {
250
+ const response = (await this.queryFeatures({
251
+ layerId: options.layerId,
252
+ where: options.where ?? "1=1",
253
+ returnGeometry: false,
254
+ method: options.method,
255
+ extraParams: {
256
+ returnExtentOnly: true,
257
+ ...options.extraParams,
258
+ },
259
+ }));
260
+ return extractExtent(response);
261
+ }
262
+ queryRelatedRecords(options) {
263
+ return this.client.queryMapRelatedRecords({
264
+ ...options,
265
+ serviceId: this.serviceId,
266
+ });
267
+ }
268
+ queryRelatedFeatures(options) {
269
+ return this.queryRelatedRecords(options);
270
+ }
271
+ async applyEdits(options) {
272
+ const result = await this.client.applyEdits({
273
+ serviceId: this.serviceId,
274
+ layerId: options.layerId,
275
+ adds: options.adds,
276
+ updates: options.updates,
277
+ deletes: options.deletes,
278
+ rollbackOnFailure: options.rollbackOnFailure,
279
+ });
280
+ this.eventBus.emit("map-image-layer.edits", { result, layerId: this.id, sublayerId: options.layerId }, this);
281
+ return result;
282
+ }
283
+ setVisibility(visible) {
284
+ this.visible = visible;
285
+ this.notifyWatchers("visible", this.visible);
286
+ this.eventBus.emit("layer.visibility-changed", { layerId: this.id, visible }, this);
287
+ }
288
+ setOpacity(opacity) {
289
+ this.opacity = normalizeOpacity(opacity);
290
+ this.notifyWatchers("opacity", this.opacity);
291
+ this.eventBus.emit("layer.opacity-changed", { layerId: this.id, opacity: this.opacity }, this);
292
+ }
293
+ setSublayers(sublayers) {
294
+ this.sublayerSources = sublayers.map((candidate) => candidate instanceof MapImageSublayerCompat ? candidate.source : candidate);
295
+ const wrappers = this.sublayers;
296
+ this.notifyWatchers("sublayers", wrappers);
297
+ this.eventBus.emit("map-image-layer.sublayers-changed", { layerId: this.id }, this);
298
+ }
299
+ findSublayerById(id) {
300
+ const expectedId = normalizeSublayerId(id);
301
+ if (expectedId === undefined) {
302
+ return undefined;
303
+ }
304
+ const source = findSublayerSourceById(this.sublayerSources, expectedId);
305
+ if (source === undefined) {
306
+ return undefined;
307
+ }
308
+ return this.getOrCreateSublayerWrapper(expectedId, source);
309
+ }
310
+ sublayer(id) {
311
+ return this.findSublayerById(id);
312
+ }
313
+ setScaleRange(minScale, maxScale) {
314
+ this.minScale = normalizeScale(minScale);
315
+ this.maxScale = normalizeScale(maxScale);
316
+ this.notifyWatchers("minScale", this.minScale);
317
+ this.notifyWatchers("maxScale", this.maxScale);
318
+ this.eventBus.emit("map-image-layer.scale-range-changed", { layerId: this.id, minScale: this.minScale, maxScale: this.maxScale }, this);
319
+ }
320
+ setListMode(listMode) {
321
+ this.listMode = listMode;
322
+ this.notifyWatchers("listMode", this.listMode);
323
+ this.eventBus.emit("map-image-layer.list-mode-changed", { layerId: this.id, listMode }, this);
324
+ }
325
+ on(eventName, listener) {
326
+ const namespacedEvent = `map-image-layer.${eventName}`;
327
+ let listeners = this.eventListeners.get(eventName);
328
+ if (!listeners) {
329
+ listeners = new Set();
330
+ this.eventListeners.set(eventName, listeners);
331
+ }
332
+ listeners.add(listener);
333
+ const subscription = this.eventBus.on(namespacedEvent, (event) => {
334
+ safeInvokeCompatListener(listener, event.payload);
335
+ });
336
+ return {
337
+ remove: () => {
338
+ listeners?.delete(listener);
339
+ subscription.remove();
340
+ },
341
+ };
342
+ }
343
+ destroy() {
344
+ this.watchListeners.clear();
345
+ this.eventListeners.clear();
346
+ this.eventBus.emit("map-image-layer.destroyed", { id: this.id }, this);
347
+ }
348
+ setLegendEnabled(legendEnabled) {
349
+ this.legendEnabled = legendEnabled;
350
+ this.notifyWatchers("legendEnabled", this.legendEnabled);
351
+ this.eventBus.emit("map-image-layer.legend-enabled-changed", { layerId: this.id, legendEnabled }, this);
352
+ }
353
+ listFields() {
354
+ return extractFieldDefinitions(this.metadata);
355
+ }
356
+ getField(fieldName) {
357
+ const normalizedFieldName = fieldName.trim();
358
+ if (normalizedFieldName.length === 0) {
359
+ return undefined;
360
+ }
361
+ return this.listFields().find((field) => {
362
+ return field.name.trim() === normalizedFieldName;
363
+ });
364
+ }
365
+ hydrateSublayersFromMetadataIfNeeded() {
366
+ if (this.sublayerSources.length > 0) {
367
+ return;
368
+ }
369
+ const metadataSublayers = extractSublayersFromMetadata(this.metadata);
370
+ if (metadataSublayers.length === 0) {
371
+ return;
372
+ }
373
+ this.sublayerSources = metadataSublayers;
374
+ const wrappers = this.sublayers;
375
+ this.notifyWatchers("sublayers", wrappers);
376
+ this.eventBus.emit("map-image-layer.sublayers-changed", { layerId: this.id, source: "metadata" }, this);
377
+ }
378
+ getOrCreateSublayerWrapper(layerId, source) {
379
+ const existing = this.sublayerWrappersById.get(layerId);
380
+ if (existing) {
381
+ existing.setSource(source);
382
+ return existing;
383
+ }
384
+ const created = new MapImageSublayerCompat({
385
+ layer: this,
386
+ layerId,
387
+ source,
388
+ });
389
+ this.sublayerWrappersById.set(layerId, created);
390
+ return created;
391
+ }
392
+ synchronizeSublayerWrapperCache() {
393
+ const currentSublayerIds = new Set();
394
+ const wrappers = [];
395
+ collectSublayerWrappers(this.sublayerSources, this, wrappers, currentSublayerIds);
396
+ for (const cachedLayerId of this.sublayerWrappersById.keys()) {
397
+ if (!currentSublayerIds.has(cachedLayerId)) {
398
+ this.sublayerWrappersById.delete(cachedLayerId);
399
+ }
400
+ }
401
+ return wrappers;
402
+ }
403
+ notifyWatchers(propertyName, value) {
404
+ const listeners = this.watchListeners.get(propertyName);
405
+ if (!listeners) {
406
+ return;
407
+ }
408
+ for (const listener of listeners) {
409
+ safeInvokeCompatListener(listener, value);
410
+ }
411
+ }
412
+ }
413
+ export class MapImageSublayerCompat {
414
+ layer;
415
+ layerId;
416
+ source;
417
+ constructor(options) {
418
+ this.layer = options.layer;
419
+ this.layerId = options.layerId;
420
+ this.source = options.source ?? { id: options.layerId };
421
+ }
422
+ setSource(source) {
423
+ this.source = source;
424
+ }
425
+ get id() {
426
+ return this.layerId;
427
+ }
428
+ get visible() {
429
+ if (typeof this.source.visible !== "boolean") {
430
+ return true;
431
+ }
432
+ return this.source.visible;
433
+ }
434
+ set visible(visible) {
435
+ this.source.visible = visible;
436
+ }
437
+ get title() {
438
+ if (typeof this.source.title !== "string") {
439
+ return undefined;
440
+ }
441
+ return this.source.title;
442
+ }
443
+ get definitionExpression() {
444
+ if (typeof this.source.definitionExpression !== "string") {
445
+ return undefined;
446
+ }
447
+ return this.source.definitionExpression;
448
+ }
449
+ set definitionExpression(definitionExpression) {
450
+ if (definitionExpression === undefined ||
451
+ (typeof definitionExpression === "string" && definitionExpression.trim().length === 0)) {
452
+ delete this.source.definitionExpression;
453
+ return;
454
+ }
455
+ this.source.definitionExpression = definitionExpression;
456
+ }
457
+ setVisibility(visible) {
458
+ this.visible = visible;
459
+ this.layer.eventBus.emit("layer.visibility-changed", { layerId: this.layerId, visible: this.visible }, this);
460
+ }
461
+ createQuery() {
462
+ const query = this.layer.createQuery(this.layerId);
463
+ return {
464
+ where: query.where,
465
+ outFields: query.outFields,
466
+ returnGeometry: query.returnGeometry,
467
+ method: query.method,
468
+ extraParams: query.extraParams,
469
+ };
470
+ }
471
+ queryFeatures(options = {}) {
472
+ return this.layer.queryFeatures({
473
+ layerId: this.layerId,
474
+ where: options.where ?? this.definitionExpression ?? "1=1",
475
+ ...options,
476
+ });
477
+ }
478
+ queryFeaturesAll(options = {}) {
479
+ return this.layer.queryFeaturesAll({
480
+ layerId: this.layerId,
481
+ where: options.where ?? this.definitionExpression ?? "1=1",
482
+ ...options,
483
+ });
484
+ }
485
+ queryFeatureCount(options = {}) {
486
+ return this.layer.queryFeatureCount({
487
+ layerId: this.layerId,
488
+ where: options.where ?? this.definitionExpression,
489
+ ...options,
490
+ });
491
+ }
492
+ queryObjectIds(options = {}) {
493
+ return this.layer.queryObjectIds({
494
+ layerId: this.layerId,
495
+ where: options.where ?? this.definitionExpression,
496
+ ...options,
497
+ });
498
+ }
499
+ queryExtent(options = {}) {
500
+ return this.layer.queryExtent({
501
+ layerId: this.layerId,
502
+ where: options.where ?? this.definitionExpression,
503
+ ...options,
504
+ });
505
+ }
506
+ queryRelatedRecords(options) {
507
+ return this.layer.queryRelatedRecords({
508
+ layerId: this.layerId,
509
+ where: options.where ?? this.definitionExpression,
510
+ ...options,
511
+ });
512
+ }
513
+ queryRelatedFeatures(options) {
514
+ return this.queryRelatedRecords(options);
515
+ }
516
+ applyEdits(options = {}) {
517
+ return this.layer.applyEdits({
518
+ layerId: this.layerId,
519
+ ...options,
520
+ });
521
+ }
522
+ get sublayers() {
523
+ const childSources = getChildSublayers(this.source);
524
+ const wrappers = [];
525
+ for (const childSource of childSources) {
526
+ const childId = extractSublayerId(childSource);
527
+ if (childId === undefined) {
528
+ continue;
529
+ }
530
+ wrappers.push(this.layer.getOrCreateSublayerWrapper(childId, childSource));
531
+ }
532
+ return wrappers;
533
+ }
534
+ get allSublayers() {
535
+ const wrappers = [];
536
+ const trackedIds = new Set();
537
+ collectSublayerWrappers(getChildSublayers(this.source), this.layer, wrappers, trackedIds);
538
+ return wrappers;
539
+ }
540
+ findSublayerById(id) {
541
+ const expectedId = normalizeSublayerId(id);
542
+ if (expectedId === undefined) {
543
+ return undefined;
544
+ }
545
+ const source = findSublayerSourceById(getChildSublayers(this.source), expectedId);
546
+ if (source === undefined) {
547
+ return undefined;
548
+ }
549
+ return this.layer.getOrCreateSublayerWrapper(expectedId, source);
550
+ }
551
+ sublayer(id) {
552
+ return this.findSublayerById(id);
553
+ }
554
+ }
555
+ function normalizeScale(scale) {
556
+ if (scale === undefined || !Number.isFinite(scale)) {
557
+ return 0;
558
+ }
559
+ return Math.max(0, Math.trunc(scale));
560
+ }
561
+ function normalizeOpacity(opacity) {
562
+ if (!Number.isFinite(opacity)) {
563
+ return 1;
564
+ }
565
+ return Math.min(Math.max(opacity, 0), 1);
566
+ }
567
+ function normalizeSublayerId(id) {
568
+ const parsed = Number(id);
569
+ if (!Number.isFinite(parsed)) {
570
+ return undefined;
571
+ }
572
+ return Math.trunc(parsed);
573
+ }
574
+ function extractSublayerId(sublayer) {
575
+ const id = sublayer.id;
576
+ if (id === undefined) {
577
+ return undefined;
578
+ }
579
+ return normalizeSublayerId(id);
580
+ }
581
+ function getChildSublayers(source) {
582
+ if (Array.isArray(source.sublayers)) {
583
+ return [...source.sublayers];
584
+ }
585
+ if (Array.isArray(source.allSublayers)) {
586
+ return [...source.allSublayers];
587
+ }
588
+ return [];
589
+ }
590
+ function collectSublayerWrappers(sources, layer, wrappers, trackedIds) {
591
+ for (const source of sources) {
592
+ const sourceId = extractSublayerId(source);
593
+ if (sourceId === undefined || trackedIds.has(sourceId)) {
594
+ continue;
595
+ }
596
+ trackedIds.add(sourceId);
597
+ wrappers.push(layer.getOrCreateSublayerWrapper(sourceId, source));
598
+ collectSublayerWrappers(getChildSublayers(source), layer, wrappers, trackedIds);
599
+ }
600
+ }
601
+ function findSublayerSourceById(sources, expectedId) {
602
+ for (const source of sources) {
603
+ if (extractSublayerId(source) === expectedId) {
604
+ return source;
605
+ }
606
+ const nested = findSublayerSourceById(getChildSublayers(source), expectedId);
607
+ if (nested !== undefined) {
608
+ return nested;
609
+ }
610
+ }
611
+ return undefined;
612
+ }
613
+ function extractSublayersFromMetadata(metadata) {
614
+ if (!isRecord(metadata) || !Array.isArray(metadata.layers)) {
615
+ return [];
616
+ }
617
+ const sublayersById = new Map();
618
+ const orderedIds = [];
619
+ const seenIds = new Set();
620
+ for (const entry of metadata.layers) {
621
+ if (!isRecord(entry)) {
622
+ continue;
623
+ }
624
+ const layerId = normalizeSublayerId(entry.id);
625
+ if (layerId === undefined || seenIds.has(layerId)) {
626
+ continue;
627
+ }
628
+ const hydrated = { ...entry, id: layerId };
629
+ if (typeof hydrated.title !== "string" && typeof hydrated.name === "string") {
630
+ hydrated.title = hydrated.name;
631
+ }
632
+ hydrated.sublayers = [];
633
+ sublayersById.set(layerId, hydrated);
634
+ orderedIds.push(layerId);
635
+ seenIds.add(layerId);
636
+ }
637
+ if (sublayersById.size === 0) {
638
+ return [];
639
+ }
640
+ const roots = [];
641
+ for (const layerId of orderedIds) {
642
+ const hydrated = sublayersById.get(layerId);
643
+ if (!hydrated) {
644
+ continue;
645
+ }
646
+ const parentId = normalizeSublayerId(hydrated.parentLayerId);
647
+ const parent = parentId === undefined ? undefined : sublayersById.get(parentId);
648
+ if (parent && Array.isArray(parent.sublayers)) {
649
+ parent.sublayers.push(hydrated);
650
+ }
651
+ else {
652
+ roots.push(hydrated);
653
+ }
654
+ }
655
+ return roots;
656
+ }
657
+ function extractFeatureCount(response) {
658
+ if (typeof response.count === "number" && Number.isFinite(response.count)) {
659
+ return response.count;
660
+ }
661
+ if (Array.isArray(response.features)) {
662
+ return response.features.length;
663
+ }
664
+ return 0;
665
+ }
666
+ function extractFeatures(response) {
667
+ if (!Array.isArray(response.features)) {
668
+ return [];
669
+ }
670
+ return response.features;
671
+ }
672
+ function extractObjectIds(response) {
673
+ if (!Array.isArray(response.objectIds)) {
674
+ return [];
675
+ }
676
+ return response.objectIds.map((value) => Number(value)).filter((value) => Number.isFinite(value));
677
+ }
678
+ function extractExtent(response) {
679
+ const count = typeof response.count === "number" && Number.isFinite(response.count) ? response.count : undefined;
680
+ return {
681
+ extent: (response.extent ?? null),
682
+ count,
683
+ };
684
+ }
685
+ function extractFieldDefinitions(metadata) {
686
+ if (!isRecord(metadata)) {
687
+ return [];
688
+ }
689
+ const fields = metadata.fields;
690
+ if (!Array.isArray(fields)) {
691
+ return [];
692
+ }
693
+ const records = [];
694
+ for (const field of fields) {
695
+ if (!isRecord(field) || typeof field.name !== "string" || typeof field.type !== "string") {
696
+ continue;
697
+ }
698
+ records.push(field);
699
+ }
700
+ return records;
701
+ }
702
+ function isRecord(value) {
703
+ return typeof value === "object" && value !== null;
704
+ }