@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.
- package/README.md +5 -0
- package/contract/edit-session.d.ts +203 -0
- package/contract/edit-session.d.ts.map +1 -0
- package/contract/edit-session.js +717 -0
- package/contract/index.d.ts +20 -0
- package/contract/index.d.ts.map +1 -0
- package/contract/index.js +15 -0
- package/contract/jobs.d.ts +115 -0
- package/contract/jobs.d.ts.map +1 -0
- package/contract/jobs.js +22 -0
- package/contract/source.d.ts +138 -0
- package/contract/source.d.ts.map +1 -0
- package/contract/source.js +3364 -0
- package/contract/spatial-aggregation.d.ts +312 -0
- package/contract/spatial-aggregation.d.ts.map +1 -0
- package/contract/spatial-aggregation.js +196 -0
- package/contract/types.d.ts +542 -0
- package/contract/types.d.ts.map +1 -0
- package/contract/types.js +171 -0
- package/core/batch.d.ts +37 -0
- package/core/batch.d.ts.map +1 -0
- package/core/batch.js +78 -0
- package/core/cache-state.d.ts +76 -0
- package/core/cache-state.d.ts.map +1 -0
- package/core/cache-state.js +84 -0
- package/core/client.d.ts +289 -0
- package/core/client.d.ts.map +1 -0
- package/core/client.js +2625 -0
- package/core/errors.d.ts +68 -0
- package/core/errors.d.ts.map +1 -0
- package/core/errors.js +116 -0
- package/core/grpc-adapter.d.ts +23 -0
- package/core/grpc-adapter.d.ts.map +1 -0
- package/core/grpc-adapter.js +704 -0
- package/core/odata.d.ts +347 -0
- package/core/odata.d.ts.map +1 -0
- package/core/odata.js +837 -0
- package/core/ogc-conformance.d.ts +35 -0
- package/core/ogc-conformance.d.ts.map +1 -0
- package/core/ogc-conformance.js +121 -0
- package/core/ogc-maps.d.ts +45 -0
- package/core/ogc-maps.d.ts.map +1 -0
- package/core/ogc-maps.js +53 -0
- package/core/ogc-processes.d.ts +92 -0
- package/core/ogc-processes.d.ts.map +1 -0
- package/core/ogc-processes.js +325 -0
- package/core/ogc-tiles.d.ts +55 -0
- package/core/ogc-tiles.d.ts.map +1 -0
- package/core/ogc-tiles.js +81 -0
- package/core/pbf-decoder.d.ts +28 -0
- package/core/pbf-decoder.d.ts.map +1 -0
- package/core/pbf-decoder.js +627 -0
- package/core/query-builder.d.ts +261 -0
- package/core/query-builder.d.ts.map +1 -0
- package/core/query-builder.js +538 -0
- package/core/spatial-filter.d.ts +93 -0
- package/core/spatial-filter.d.ts.map +1 -0
- package/core/spatial-filter.js +153 -0
- package/core/stac.d.ts +43 -0
- package/core/stac.d.ts.map +1 -0
- package/core/stac.js +116 -0
- package/core/surfaces.d.ts +464 -0
- package/core/surfaces.d.ts.map +1 -0
- package/core/surfaces.js +1322 -0
- package/core/types.d.ts +1238 -0
- package/core/types.d.ts.map +1 -0
- package/core/types.js +13 -0
- package/core/wfs-capabilities.d.ts +143 -0
- package/core/wfs-capabilities.d.ts.map +1 -0
- package/core/wfs-capabilities.js +478 -0
- package/core/wfs-filter.d.ts +118 -0
- package/core/wfs-filter.d.ts.map +1 -0
- package/core/wfs-filter.js +586 -0
- package/core/wfs.d.ts +219 -0
- package/core/wfs.d.ts.map +1 -0
- package/core/wfs.js +406 -0
- package/core/wms-capabilities.d.ts +110 -0
- package/core/wms-capabilities.d.ts.map +1 -0
- package/core/wms-capabilities.js +566 -0
- package/core/wms-types.d.ts +128 -0
- package/core/wms-types.d.ts.map +1 -0
- package/core/wms-types.js +32 -0
- package/core/wms.d.ts +108 -0
- package/core/wms.d.ts.map +1 -0
- package/core/wms.js +182 -0
- package/core/wmts-capabilities.d.ts +82 -0
- package/core/wmts-capabilities.d.ts.map +1 -0
- package/core/wmts-capabilities.js +409 -0
- package/core/wmts.d.ts +80 -0
- package/core/wmts.d.ts.map +1 -0
- package/core/wmts.js +173 -0
- package/esri-compat/basemap-gallery.d.ts +38 -0
- package/esri-compat/basemap-gallery.d.ts.map +1 -0
- package/esri-compat/basemap-gallery.js +159 -0
- package/esri-compat/basemap-layer-list.d.ts +35 -0
- package/esri-compat/basemap-layer-list.d.ts.map +1 -0
- package/esri-compat/basemap-layer-list.js +139 -0
- package/esri-compat/basemap.d.ts +32 -0
- package/esri-compat/basemap.d.ts.map +1 -0
- package/esri-compat/basemap.js +84 -0
- package/esri-compat/bookmarks.d.ts +36 -0
- package/esri-compat/bookmarks.d.ts.map +1 -0
- package/esri-compat/bookmarks.js +108 -0
- package/esri-compat/class-breaks-renderer.d.ts +50 -0
- package/esri-compat/class-breaks-renderer.d.ts.map +1 -0
- package/esri-compat/class-breaks-renderer.js +164 -0
- package/esri-compat/color.d.ts +22 -0
- package/esri-compat/color.d.ts.map +1 -0
- package/esri-compat/color.js +106 -0
- package/esri-compat/controls.d.ts +174 -0
- package/esri-compat/controls.d.ts.map +1 -0
- package/esri-compat/controls.js +479 -0
- package/esri-compat/coordinate-conversion.d.ts +41 -0
- package/esri-compat/coordinate-conversion.d.ts.map +1 -0
- package/esri-compat/coordinate-conversion.js +125 -0
- package/esri-compat/directions.d.ts +45 -0
- package/esri-compat/directions.d.ts.map +1 -0
- package/esri-compat/directions.js +123 -0
- package/esri-compat/editor.d.ts +47 -0
- package/esri-compat/editor.d.ts.map +1 -0
- package/esri-compat/editor.js +170 -0
- package/esri-compat/esri-config.d.ts +16 -0
- package/esri-compat/esri-config.d.ts.map +1 -0
- package/esri-compat/esri-config.js +23 -0
- package/esri-compat/esri-request.d.ts +17 -0
- package/esri-compat/esri-request.d.ts.map +1 -0
- package/esri-compat/esri-request.js +66 -0
- package/esri-compat/event-bus.d.ts +106 -0
- package/esri-compat/event-bus.d.ts.map +1 -0
- package/esri-compat/event-bus.js +90 -0
- package/esri-compat/expand.d.ts +36 -0
- package/esri-compat/expand.d.ts.map +1 -0
- package/esri-compat/expand.js +97 -0
- package/esri-compat/extent.d.ts +43 -0
- package/esri-compat/extent.d.ts.map +1 -0
- package/esri-compat/extent.js +140 -0
- package/esri-compat/feature-form.d.ts +64 -0
- package/esri-compat/feature-form.d.ts.map +1 -0
- package/esri-compat/feature-form.js +137 -0
- package/esri-compat/feature-layer.d.ts +173 -0
- package/esri-compat/feature-layer.d.ts.map +1 -0
- package/esri-compat/feature-layer.js +655 -0
- package/esri-compat/feature-set.d.ts +32 -0
- package/esri-compat/feature-set.d.ts.map +1 -0
- package/esri-compat/feature-set.js +80 -0
- package/esri-compat/feature-table.d.ts +141 -0
- package/esri-compat/feature-table.d.ts.map +1 -0
- package/esri-compat/feature-table.js +500 -0
- package/esri-compat/feature-templates.d.ts +41 -0
- package/esri-compat/feature-templates.d.ts.map +1 -0
- package/esri-compat/feature-templates.js +97 -0
- package/esri-compat/feature.d.ts +33 -0
- package/esri-compat/feature.d.ts.map +1 -0
- package/esri-compat/feature.js +83 -0
- package/esri-compat/graphic.d.ts +46 -0
- package/esri-compat/graphic.d.ts.map +1 -0
- package/esri-compat/graphic.js +103 -0
- package/esri-compat/graphics-layer.d.ts +49 -0
- package/esri-compat/graphics-layer.d.ts.map +1 -0
- package/esri-compat/graphics-layer.js +185 -0
- package/esri-compat/group-layer.d.ts +48 -0
- package/esri-compat/group-layer.d.ts.map +1 -0
- package/esri-compat/group-layer.js +212 -0
- package/esri-compat/identify.d.ts +71 -0
- package/esri-compat/identify.d.ts.map +1 -0
- package/esri-compat/identify.js +299 -0
- package/esri-compat/identity-manager.d.ts +31 -0
- package/esri-compat/identity-manager.d.ts.map +1 -0
- package/esri-compat/identity-manager.js +115 -0
- package/esri-compat/label-class.d.ts +31 -0
- package/esri-compat/label-class.d.ts.map +1 -0
- package/esri-compat/label-class.js +102 -0
- package/esri-compat/layer-list.d.ts +77 -0
- package/esri-compat/layer-list.d.ts.map +1 -0
- package/esri-compat/layer-list.js +342 -0
- package/esri-compat/legend.d.ts +53 -0
- package/esri-compat/legend.d.ts.map +1 -0
- package/esri-compat/legend.js +254 -0
- package/esri-compat/map-image-layer.d.ts +162 -0
- package/esri-compat/map-image-layer.d.ts.map +1 -0
- package/esri-compat/map-image-layer.js +704 -0
- package/esri-compat/map-view.d.ts +315 -0
- package/esri-compat/map-view.d.ts.map +1 -0
- package/esri-compat/map-view.js +1110 -0
- package/esri-compat/map.d.ts +47 -0
- package/esri-compat/map.d.ts.map +1 -0
- package/esri-compat/map.js +209 -0
- package/esri-compat/measurement-2d.d.ts +61 -0
- package/esri-compat/measurement-2d.d.ts.map +1 -0
- package/esri-compat/measurement-2d.js +184 -0
- package/esri-compat/measurement.d.ts +45 -0
- package/esri-compat/measurement.d.ts.map +1 -0
- package/esri-compat/measurement.js +193 -0
- package/esri-compat/oauth-info.d.ts +35 -0
- package/esri-compat/oauth-info.d.ts.map +1 -0
- package/esri-compat/oauth-info.js +115 -0
- package/esri-compat/picture-marker-symbol.d.ts +35 -0
- package/esri-compat/picture-marker-symbol.d.ts.map +1 -0
- package/esri-compat/picture-marker-symbol.js +126 -0
- package/esri-compat/point.d.ts +31 -0
- package/esri-compat/point.d.ts.map +1 -0
- package/esri-compat/point.js +102 -0
- package/esri-compat/polygon.d.ts +31 -0
- package/esri-compat/polygon.d.ts.map +1 -0
- package/esri-compat/polygon.js +107 -0
- package/esri-compat/polyline.d.ts +31 -0
- package/esri-compat/polyline.d.ts.map +1 -0
- package/esri-compat/polyline.js +107 -0
- package/esri-compat/popup-template.d.ts +55 -0
- package/esri-compat/popup-template.d.ts.map +1 -0
- package/esri-compat/popup-template.js +128 -0
- package/esri-compat/popup.d.ts +54 -0
- package/esri-compat/popup.d.ts.map +1 -0
- package/esri-compat/popup.js +312 -0
- package/esri-compat/print.d.ts +47 -0
- package/esri-compat/print.d.ts.map +1 -0
- package/esri-compat/print.js +105 -0
- package/esri-compat/query.d.ts +46 -0
- package/esri-compat/query.d.ts.map +1 -0
- package/esri-compat/query.js +119 -0
- package/esri-compat/reactive-utils.d.ts +23 -0
- package/esri-compat/reactive-utils.d.ts.map +1 -0
- package/esri-compat/reactive-utils.js +178 -0
- package/esri-compat/request.d.ts +41 -0
- package/esri-compat/request.d.ts.map +1 -0
- package/esri-compat/request.js +253 -0
- package/esri-compat/route-layer.d.ts +59 -0
- package/esri-compat/route-layer.d.ts.map +1 -0
- package/esri-compat/route-layer.js +223 -0
- package/esri-compat/route-task.d.ts +88 -0
- package/esri-compat/route-task.d.ts.map +1 -0
- package/esri-compat/route-task.js +225 -0
- package/esri-compat/scene-view.d.ts +41 -0
- package/esri-compat/scene-view.d.ts.map +1 -0
- package/esri-compat/scene-view.js +68 -0
- package/esri-compat/search.d.ts +112 -0
- package/esri-compat/search.d.ts.map +1 -0
- package/esri-compat/search.js +820 -0
- package/esri-compat/simple-fill-symbol.d.ts +27 -0
- package/esri-compat/simple-fill-symbol.d.ts.map +1 -0
- package/esri-compat/simple-fill-symbol.js +85 -0
- package/esri-compat/simple-line-symbol.d.ts +27 -0
- package/esri-compat/simple-line-symbol.d.ts.map +1 -0
- package/esri-compat/simple-line-symbol.js +85 -0
- package/esri-compat/simple-marker-symbol.d.ts +29 -0
- package/esri-compat/simple-marker-symbol.d.ts.map +1 -0
- package/esri-compat/simple-marker-symbol.js +92 -0
- package/esri-compat/simple-renderer.d.ts +29 -0
- package/esri-compat/simple-renderer.d.ts.map +1 -0
- package/esri-compat/simple-renderer.js +92 -0
- package/esri-compat/sketch.d.ts +64 -0
- package/esri-compat/sketch.d.ts.map +1 -0
- package/esri-compat/sketch.js +227 -0
- package/esri-compat/spatial-reference.d.ts +31 -0
- package/esri-compat/spatial-reference.d.ts.map +1 -0
- package/esri-compat/spatial-reference.js +102 -0
- package/esri-compat/swipe.d.ts +34 -0
- package/esri-compat/swipe.d.ts.map +1 -0
- package/esri-compat/swipe.js +93 -0
- package/esri-compat/table-list.d.ts +36 -0
- package/esri-compat/table-list.d.ts.map +1 -0
- package/esri-compat/table-list.js +126 -0
- package/esri-compat/text-symbol.d.ts +37 -0
- package/esri-compat/text-symbol.d.ts.map +1 -0
- package/esri-compat/text-symbol.js +123 -0
- package/esri-compat/tile-layer.d.ts +52 -0
- package/esri-compat/tile-layer.d.ts.map +1 -0
- package/esri-compat/tile-layer.js +167 -0
- package/esri-compat/time-slider.d.ts +70 -0
- package/esri-compat/time-slider.d.ts.map +1 -0
- package/esri-compat/time-slider.js +208 -0
- package/esri-compat/track.d.ts +51 -0
- package/esri-compat/track.d.ts.map +1 -0
- package/esri-compat/track.js +174 -0
- package/esri-compat/unique-value-renderer.d.ts +41 -0
- package/esri-compat/unique-value-renderer.d.ts.map +1 -0
- package/esri-compat/unique-value-renderer.js +127 -0
- package/esri-compat/url.d.ts +12 -0
- package/esri-compat/url.d.ts.map +1 -0
- package/esri-compat/url.js +54 -0
- package/esri-compat/web-map.d.ts +14 -0
- package/esri-compat/web-map.d.ts.map +1 -0
- package/esri-compat/web-map.js +24 -0
- package/gen/honua/v1/feature_service_pb.d.ts +918 -0
- package/gen/honua/v1/feature_service_pb.d.ts.map +1 -0
- package/gen/honua/v1/feature_service_pb.js +375 -0
- package/index.d.ts +130 -0
- package/index.js +65 -0
- package/package.json +22 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { OAuthInfoCompat } from "./oauth-info.js";
|
|
2
|
+
class IdentityManagerCompatStore {
|
|
3
|
+
oauthInfosInternal;
|
|
4
|
+
credentialsInternal;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.oauthInfosInternal = [];
|
|
7
|
+
this.credentialsInternal = [];
|
|
8
|
+
}
|
|
9
|
+
get oauthInfos() {
|
|
10
|
+
return this.oauthInfosInternal.map((info) => info.clone());
|
|
11
|
+
}
|
|
12
|
+
get credentials() {
|
|
13
|
+
return this.credentialsInternal.map((credential) => ({ ...credential }));
|
|
14
|
+
}
|
|
15
|
+
registerOAuthInfos(infos) {
|
|
16
|
+
this.oauthInfosInternal.length = 0;
|
|
17
|
+
for (const info of infos) {
|
|
18
|
+
this.oauthInfosInternal.push(info instanceof OAuthInfoCompat ? info.clone() : new OAuthInfoCompat(info));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
registerToken(token) {
|
|
22
|
+
const next = {
|
|
23
|
+
server: token.server,
|
|
24
|
+
token: token.token,
|
|
25
|
+
expires: typeof token.expires === "number" && Number.isFinite(token.expires) ? token.expires : undefined,
|
|
26
|
+
userId: token.userId,
|
|
27
|
+
};
|
|
28
|
+
const deduped = [];
|
|
29
|
+
let replaced = false;
|
|
30
|
+
for (const existing of this.credentialsInternal) {
|
|
31
|
+
if (isSameCredentialServer(existing.server, next.server)) {
|
|
32
|
+
if (!replaced) {
|
|
33
|
+
deduped.push(next);
|
|
34
|
+
replaced = true;
|
|
35
|
+
}
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
deduped.push(existing);
|
|
39
|
+
}
|
|
40
|
+
if (!replaced) {
|
|
41
|
+
deduped.push(next);
|
|
42
|
+
}
|
|
43
|
+
this.credentialsInternal.length = 0;
|
|
44
|
+
this.credentialsInternal.push(...deduped);
|
|
45
|
+
}
|
|
46
|
+
findCredential(url) {
|
|
47
|
+
const match = this.findCredentialEntry(url);
|
|
48
|
+
if (!match || isCredentialExpired(match)) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return { ...match };
|
|
52
|
+
}
|
|
53
|
+
async checkSignInStatus(url) {
|
|
54
|
+
const credential = this.findCredentialEntry(url);
|
|
55
|
+
if (!credential) {
|
|
56
|
+
throw new Error("No registered credential for requested server.");
|
|
57
|
+
}
|
|
58
|
+
if (isCredentialExpired(credential)) {
|
|
59
|
+
throw new Error("Registered credential for requested server has expired.");
|
|
60
|
+
}
|
|
61
|
+
return { ...credential };
|
|
62
|
+
}
|
|
63
|
+
async getCredential(url) {
|
|
64
|
+
return this.checkSignInStatus(url);
|
|
65
|
+
}
|
|
66
|
+
destroyCredentials() {
|
|
67
|
+
this.credentialsInternal.length = 0;
|
|
68
|
+
}
|
|
69
|
+
reset() {
|
|
70
|
+
this.oauthInfosInternal.length = 0;
|
|
71
|
+
this.credentialsInternal.length = 0;
|
|
72
|
+
}
|
|
73
|
+
findCredentialEntry(url) {
|
|
74
|
+
const normalized = normalizeServerUrl(url);
|
|
75
|
+
if (!normalized) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
for (let index = this.credentialsInternal.length - 1; index >= 0; index -= 1) {
|
|
79
|
+
const credential = this.credentialsInternal[index];
|
|
80
|
+
if (!credential) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const server = normalizeServerUrl(credential.server);
|
|
84
|
+
if (!server) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (normalized === server || normalized.startsWith(`${server}/`)) {
|
|
88
|
+
return credential;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export const identityManager = new IdentityManagerCompatStore();
|
|
95
|
+
function normalizeServerUrl(value) {
|
|
96
|
+
try {
|
|
97
|
+
const url = new URL(value);
|
|
98
|
+
const pathname = url.pathname.endsWith("/") ? url.pathname.slice(0, -1) : url.pathname;
|
|
99
|
+
return `${url.protocol}//${url.host}${pathname}`;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function isCredentialExpired(credential) {
|
|
106
|
+
return (typeof credential.expires === "number" && Number.isFinite(credential.expires) && credential.expires <= Date.now());
|
|
107
|
+
}
|
|
108
|
+
function isSameCredentialServer(left, right) {
|
|
109
|
+
const leftNormalized = normalizeServerUrl(left);
|
|
110
|
+
const rightNormalized = normalizeServerUrl(right);
|
|
111
|
+
if (leftNormalized && rightNormalized) {
|
|
112
|
+
return leftNormalized === rightNormalized;
|
|
113
|
+
}
|
|
114
|
+
return left === right;
|
|
115
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface LabelClassCompatOptions {
|
|
2
|
+
labelExpressionInfo?: unknown;
|
|
3
|
+
symbol?: unknown;
|
|
4
|
+
where?: string;
|
|
5
|
+
minScale?: number;
|
|
6
|
+
maxScale?: number;
|
|
7
|
+
}
|
|
8
|
+
export type LabelClassLoadStatusCompat = "not-loaded" | "loading" | "loaded";
|
|
9
|
+
export interface LabelClassHandleCompat {
|
|
10
|
+
remove(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class LabelClassCompat {
|
|
13
|
+
loaded: boolean;
|
|
14
|
+
loadStatus: LabelClassLoadStatusCompat;
|
|
15
|
+
labelExpressionInfo: unknown;
|
|
16
|
+
symbol: unknown;
|
|
17
|
+
where: string | undefined;
|
|
18
|
+
minScale: number | undefined;
|
|
19
|
+
maxScale: number | undefined;
|
|
20
|
+
private readonly watchListeners;
|
|
21
|
+
constructor(options?: LabelClassCompatOptions);
|
|
22
|
+
load(): Promise<LabelClassCompat>;
|
|
23
|
+
when(callback?: (labelClass: LabelClassCompat) => void): Promise<LabelClassCompat>;
|
|
24
|
+
watch(propertyName: string, listener: (value: unknown) => void): LabelClassHandleCompat;
|
|
25
|
+
update(options: LabelClassCompatOptions): void;
|
|
26
|
+
clone(): LabelClassCompat;
|
|
27
|
+
toJSON(): LabelClassCompatOptions;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
private notifyWatchers;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=label-class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"label-class.d.ts","sourceRoot":"","sources":["../../../src/esri-compat/label-class.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,uBAAuB;IACtC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;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,mBAAmB,EAAE,OAAO,CAAC;IAC7B,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA6C;gBAEzD,OAAO,GAAE,uBAA4B;IAW3C,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,MAAM,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAuB9C,KAAK,IAAI,gBAAgB;IAIzB,MAAM,IAAI,uBAAuB;IAUjC,OAAO,IAAI,IAAI;IAItB,OAAO,CAAC,cAAc;CAUvB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { safeInvokeCompatListener } from "./event-bus.js";
|
|
2
|
+
export class LabelClassCompat {
|
|
3
|
+
loaded;
|
|
4
|
+
loadStatus;
|
|
5
|
+
labelExpressionInfo;
|
|
6
|
+
symbol;
|
|
7
|
+
where;
|
|
8
|
+
minScale;
|
|
9
|
+
maxScale;
|
|
10
|
+
watchListeners;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.loaded = false;
|
|
13
|
+
this.loadStatus = "not-loaded";
|
|
14
|
+
this.labelExpressionInfo = options.labelExpressionInfo;
|
|
15
|
+
this.symbol = options.symbol;
|
|
16
|
+
this.where = options.where;
|
|
17
|
+
this.minScale = finiteNumberOrUndefined(options.minScale);
|
|
18
|
+
this.maxScale = finiteNumberOrUndefined(options.maxScale);
|
|
19
|
+
this.watchListeners = new Map();
|
|
20
|
+
}
|
|
21
|
+
async load() {
|
|
22
|
+
if (this.loaded) {
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
this.loadStatus = "loading";
|
|
26
|
+
this.notifyWatchers("loadStatus", this.loadStatus);
|
|
27
|
+
this.loaded = true;
|
|
28
|
+
this.notifyWatchers("loaded", this.loaded);
|
|
29
|
+
this.loadStatus = "loaded";
|
|
30
|
+
this.notifyWatchers("loadStatus", this.loadStatus);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
async when(callback) {
|
|
34
|
+
const labelClass = await this.load();
|
|
35
|
+
if (callback) {
|
|
36
|
+
callback(labelClass);
|
|
37
|
+
}
|
|
38
|
+
return labelClass;
|
|
39
|
+
}
|
|
40
|
+
watch(propertyName, listener) {
|
|
41
|
+
let listeners = this.watchListeners.get(propertyName);
|
|
42
|
+
if (!listeners) {
|
|
43
|
+
listeners = new Set();
|
|
44
|
+
this.watchListeners.set(propertyName, listeners);
|
|
45
|
+
}
|
|
46
|
+
listeners.add(listener);
|
|
47
|
+
return {
|
|
48
|
+
remove: () => {
|
|
49
|
+
listeners?.delete(listener);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
update(options) {
|
|
54
|
+
if (options.labelExpressionInfo !== undefined) {
|
|
55
|
+
this.labelExpressionInfo = options.labelExpressionInfo;
|
|
56
|
+
this.notifyWatchers("labelExpressionInfo", this.labelExpressionInfo);
|
|
57
|
+
}
|
|
58
|
+
if (options.symbol !== undefined) {
|
|
59
|
+
this.symbol = options.symbol;
|
|
60
|
+
this.notifyWatchers("symbol", this.symbol);
|
|
61
|
+
}
|
|
62
|
+
if (options.where !== undefined) {
|
|
63
|
+
this.where = options.where;
|
|
64
|
+
this.notifyWatchers("where", this.where);
|
|
65
|
+
}
|
|
66
|
+
if (options.minScale !== undefined) {
|
|
67
|
+
this.minScale = finiteNumberOrUndefined(options.minScale);
|
|
68
|
+
this.notifyWatchers("minScale", this.minScale);
|
|
69
|
+
}
|
|
70
|
+
if (options.maxScale !== undefined) {
|
|
71
|
+
this.maxScale = finiteNumberOrUndefined(options.maxScale);
|
|
72
|
+
this.notifyWatchers("maxScale", this.maxScale);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
clone() {
|
|
76
|
+
return new LabelClassCompat(this.toJSON());
|
|
77
|
+
}
|
|
78
|
+
toJSON() {
|
|
79
|
+
return {
|
|
80
|
+
labelExpressionInfo: this.labelExpressionInfo,
|
|
81
|
+
symbol: this.symbol,
|
|
82
|
+
where: this.where,
|
|
83
|
+
minScale: this.minScale,
|
|
84
|
+
maxScale: this.maxScale,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
destroy() {
|
|
88
|
+
this.watchListeners.clear();
|
|
89
|
+
}
|
|
90
|
+
notifyWatchers(propertyName, value) {
|
|
91
|
+
const listeners = this.watchListeners.get(propertyName);
|
|
92
|
+
if (!listeners) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
for (const listener of listeners) {
|
|
96
|
+
safeInvokeCompatListener(listener, value);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function finiteNumberOrUndefined(value) {
|
|
101
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
102
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { CompatEventBus } from "./event-bus.js";
|
|
2
|
+
export interface LayerListCompatOptions {
|
|
3
|
+
view?: unknown;
|
|
4
|
+
map?: unknown;
|
|
5
|
+
container?: unknown;
|
|
6
|
+
eventBus?: CompatEventBus;
|
|
7
|
+
includeHidden?: boolean;
|
|
8
|
+
autoRefresh?: boolean;
|
|
9
|
+
listItemCreatedFunction?: (event: LayerListListItemCreatedEventCompat) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface LayerListActionCompat {
|
|
12
|
+
id: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
icon?: string;
|
|
16
|
+
value?: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface LayerListItemCompat {
|
|
19
|
+
id: string | number | undefined;
|
|
20
|
+
title: string;
|
|
21
|
+
visible: boolean;
|
|
22
|
+
layer: unknown;
|
|
23
|
+
actionsSections: LayerListActionCompat[][];
|
|
24
|
+
children: LayerListItemCompat[];
|
|
25
|
+
}
|
|
26
|
+
export interface LayerListListItemCreatedEventCompat {
|
|
27
|
+
item: LayerListItemCompat;
|
|
28
|
+
}
|
|
29
|
+
export interface LayerListTriggerActionEventCompat {
|
|
30
|
+
action: LayerListActionCompat;
|
|
31
|
+
actionId: string;
|
|
32
|
+
item: LayerListItemCompat;
|
|
33
|
+
layer: unknown;
|
|
34
|
+
}
|
|
35
|
+
export interface LayerListUpdatedEventCompat {
|
|
36
|
+
itemCount: number;
|
|
37
|
+
}
|
|
38
|
+
export interface LayerListHandleCompat {
|
|
39
|
+
remove(): void;
|
|
40
|
+
}
|
|
41
|
+
export type LayerListLoadStatusCompat = "not-loaded" | "loading" | "loaded";
|
|
42
|
+
interface LayerListEventPayloadByType {
|
|
43
|
+
"trigger-action": LayerListTriggerActionEventCompat;
|
|
44
|
+
updated: LayerListUpdatedEventCompat;
|
|
45
|
+
}
|
|
46
|
+
type LayerListEventTypeCompat = keyof LayerListEventPayloadByType;
|
|
47
|
+
export declare class LayerListCompat {
|
|
48
|
+
readonly view: unknown;
|
|
49
|
+
readonly map: unknown;
|
|
50
|
+
readonly container: unknown;
|
|
51
|
+
readonly eventBus: CompatEventBus;
|
|
52
|
+
readonly includeHidden: boolean;
|
|
53
|
+
loaded: boolean;
|
|
54
|
+
loadStatus: LayerListLoadStatusCompat;
|
|
55
|
+
items: LayerListItemCompat[];
|
|
56
|
+
private readonly autoRefresh;
|
|
57
|
+
private readonly listItemCreatedFunction;
|
|
58
|
+
private readonly listenersByType;
|
|
59
|
+
private readonly watchListeners;
|
|
60
|
+
private subscriptions;
|
|
61
|
+
constructor(options?: LayerListCompatOptions);
|
|
62
|
+
load(): Promise<LayerListCompat>;
|
|
63
|
+
when(callback?: (widget: LayerListCompat) => void): Promise<LayerListCompat>;
|
|
64
|
+
watch(propertyName: string, listener: (value: unknown) => void): LayerListHandleCompat;
|
|
65
|
+
refresh(): readonly LayerListItemCompat[];
|
|
66
|
+
toggle(layerOrId: unknown | string | number, visible?: boolean): boolean;
|
|
67
|
+
setItemActions(layerOrId: unknown | string | number, actionsSections: readonly (readonly LayerListActionCompat[])[]): boolean;
|
|
68
|
+
triggerAction(actionId: string, layerOrId?: unknown | string | number): boolean;
|
|
69
|
+
on<TType extends LayerListEventTypeCompat>(type: TType, listener: (event: LayerListEventPayloadByType[TType]) => void): LayerListHandleCompat;
|
|
70
|
+
destroy(): void;
|
|
71
|
+
private findLayer;
|
|
72
|
+
private findItem;
|
|
73
|
+
private emit;
|
|
74
|
+
private notifyWatchers;
|
|
75
|
+
}
|
|
76
|
+
export {};
|
|
77
|
+
//# sourceMappingURL=layer-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer-list.d.ts","sourceRoot":"","sources":["../../../src/esri-compat/layer-list.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { CompatEventBus, resolveCompatEventBus, safeInvokeCompatListener, } from "./event-bus.js";
|
|
2
|
+
export class LayerListCompat {
|
|
3
|
+
view;
|
|
4
|
+
map;
|
|
5
|
+
container;
|
|
6
|
+
eventBus;
|
|
7
|
+
includeHidden;
|
|
8
|
+
loaded;
|
|
9
|
+
loadStatus;
|
|
10
|
+
items;
|
|
11
|
+
autoRefresh;
|
|
12
|
+
listItemCreatedFunction;
|
|
13
|
+
listenersByType;
|
|
14
|
+
watchListeners;
|
|
15
|
+
subscriptions;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.view = options.view;
|
|
18
|
+
this.map = options.map ?? extractMapFromView(options.view);
|
|
19
|
+
this.container = options.container;
|
|
20
|
+
this.eventBus = options.eventBus ?? resolveCompatEventBus(this.view, this.map) ?? new CompatEventBus();
|
|
21
|
+
this.includeHidden = options.includeHidden ?? false;
|
|
22
|
+
this.loaded = false;
|
|
23
|
+
this.loadStatus = "not-loaded";
|
|
24
|
+
this.autoRefresh = options.autoRefresh ?? true;
|
|
25
|
+
this.listItemCreatedFunction = options.listItemCreatedFunction;
|
|
26
|
+
this.items = [];
|
|
27
|
+
this.listenersByType = new Map();
|
|
28
|
+
this.watchListeners = new Map();
|
|
29
|
+
this.subscriptions = [];
|
|
30
|
+
if (this.autoRefresh) {
|
|
31
|
+
this.subscriptions.push(this.eventBus.on("map.layer-added", () => this.refresh()));
|
|
32
|
+
this.subscriptions.push(this.eventBus.on("map.layer-removed", () => this.refresh()));
|
|
33
|
+
this.subscriptions.push(this.eventBus.on("map.layers-added", () => this.refresh()));
|
|
34
|
+
this.subscriptions.push(this.eventBus.on("map.layers-cleared", () => this.refresh()));
|
|
35
|
+
this.subscriptions.push(this.eventBus.on("map.layer-reordered", () => this.refresh()));
|
|
36
|
+
this.subscriptions.push(this.eventBus.on("group-layer.layer-added", () => this.refresh()));
|
|
37
|
+
this.subscriptions.push(this.eventBus.on("group-layer.layer-removed", () => this.refresh()));
|
|
38
|
+
this.subscriptions.push(this.eventBus.on("group-layer.layers-added", () => this.refresh()));
|
|
39
|
+
this.subscriptions.push(this.eventBus.on("group-layer.layers-cleared", () => this.refresh()));
|
|
40
|
+
this.subscriptions.push(this.eventBus.on("layer.visibility-changed", () => this.refresh()));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async load() {
|
|
44
|
+
if (this.loaded) {
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
this.loadStatus = "loading";
|
|
48
|
+
this.notifyWatchers("loadStatus", this.loadStatus);
|
|
49
|
+
this.eventBus.emit("layer-list.loading", undefined, this);
|
|
50
|
+
this.refresh();
|
|
51
|
+
this.loaded = true;
|
|
52
|
+
this.notifyWatchers("loaded", this.loaded);
|
|
53
|
+
this.loadStatus = "loaded";
|
|
54
|
+
this.notifyWatchers("loadStatus", this.loadStatus);
|
|
55
|
+
this.eventBus.emit("layer-list.loaded", { itemCount: this.items.length }, this);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
async when(callback) {
|
|
59
|
+
const widget = await this.load();
|
|
60
|
+
if (callback) {
|
|
61
|
+
callback(widget);
|
|
62
|
+
}
|
|
63
|
+
return widget;
|
|
64
|
+
}
|
|
65
|
+
watch(propertyName, listener) {
|
|
66
|
+
let listeners = this.watchListeners.get(propertyName);
|
|
67
|
+
if (!listeners) {
|
|
68
|
+
listeners = new Set();
|
|
69
|
+
this.watchListeners.set(propertyName, listeners);
|
|
70
|
+
}
|
|
71
|
+
listeners.add(listener);
|
|
72
|
+
return {
|
|
73
|
+
remove: () => {
|
|
74
|
+
listeners?.delete(listener);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
refresh() {
|
|
79
|
+
const rootLayers = getRootLayers(this.map);
|
|
80
|
+
this.items = rootLayers
|
|
81
|
+
.map((layer, index) => toLayerListItem(layer, this.includeHidden, index))
|
|
82
|
+
.filter((item) => item !== undefined);
|
|
83
|
+
if (this.listItemCreatedFunction) {
|
|
84
|
+
for (const item of this.items) {
|
|
85
|
+
applyListItemCreated(item, this.listItemCreatedFunction);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
this.notifyWatchers("items", this.items);
|
|
89
|
+
const updateEvent = { itemCount: this.items.length };
|
|
90
|
+
this.eventBus.emit("layer-list.updated", updateEvent, this);
|
|
91
|
+
this.emit("updated", updateEvent);
|
|
92
|
+
return this.items;
|
|
93
|
+
}
|
|
94
|
+
toggle(layerOrId, visible) {
|
|
95
|
+
const layer = this.findLayer(layerOrId);
|
|
96
|
+
if (!layer || !isLayerLike(layer)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
const nextVisible = visible ?? !toVisible(layer);
|
|
100
|
+
if (hasSetVisibility(layer)) {
|
|
101
|
+
layer.setVisibility(nextVisible);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
layer.visible = nextVisible;
|
|
105
|
+
this.eventBus.emit("layer.visibility-changed", { layerId: layer.id, visible: nextVisible }, this);
|
|
106
|
+
}
|
|
107
|
+
this.refresh();
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
setItemActions(layerOrId, actionsSections) {
|
|
111
|
+
const item = this.findItem(layerOrId);
|
|
112
|
+
if (!item) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
item.actionsSections = normalizeActionSections(actionsSections);
|
|
116
|
+
this.notifyWatchers("items", this.items);
|
|
117
|
+
const updateEvent = { itemCount: this.items.length };
|
|
118
|
+
this.eventBus.emit("layer-list.updated", updateEvent, this);
|
|
119
|
+
this.emit("updated", updateEvent);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
triggerAction(actionId, layerOrId) {
|
|
123
|
+
const item = layerOrId === undefined ? this.items[0] : this.findItem(layerOrId);
|
|
124
|
+
if (!item) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
const action = findActionById(item.actionsSections, actionId);
|
|
128
|
+
if (!action) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const event = {
|
|
132
|
+
action,
|
|
133
|
+
actionId: action.id,
|
|
134
|
+
item,
|
|
135
|
+
layer: item.layer,
|
|
136
|
+
};
|
|
137
|
+
this.eventBus.emit("layer-list.trigger-action", event, this);
|
|
138
|
+
this.emit("trigger-action", event);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
on(type, listener) {
|
|
142
|
+
let listeners = this.listenersByType.get(type);
|
|
143
|
+
if (!listeners) {
|
|
144
|
+
listeners = new Set();
|
|
145
|
+
this.listenersByType.set(type, listeners);
|
|
146
|
+
}
|
|
147
|
+
const untypedListener = listener;
|
|
148
|
+
listeners.add(untypedListener);
|
|
149
|
+
return {
|
|
150
|
+
remove: () => {
|
|
151
|
+
listeners?.delete(untypedListener);
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
destroy() {
|
|
156
|
+
for (const subscription of this.subscriptions.splice(0)) {
|
|
157
|
+
subscription.remove();
|
|
158
|
+
}
|
|
159
|
+
this.listenersByType.clear();
|
|
160
|
+
this.watchListeners.clear();
|
|
161
|
+
}
|
|
162
|
+
findLayer(layerOrId) {
|
|
163
|
+
const rootLayers = getRootLayers(this.map);
|
|
164
|
+
if (typeof layerOrId !== "string" && typeof layerOrId !== "number") {
|
|
165
|
+
return findLayerByReference(rootLayers, layerOrId);
|
|
166
|
+
}
|
|
167
|
+
return findLayerById(rootLayers, layerOrId);
|
|
168
|
+
}
|
|
169
|
+
findItem(layerOrId) {
|
|
170
|
+
if (typeof layerOrId !== "string" && typeof layerOrId !== "number") {
|
|
171
|
+
return findItemByLayer(this.items, layerOrId);
|
|
172
|
+
}
|
|
173
|
+
return findItemById(this.items, layerOrId);
|
|
174
|
+
}
|
|
175
|
+
emit(type, event) {
|
|
176
|
+
const listeners = this.listenersByType.get(type);
|
|
177
|
+
if (!listeners) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
for (const listener of listeners) {
|
|
181
|
+
try {
|
|
182
|
+
safeInvokeCompatListener(listener, event);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
// Listener errors should not break widget compatibility flow.
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
notifyWatchers(propertyName, value) {
|
|
190
|
+
const listeners = this.watchListeners.get(propertyName);
|
|
191
|
+
if (!listeners) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
for (const listener of listeners) {
|
|
195
|
+
safeInvokeCompatListener(listener, value);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function extractMapFromView(view) {
|
|
200
|
+
if (!isRecord(view)) {
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
return view.map;
|
|
204
|
+
}
|
|
205
|
+
function getRootLayers(map) {
|
|
206
|
+
if (!isRecord(map) || !Array.isArray(map.layers)) {
|
|
207
|
+
return [];
|
|
208
|
+
}
|
|
209
|
+
return [...map.layers];
|
|
210
|
+
}
|
|
211
|
+
function toLayerListItem(layer, includeHidden, index) {
|
|
212
|
+
if (!isLayerLike(layer)) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
if (!includeHidden && !toVisible(layer)) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
const children = getChildLayers(layer)
|
|
219
|
+
.map((child, childIndex) => toLayerListItem(child, includeHidden, childIndex))
|
|
220
|
+
.filter((item) => item !== undefined);
|
|
221
|
+
return {
|
|
222
|
+
id: layer.id,
|
|
223
|
+
title: toLayerTitle(layer, index),
|
|
224
|
+
visible: toVisible(layer),
|
|
225
|
+
layer,
|
|
226
|
+
actionsSections: [],
|
|
227
|
+
children,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function applyListItemCreated(item, callback) {
|
|
231
|
+
callback({ item });
|
|
232
|
+
for (const child of item.children) {
|
|
233
|
+
applyListItemCreated(child, callback);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function normalizeActionSections(actionsSections) {
|
|
237
|
+
return actionsSections.map((section) => section
|
|
238
|
+
.filter((action) => typeof action.id === "string" && action.id.trim().length > 0)
|
|
239
|
+
.map((action) => ({ ...action })));
|
|
240
|
+
}
|
|
241
|
+
function findActionById(actionsSections, actionId) {
|
|
242
|
+
for (const section of actionsSections) {
|
|
243
|
+
for (const action of section) {
|
|
244
|
+
if (action.id === actionId) {
|
|
245
|
+
return action;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
function findItemByLayer(items, layer) {
|
|
252
|
+
for (const item of items) {
|
|
253
|
+
if (item.layer === layer) {
|
|
254
|
+
return item;
|
|
255
|
+
}
|
|
256
|
+
const nested = findItemByLayer(item.children, layer);
|
|
257
|
+
if (nested) {
|
|
258
|
+
return nested;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
function findItemById(items, id) {
|
|
264
|
+
const normalizedId = String(id);
|
|
265
|
+
for (const item of items) {
|
|
266
|
+
if (item.id !== undefined && String(item.id) === normalizedId) {
|
|
267
|
+
return item;
|
|
268
|
+
}
|
|
269
|
+
const nested = findItemById(item.children, id);
|
|
270
|
+
if (nested) {
|
|
271
|
+
return nested;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
function findLayerByReference(layers, target) {
|
|
277
|
+
for (const layer of layers) {
|
|
278
|
+
if (layer === target) {
|
|
279
|
+
return layer;
|
|
280
|
+
}
|
|
281
|
+
const nested = findLayerByReference(getChildLayers(layer), target);
|
|
282
|
+
if (nested !== undefined) {
|
|
283
|
+
return nested;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
function findLayerById(layers, id) {
|
|
289
|
+
const normalizedId = String(id);
|
|
290
|
+
for (const layer of layers) {
|
|
291
|
+
if (isLayerLike(layer) && layer.id !== undefined && String(layer.id) === normalizedId) {
|
|
292
|
+
return layer;
|
|
293
|
+
}
|
|
294
|
+
const nested = findLayerById(getChildLayers(layer), id);
|
|
295
|
+
if (nested !== undefined) {
|
|
296
|
+
return nested;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
function isLayerLike(value) {
|
|
302
|
+
return typeof value === "object" && value !== null;
|
|
303
|
+
}
|
|
304
|
+
function hasSetVisibility(value) {
|
|
305
|
+
if (!isLayerLike(value)) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
return typeof value.setVisibility === "function";
|
|
309
|
+
}
|
|
310
|
+
function getChildLayers(layer) {
|
|
311
|
+
if (!isRecord(layer)) {
|
|
312
|
+
return [];
|
|
313
|
+
}
|
|
314
|
+
if (Array.isArray(layer.layers)) {
|
|
315
|
+
return [...layer.layers];
|
|
316
|
+
}
|
|
317
|
+
if (Array.isArray(layer.allSublayers)) {
|
|
318
|
+
return [...layer.allSublayers];
|
|
319
|
+
}
|
|
320
|
+
if (Array.isArray(layer.sublayers)) {
|
|
321
|
+
return [...layer.sublayers];
|
|
322
|
+
}
|
|
323
|
+
return [];
|
|
324
|
+
}
|
|
325
|
+
function toLayerTitle(layer, index) {
|
|
326
|
+
if (typeof layer.title === "string" && layer.title.trim().length > 0) {
|
|
327
|
+
return layer.title;
|
|
328
|
+
}
|
|
329
|
+
if (typeof layer.id === "string" && layer.id.trim().length > 0) {
|
|
330
|
+
return layer.id;
|
|
331
|
+
}
|
|
332
|
+
if (typeof layer.id === "number" && Number.isFinite(layer.id)) {
|
|
333
|
+
return String(layer.id);
|
|
334
|
+
}
|
|
335
|
+
return `Layer ${index + 1}`;
|
|
336
|
+
}
|
|
337
|
+
function toVisible(layer) {
|
|
338
|
+
return layer.visible ?? true;
|
|
339
|
+
}
|
|
340
|
+
function isRecord(value) {
|
|
341
|
+
return typeof value === "object" && value !== null;
|
|
342
|
+
}
|