@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,655 @@
1
+ import { HonuaClient } from "../core/client.js";
2
+ import { CompatEventBus, resolveCompatEventBus, safeInvokeCompatListener } from "./event-bus.js";
3
+ import { parseFeatureLayerUrl } from "./url.js";
4
+ const DEFAULT_MAX_ATTACHMENT_BYTES = 25 * 1024 * 1024;
5
+ export class FeatureLayerCompat {
6
+ url;
7
+ id;
8
+ title;
9
+ serviceId;
10
+ layerId;
11
+ outFields;
12
+ definitionExpression;
13
+ renderer;
14
+ popupTemplate;
15
+ labelingInfo;
16
+ labelsVisible;
17
+ opacity;
18
+ visible;
19
+ minScale;
20
+ maxScale;
21
+ legendEnabled;
22
+ listMode;
23
+ loaded;
24
+ loadStatus;
25
+ metadata;
26
+ timeExtent;
27
+ eventBus;
28
+ client;
29
+ watchListeners;
30
+ eventListeners;
31
+ maxAttachmentBytes;
32
+ constructor(options) {
33
+ const parsed = parseFeatureLayerUrl(options.url);
34
+ this.url = options.url;
35
+ this.serviceId = parsed.serviceId;
36
+ this.layerId = parsed.layerId;
37
+ this.id = options.id ?? `${this.serviceId}-${this.layerId}`;
38
+ this.title = options.title;
39
+ this.outFields =
40
+ options.outFields === undefined
41
+ ? undefined
42
+ : Array.isArray(options.outFields)
43
+ ? [...options.outFields]
44
+ : [options.outFields];
45
+ this.definitionExpression = options.definitionExpression;
46
+ this.renderer = options.renderer;
47
+ this.popupTemplate = options.popupTemplate;
48
+ this.labelingInfo = Array.isArray(options.labelingInfo) ? [...options.labelingInfo] : [];
49
+ this.labelsVisible = options.labelsVisible ?? true;
50
+ this.opacity = normalizeOpacity(options.opacity ?? 1);
51
+ this.visible = options.visible ?? true;
52
+ this.minScale = normalizeScale(options.minScale);
53
+ this.maxScale = normalizeScale(options.maxScale);
54
+ this.legendEnabled = options.legendEnabled ?? true;
55
+ this.listMode = options.listMode ?? "show";
56
+ this.loaded = false;
57
+ this.loadStatus = "not-loaded";
58
+ this.metadata = undefined;
59
+ this.timeExtent = undefined;
60
+ this.eventBus = options.eventBus ?? resolveCompatEventBus(options.client) ?? new CompatEventBus();
61
+ this.client = options.client ?? new HonuaClient({ baseUrl: parsed.baseUrl });
62
+ this.watchListeners = new Map();
63
+ this.eventListeners = new Map();
64
+ this.maxAttachmentBytes = normalizeAttachmentSizeLimit(options.maxAttachmentBytes);
65
+ }
66
+ async load() {
67
+ if (!this.loaded) {
68
+ this.loadStatus = "loading";
69
+ this.notifyWatchers("loadStatus", this.loadStatus);
70
+ this.eventBus.emit("feature-layer.loading", { serviceId: this.serviceId, layerId: this.layerId, id: this.id }, this);
71
+ try {
72
+ this.metadata = await this.client.getLayerMetadata(this.serviceId, this.layerId);
73
+ this.notifyWatchers("metadata", this.metadata);
74
+ this.loaded = true;
75
+ this.notifyWatchers("loaded", this.loaded);
76
+ this.loadStatus = "loaded";
77
+ this.notifyWatchers("loadStatus", this.loadStatus);
78
+ this.eventBus.emit("feature-layer.loaded", { serviceId: this.serviceId, layerId: this.layerId, id: this.id }, this);
79
+ }
80
+ catch (error) {
81
+ this.metadata = undefined;
82
+ this.notifyWatchers("metadata", this.metadata);
83
+ this.loaded = false;
84
+ this.notifyWatchers("loaded", this.loaded);
85
+ this.loadStatus = "failed";
86
+ this.notifyWatchers("loadStatus", this.loadStatus);
87
+ this.eventBus.emit("feature-layer.failed", { serviceId: this.serviceId, layerId: this.layerId, id: this.id, error }, this);
88
+ throw error;
89
+ }
90
+ }
91
+ return this;
92
+ }
93
+ async when(callback) {
94
+ const layer = await this.load();
95
+ if (callback) {
96
+ callback(layer);
97
+ }
98
+ return layer;
99
+ }
100
+ refresh() {
101
+ this.loaded = false;
102
+ this.notifyWatchers("loaded", this.loaded);
103
+ this.loadStatus = "not-loaded";
104
+ this.notifyWatchers("loadStatus", this.loadStatus);
105
+ this.metadata = undefined;
106
+ this.notifyWatchers("metadata", this.metadata);
107
+ this.eventBus.emit("feature-layer.refreshed", { serviceId: this.serviceId, layerId: this.layerId, id: this.id }, this);
108
+ }
109
+ watch(propertyName, listener) {
110
+ let listeners = this.watchListeners.get(propertyName);
111
+ if (!listeners) {
112
+ listeners = new Set();
113
+ this.watchListeners.set(propertyName, listeners);
114
+ }
115
+ listeners.add(listener);
116
+ return {
117
+ remove: () => {
118
+ listeners?.delete(listener);
119
+ },
120
+ };
121
+ }
122
+ setVisibility(visible) {
123
+ this.visible = visible;
124
+ this.notifyWatchers("visible", this.visible);
125
+ this.eventBus.emit("layer.visibility-changed", { layerId: this.id, serviceId: this.serviceId, sublayerId: this.layerId, visible }, this);
126
+ }
127
+ setOpacity(opacity) {
128
+ this.opacity = normalizeOpacity(opacity);
129
+ this.notifyWatchers("opacity", this.opacity);
130
+ this.eventBus.emit("layer.opacity-changed", { layerId: this.id, serviceId: this.serviceId, sublayerId: this.layerId, opacity: this.opacity }, this);
131
+ }
132
+ setRenderer(renderer) {
133
+ this.renderer = renderer;
134
+ this.notifyWatchers("renderer", this.renderer);
135
+ this.eventBus.emit("feature-layer.renderer-changed", { layerId: this.id }, this);
136
+ }
137
+ setPopupTemplate(popupTemplate) {
138
+ this.popupTemplate = popupTemplate;
139
+ this.notifyWatchers("popupTemplate", this.popupTemplate);
140
+ this.eventBus.emit("feature-layer.popup-template-changed", { layerId: this.id }, this);
141
+ }
142
+ setLabelingInfo(labelingInfo) {
143
+ this.labelingInfo = [...labelingInfo];
144
+ this.notifyWatchers("labelingInfo", this.labelingInfo);
145
+ this.eventBus.emit("feature-layer.labeling-changed", { layerId: this.id }, this);
146
+ }
147
+ setDefinitionExpression(definitionExpression) {
148
+ this.definitionExpression = definitionExpression;
149
+ this.notifyWatchers("definitionExpression", this.definitionExpression);
150
+ this.eventBus.emit("feature-layer.definition-expression-changed", { layerId: this.id, definitionExpression }, this);
151
+ }
152
+ setOutFields(outFields) {
153
+ this.outFields = outFields === undefined ? undefined : Array.isArray(outFields) ? [...outFields] : [outFields];
154
+ this.notifyWatchers("outFields", this.outFields);
155
+ this.eventBus.emit("feature-layer.out-fields-changed", { layerId: this.id, outFields: this.outFields }, this);
156
+ }
157
+ setLabelsVisible(labelsVisible) {
158
+ this.labelsVisible = labelsVisible;
159
+ this.notifyWatchers("labelsVisible", this.labelsVisible);
160
+ this.eventBus.emit("feature-layer.labels-visible-changed", { layerId: this.id, labelsVisible }, this);
161
+ }
162
+ setScaleRange(minScale, maxScale) {
163
+ this.minScale = normalizeScale(minScale);
164
+ this.maxScale = normalizeScale(maxScale);
165
+ this.notifyWatchers("minScale", this.minScale);
166
+ this.notifyWatchers("maxScale", this.maxScale);
167
+ this.eventBus.emit("feature-layer.scale-range-changed", { layerId: this.id, minScale: this.minScale, maxScale: this.maxScale }, this);
168
+ }
169
+ setLegendEnabled(legendEnabled) {
170
+ this.legendEnabled = legendEnabled;
171
+ this.notifyWatchers("legendEnabled", this.legendEnabled);
172
+ this.eventBus.emit("feature-layer.legend-enabled-changed", { layerId: this.id, legendEnabled }, this);
173
+ }
174
+ setTimeExtent(extent) {
175
+ this.timeExtent = extent
176
+ ? { start: new Date(extent.start.getTime()), end: new Date(extent.end.getTime()) }
177
+ : undefined;
178
+ this.notifyWatchers("timeExtent", this.timeExtent);
179
+ this.eventBus.emit("feature-layer.time-extent-change", { layerId: this.id, timeExtent: this.timeExtent }, this);
180
+ }
181
+ destroy() {
182
+ this.watchListeners.clear();
183
+ this.eventListeners.clear();
184
+ this.eventBus.emit("feature-layer.destroyed", { id: this.id }, this);
185
+ }
186
+ on(eventName, listener) {
187
+ const namespacedEvent = `feature-layer.${eventName}`;
188
+ let listeners = this.eventListeners.get(eventName);
189
+ if (!listeners) {
190
+ listeners = new Set();
191
+ this.eventListeners.set(eventName, listeners);
192
+ }
193
+ listeners.add(listener);
194
+ const subscription = this.eventBus.on(namespacedEvent, (event) => {
195
+ safeInvokeCompatListener(listener, event.payload);
196
+ });
197
+ return {
198
+ remove: () => {
199
+ listeners?.delete(listener);
200
+ subscription.remove();
201
+ },
202
+ };
203
+ }
204
+ listFields() {
205
+ return extractFieldDefinitions(this.metadata);
206
+ }
207
+ getField(fieldName) {
208
+ const normalizedFieldName = fieldName.trim();
209
+ if (normalizedFieldName.length === 0) {
210
+ return undefined;
211
+ }
212
+ return this.listFields().find((field) => {
213
+ return field.name.trim() === normalizedFieldName;
214
+ });
215
+ }
216
+ hasField(fieldName) {
217
+ return this.getField(fieldName) !== undefined;
218
+ }
219
+ createQuery() {
220
+ return {
221
+ where: this.definitionExpression ?? "1=1",
222
+ outFields: this.outFields ? [...this.outFields] : ["*"],
223
+ returnGeometry: true,
224
+ };
225
+ }
226
+ queryFeatures(options = {}) {
227
+ const timeParam = buildTimeParam(this.timeExtent, options.extraParams);
228
+ return this.client.queryFeatures({
229
+ serviceId: this.serviceId,
230
+ layerId: this.layerId,
231
+ where: options.where ?? this.definitionExpression,
232
+ outFields: options.outFields ?? this.outFields,
233
+ returnGeometry: options.returnGeometry,
234
+ method: options.method,
235
+ extraParams: timeParam ? { ...(options.extraParams ?? {}), time: timeParam } : options.extraParams,
236
+ });
237
+ }
238
+ async queryFeaturesAll(options = {}) {
239
+ const { pageSize: requestedPageSize, maxPages: requestedMaxPages, ...queryOptions } = options;
240
+ const pageSize = typeof requestedPageSize === "number" && Number.isFinite(requestedPageSize)
241
+ ? Math.max(1, Math.trunc(requestedPageSize))
242
+ : 2000;
243
+ const maxPages = typeof requestedMaxPages === "number" && Number.isFinite(requestedMaxPages)
244
+ ? Math.max(1, Math.trunc(requestedMaxPages))
245
+ : 100;
246
+ const features = [];
247
+ for (let page = 0; page < maxPages; page += 1) {
248
+ const response = await this.queryFeatures({
249
+ ...queryOptions,
250
+ extraParams: {
251
+ ...(queryOptions.extraParams ?? {}),
252
+ resultOffset: page * pageSize,
253
+ resultRecordCount: pageSize,
254
+ },
255
+ });
256
+ const pageFeatures = response.features ?? [];
257
+ if (pageFeatures.length === 0) {
258
+ break;
259
+ }
260
+ features.push(...pageFeatures);
261
+ if (pageFeatures.length < pageSize) {
262
+ break;
263
+ }
264
+ }
265
+ return features;
266
+ }
267
+ async *queryFeaturesStream(options = {}) {
268
+ const { pageSize: requestedPageSize, maxPages: requestedMaxPages, ...queryOptions } = options;
269
+ const pageSize = typeof requestedPageSize === "number" && Number.isFinite(requestedPageSize)
270
+ ? Math.max(1, Math.trunc(requestedPageSize))
271
+ : 2000;
272
+ const maxPages = typeof requestedMaxPages === "number" && Number.isFinite(requestedMaxPages)
273
+ ? Math.max(1, Math.trunc(requestedMaxPages))
274
+ : 100;
275
+ for (let page = 0; page < maxPages; page += 1) {
276
+ const response = await this.queryFeatures({
277
+ ...queryOptions,
278
+ extraParams: {
279
+ ...(queryOptions.extraParams ?? {}),
280
+ resultOffset: page * pageSize,
281
+ resultRecordCount: pageSize,
282
+ },
283
+ });
284
+ const pageFeatures = response.features ?? [];
285
+ if (pageFeatures.length === 0) {
286
+ break;
287
+ }
288
+ yield pageFeatures;
289
+ if (pageFeatures.length < pageSize) {
290
+ break;
291
+ }
292
+ }
293
+ }
294
+ async queryObjectIds(options = {}) {
295
+ const response = (await this.client.queryFeatures({
296
+ serviceId: this.serviceId,
297
+ layerId: this.layerId,
298
+ where: options.where ?? this.definitionExpression,
299
+ returnGeometry: false,
300
+ method: options.method,
301
+ extraParams: {
302
+ ...options.extraParams,
303
+ returnIdsOnly: true,
304
+ },
305
+ }));
306
+ if (Array.isArray(response.objectIds)) {
307
+ return response.objectIds.map((value) => Number(value)).filter((value) => Number.isFinite(value));
308
+ }
309
+ const features = response.features;
310
+ if (!features) {
311
+ return [];
312
+ }
313
+ return features.map((feature) => extractObjectId(feature)).filter((value) => value !== undefined);
314
+ }
315
+ async queryFeatureCount(options = {}) {
316
+ const response = (await this.client.queryFeatures({
317
+ serviceId: this.serviceId,
318
+ layerId: this.layerId,
319
+ where: options.where ?? this.definitionExpression,
320
+ returnGeometry: false,
321
+ method: options.method,
322
+ extraParams: {
323
+ ...options.extraParams,
324
+ returnCountOnly: true,
325
+ },
326
+ }));
327
+ if (typeof response.count === "number" && Number.isFinite(response.count)) {
328
+ return response.count;
329
+ }
330
+ return response.features?.length ?? 0;
331
+ }
332
+ async queryExtent(options = {}) {
333
+ const response = (await this.client.queryFeatures({
334
+ serviceId: this.serviceId,
335
+ layerId: this.layerId,
336
+ where: options.where ?? this.definitionExpression,
337
+ returnGeometry: false,
338
+ method: options.method,
339
+ extraParams: {
340
+ ...options.extraParams,
341
+ returnExtentOnly: true,
342
+ },
343
+ }));
344
+ const count = typeof response.count === "number" && Number.isFinite(response.count) ? response.count : undefined;
345
+ return {
346
+ extent: response.extent ?? null,
347
+ count,
348
+ };
349
+ }
350
+ async applyEdits(options) {
351
+ const result = await this.client.applyEdits({
352
+ serviceId: this.serviceId,
353
+ layerId: this.layerId,
354
+ adds: options.adds,
355
+ updates: options.updates,
356
+ deletes: options.deletes,
357
+ rollbackOnFailure: options.rollbackOnFailure,
358
+ });
359
+ this.eventBus.emit("feature-layer.edits", { result, layerId: this.id }, this);
360
+ return result;
361
+ }
362
+ queryRelatedFeatures(options) {
363
+ return this.client.queryRelatedRecords({
364
+ serviceId: this.serviceId,
365
+ layerId: this.layerId,
366
+ relationshipId: options.relationshipId,
367
+ objectIds: options.objectIds,
368
+ where: options.where ?? this.definitionExpression,
369
+ outFields: options.outFields ?? this.outFields,
370
+ returnGeometry: options.returnGeometry,
371
+ method: options.method,
372
+ extraParams: options.extraParams,
373
+ });
374
+ }
375
+ queryRelatedRecords(options) {
376
+ return this.queryRelatedFeatures(options);
377
+ }
378
+ queryAttachments(options = {}) {
379
+ return this.client.request({
380
+ method: options.method ?? "GET",
381
+ path: `/rest/services/${encodeURIComponent(this.serviceId)}/FeatureServer/${this.layerId}/queryAttachments`,
382
+ responseFormat: options.responseFormat ?? "json",
383
+ query: {
384
+ ...(options.objectIds === undefined
385
+ ? {}
386
+ : {
387
+ objectIds: Array.isArray(options.objectIds) ? options.objectIds.join(",") : options.objectIds,
388
+ }),
389
+ ...(options.where === undefined ? {} : { where: options.where }),
390
+ ...(options.extraParams ?? {}),
391
+ },
392
+ });
393
+ }
394
+ listAttachments(options) {
395
+ return this.client.request({
396
+ method: "GET",
397
+ path: `/rest/services/${encodeURIComponent(this.serviceId)}` +
398
+ `/FeatureServer/${this.layerId}/${options.objectId}/attachments`,
399
+ responseFormat: options.responseFormat ?? "json",
400
+ query: options.extraParams,
401
+ });
402
+ }
403
+ deleteAttachments(options) {
404
+ const params = new URLSearchParams();
405
+ params.set("f", options.responseFormat ?? "json");
406
+ params.set("attachmentIds", Array.isArray(options.attachmentIds) ? options.attachmentIds.join(",") : String(options.attachmentIds));
407
+ if (options.extraParams) {
408
+ for (const [key, value] of Object.entries(options.extraParams)) {
409
+ params.set(key, String(value));
410
+ }
411
+ }
412
+ return this.client.request({
413
+ method: "POST",
414
+ path: `/rest/services/${encodeURIComponent(this.serviceId)}` +
415
+ `/FeatureServer/${this.layerId}/${options.objectId}/deleteAttachments`,
416
+ headers: {
417
+ "Content-Type": "application/x-www-form-urlencoded",
418
+ },
419
+ body: params.toString(),
420
+ });
421
+ }
422
+ addAttachment(options) {
423
+ const maxAttachmentBytes = options.maxAttachmentBytes ?? this.maxAttachmentBytes;
424
+ enforceAttachmentSizeLimit(options.attachment, maxAttachmentBytes);
425
+ const formOrPromise = buildAttachmentFormData({
426
+ ...options,
427
+ maxAttachmentBytes,
428
+ });
429
+ const sendForm = (form) => this.client.request({
430
+ method: "POST",
431
+ path: `/rest/services/${encodeURIComponent(this.serviceId)}` +
432
+ `/FeatureServer/${this.layerId}/${options.objectId}/addAttachment`,
433
+ responseFormat: options.responseFormat ?? "json",
434
+ query: options.extraParams,
435
+ body: form,
436
+ });
437
+ if (formOrPromise instanceof Promise) {
438
+ return formOrPromise.then(sendForm);
439
+ }
440
+ return sendForm(formOrPromise);
441
+ }
442
+ updateAttachment(options) {
443
+ const maxAttachmentBytes = options.maxAttachmentBytes ?? this.maxAttachmentBytes;
444
+ enforceAttachmentSizeLimit(options.attachment, maxAttachmentBytes);
445
+ const formOrPromise = buildAttachmentFormData({
446
+ ...options,
447
+ maxAttachmentBytes,
448
+ });
449
+ const sendForm = (form) => {
450
+ form.set("attachmentId", String(options.attachmentId));
451
+ return this.client.request({
452
+ method: "POST",
453
+ path: `/rest/services/${encodeURIComponent(this.serviceId)}` +
454
+ `/FeatureServer/${this.layerId}/${options.objectId}/updateAttachment`,
455
+ responseFormat: options.responseFormat ?? "json",
456
+ query: options.extraParams,
457
+ body: form,
458
+ });
459
+ };
460
+ if (formOrPromise instanceof Promise) {
461
+ return formOrPromise.then(sendForm);
462
+ }
463
+ return sendForm(formOrPromise);
464
+ }
465
+ notifyWatchers(propertyName, value) {
466
+ const listeners = this.watchListeners.get(propertyName);
467
+ if (!listeners) {
468
+ return;
469
+ }
470
+ for (const listener of listeners) {
471
+ safeInvokeCompatListener(listener, value);
472
+ }
473
+ }
474
+ }
475
+ function isRecord(value) {
476
+ return typeof value === "object" && value !== null;
477
+ }
478
+ function normalizeOpacity(opacity) {
479
+ if (!Number.isFinite(opacity)) {
480
+ return 1;
481
+ }
482
+ return Math.min(Math.max(opacity, 0), 1);
483
+ }
484
+ function normalizeScale(scale) {
485
+ if (scale === undefined || !Number.isFinite(scale)) {
486
+ return 0;
487
+ }
488
+ return Math.max(0, Math.trunc(scale));
489
+ }
490
+ function extractObjectId(feature) {
491
+ if (!isRecord(feature)) {
492
+ return undefined;
493
+ }
494
+ const attributes = feature.attributes;
495
+ if (!isRecord(attributes)) {
496
+ return undefined;
497
+ }
498
+ for (const key of ["objectid", "OBJECTID", "id"]) {
499
+ const raw = attributes[key];
500
+ const parsed = Number(raw);
501
+ if (Number.isFinite(parsed)) {
502
+ return parsed;
503
+ }
504
+ }
505
+ return undefined;
506
+ }
507
+ function extractFieldDefinitions(metadata) {
508
+ if (!isRecord(metadata)) {
509
+ return [];
510
+ }
511
+ const fields = metadata.fields;
512
+ if (!Array.isArray(fields)) {
513
+ return [];
514
+ }
515
+ const records = [];
516
+ for (const field of fields) {
517
+ if (!isRecord(field) || typeof field.name !== "string" || typeof field.type !== "string") {
518
+ continue;
519
+ }
520
+ records.push(field);
521
+ }
522
+ return records;
523
+ }
524
+ function buildAttachmentFormData(options) {
525
+ const attachmentName = resolveAttachmentName(options.attachment, options.name);
526
+ const blobOrPromise = normalizeAttachmentData(options.attachment, options.contentType, options.maxAttachmentBytes);
527
+ const buildForm = (blob) => {
528
+ const form = new FormData();
529
+ if (options.name) {
530
+ form.set("name", options.name);
531
+ }
532
+ form.set("attachment", blob, attachmentName);
533
+ return form;
534
+ };
535
+ if (blobOrPromise instanceof Promise) {
536
+ return blobOrPromise.then(buildForm);
537
+ }
538
+ return buildForm(blobOrPromise);
539
+ }
540
+ function normalizeAttachmentSizeLimit(maxAttachmentBytes) {
541
+ if (typeof maxAttachmentBytes !== "number" || !Number.isFinite(maxAttachmentBytes)) {
542
+ return DEFAULT_MAX_ATTACHMENT_BYTES;
543
+ }
544
+ return Math.max(1, Math.trunc(maxAttachmentBytes));
545
+ }
546
+ function enforceAttachmentSizeLimit(attachment, maxAttachmentBytes) {
547
+ const sizeBytes = estimateAttachmentSizeBytes(attachment);
548
+ if (sizeBytes === undefined || sizeBytes <= maxAttachmentBytes) {
549
+ return;
550
+ }
551
+ throw new Error(`Attachment payload exceeds maxAttachmentBytes (${sizeBytes} > ${maxAttachmentBytes}).`);
552
+ }
553
+ function estimateAttachmentSizeBytes(attachment) {
554
+ if (attachment instanceof Blob) {
555
+ return attachment.size;
556
+ }
557
+ if (typeof attachment === "string") {
558
+ return new TextEncoder().encode(attachment).byteLength;
559
+ }
560
+ if (attachment instanceof ArrayBuffer) {
561
+ return attachment.byteLength;
562
+ }
563
+ if (isReadableStream(attachment)) {
564
+ return undefined;
565
+ }
566
+ return attachment.byteLength;
567
+ }
568
+ function resolveAttachmentName(attachment, explicitName) {
569
+ if (explicitName && explicitName.trim().length > 0) {
570
+ return explicitName.trim();
571
+ }
572
+ if (isRecord(attachment)) {
573
+ const inferredName = attachment.name;
574
+ if (typeof inferredName === "string" && inferredName.trim().length > 0) {
575
+ return inferredName.trim();
576
+ }
577
+ }
578
+ return "attachment.bin";
579
+ }
580
+ function buildTimeParam(timeExtent, extraParams) {
581
+ if (!timeExtent) {
582
+ return undefined;
583
+ }
584
+ if (extraParams && "time" in extraParams) {
585
+ return undefined;
586
+ }
587
+ return `${timeExtent.start.getTime()},${timeExtent.end.getTime()}`;
588
+ }
589
+ function normalizeAttachmentData(attachment, contentType, maxAttachmentBytes) {
590
+ if (attachment instanceof Blob) {
591
+ return attachment;
592
+ }
593
+ if (typeof attachment === "string") {
594
+ return new Blob([attachment], {
595
+ type: contentType ?? "text/plain",
596
+ });
597
+ }
598
+ if (attachment instanceof ArrayBuffer) {
599
+ return new Blob([attachment], {
600
+ type: contentType ?? "application/octet-stream",
601
+ });
602
+ }
603
+ if (isReadableStream(attachment)) {
604
+ return collectStreamToBlob(attachment, contentType ?? "application/octet-stream", maxAttachmentBytes);
605
+ }
606
+ if (ArrayBuffer.isView(attachment)) {
607
+ const source = new Uint8Array(attachment.buffer, attachment.byteOffset, attachment.byteLength);
608
+ const copy = Uint8Array.from(source);
609
+ return new Blob([copy], {
610
+ type: contentType ?? "application/octet-stream",
611
+ });
612
+ }
613
+ throw new Error("Unsupported attachment payload type.");
614
+ }
615
+ function isReadableStream(value) {
616
+ return (typeof value === "object" &&
617
+ value !== null &&
618
+ "getReader" in value &&
619
+ typeof value.getReader === "function");
620
+ }
621
+ async function collectStreamToBlob(stream, contentType, maxAttachmentBytes) {
622
+ const reader = stream.getReader();
623
+ const chunks = [];
624
+ let totalBytes = 0;
625
+ try {
626
+ for (;;) {
627
+ const { done, value } = await reader.read();
628
+ if (done) {
629
+ break;
630
+ }
631
+ if (value) {
632
+ totalBytes += value.byteLength;
633
+ if (totalBytes > maxAttachmentBytes) {
634
+ try {
635
+ await reader.cancel();
636
+ }
637
+ catch {
638
+ // Ignore cancel errors; size-limit failure is the primary error.
639
+ }
640
+ throw new Error(`Attachment payload exceeds maxAttachmentBytes (${totalBytes} > ${maxAttachmentBytes}).`);
641
+ }
642
+ chunks.push(copyToArrayBuffer(value));
643
+ }
644
+ }
645
+ }
646
+ finally {
647
+ reader.releaseLock();
648
+ }
649
+ return new Blob(chunks, { type: contentType });
650
+ }
651
+ function copyToArrayBuffer(chunk) {
652
+ const copy = new Uint8Array(chunk.byteLength);
653
+ copy.set(chunk);
654
+ return copy.buffer;
655
+ }
@@ -0,0 +1,32 @@
1
+ export interface FeatureSetCompatOptions {
2
+ features?: unknown[];
3
+ fields?: unknown[];
4
+ geometryType?: string;
5
+ spatialReference?: unknown;
6
+ objectIdFieldName?: string;
7
+ displayFieldName?: string;
8
+ }
9
+ export type FeatureSetLoadStatusCompat = "not-loaded" | "loading" | "loaded";
10
+ export interface FeatureSetHandleCompat {
11
+ remove(): void;
12
+ }
13
+ export declare class FeatureSetCompat {
14
+ loaded: boolean;
15
+ loadStatus: FeatureSetLoadStatusCompat;
16
+ features: unknown[];
17
+ fields: unknown[];
18
+ geometryType: string | undefined;
19
+ spatialReference: unknown;
20
+ objectIdFieldName: string | undefined;
21
+ displayFieldName: string | undefined;
22
+ private readonly watchListeners;
23
+ constructor(options?: FeatureSetCompatOptions);
24
+ load(): Promise<FeatureSetCompat>;
25
+ when(callback?: (featureSet: FeatureSetCompat) => void): Promise<FeatureSetCompat>;
26
+ watch(propertyName: string, listener: (value: unknown) => void): FeatureSetHandleCompat;
27
+ clone(): FeatureSetCompat;
28
+ toJSON(): FeatureSetCompatOptions;
29
+ destroy(): void;
30
+ private notifyWatchers;
31
+ }
32
+ //# sourceMappingURL=feature-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-set.d.ts","sourceRoot":"","sources":["../../../src/esri-compat/feature-set.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,0BAA0B,GAAG,YAAY,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE7E,MAAM,WAAW,sBAAsB;IACrC,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,qBAAa,gBAAgB;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,0BAA0B,CAAC;IACvC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA6C;gBAEzD,OAAO,GAAE,uBAA4B;IAY3C,IAAI,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAcjC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAQxF,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,sBAAsB;IAevF,KAAK,IAAI,gBAAgB;IAIzB,MAAM,IAAI,uBAAuB;IAWjC,OAAO,IAAI,IAAI;IAItB,OAAO,CAAC,cAAc;CAUvB"}