@loaders.gl/services 5.0.0-alpha.6 → 5.0.0-alpha.8
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 +7 -46
- package/dist/authentication.d.ts +22 -9
- package/dist/authentication.d.ts.map +1 -1
- package/dist/authentication.js +28 -11
- package/dist/authentication.js.map +1 -1
- package/dist/index.cjs +301 -23380
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -20
- package/dist/index.js.map +1 -1
- package/package.json +6 -16
- package/src/authentication.ts +31 -19
- package/src/index.ts +3 -84
- package/dist/arcgis/arcgis-capability-graph.d.ts +0 -48
- package/dist/arcgis/arcgis-capability-graph.d.ts.map +0 -1
- package/dist/arcgis/arcgis-capability-graph.js +0 -220
- package/dist/arcgis/arcgis-capability-graph.js.map +0 -1
- package/dist/arcgis/arcgis-feature-server-source-loader.d.ts +0 -94
- package/dist/arcgis/arcgis-feature-server-source-loader.d.ts.map +0 -1
- package/dist/arcgis/arcgis-feature-server-source-loader.js +0 -230
- package/dist/arcgis/arcgis-feature-server-source-loader.js.map +0 -1
- package/dist/arcgis/arcgis-image-server-source-loader.d.ts +0 -96
- package/dist/arcgis/arcgis-image-server-source-loader.d.ts.map +0 -1
- package/dist/arcgis/arcgis-image-server-source-loader.js +0 -143
- package/dist/arcgis/arcgis-image-server-source-loader.js.map +0 -1
- package/dist/arcgis/arcgis-image-tile-source-loader.d.ts +0 -71
- package/dist/arcgis/arcgis-image-tile-source-loader.d.ts.map +0 -1
- package/dist/arcgis/arcgis-image-tile-source-loader.js +0 -153
- package/dist/arcgis/arcgis-image-tile-source-loader.js.map +0 -1
- package/dist/arcgis/arcgis-map-tile-source-loader.d.ts +0 -106
- package/dist/arcgis/arcgis-map-tile-source-loader.d.ts.map +0 -1
- package/dist/arcgis/arcgis-map-tile-source-loader.js +0 -202
- package/dist/arcgis/arcgis-map-tile-source-loader.js.map +0 -1
- package/dist/arcgis/arcgis-scene-aggregation.d.ts +0 -34
- package/dist/arcgis/arcgis-scene-aggregation.d.ts.map +0 -1
- package/dist/arcgis/arcgis-scene-aggregation.js +0 -57
- package/dist/arcgis/arcgis-scene-aggregation.js.map +0 -1
- package/dist/arcgis/arcgis-scene-server-source-loader.d.ts +0 -112
- package/dist/arcgis/arcgis-scene-server-source-loader.d.ts.map +0 -1
- package/dist/arcgis/arcgis-scene-server-source-loader.js +0 -157
- package/dist/arcgis/arcgis-scene-server-source-loader.js.map +0 -1
- package/dist/arcgis/arcgis-server.d.ts +0 -15
- package/dist/arcgis/arcgis-server.d.ts.map +0 -1
- package/dist/arcgis/arcgis-server.js +0 -41
- package/dist/arcgis/arcgis-server.js.map +0 -1
- package/dist/arcgis/arcgis-url-utils.d.ts +0 -3
- package/dist/arcgis/arcgis-url-utils.d.ts.map +0 -1
- package/dist/arcgis/arcgis-url-utils.js +0 -23
- package/dist/arcgis/arcgis-url-utils.js.map +0 -1
- package/dist/arcgis/arcgis-vector-tile-server-source-loader.d.ts +0 -115
- package/dist/arcgis/arcgis-vector-tile-server-source-loader.d.ts.map +0 -1
- package/dist/arcgis/arcgis-vector-tile-server-source-loader.js +0 -156
- package/dist/arcgis/arcgis-vector-tile-server-source-loader.js.map +0 -1
- package/dist/service-registry.d.ts +0 -18
- package/dist/service-registry.d.ts.map +0 -1
- package/dist/service-registry.js +0 -29
- package/dist/service-registry.js.map +0 -1
- package/src/arcgis/arcgis-capability-graph.ts +0 -295
- package/src/arcgis/arcgis-feature-server-source-loader.ts +0 -344
- package/src/arcgis/arcgis-image-server-source-loader.ts +0 -242
- package/src/arcgis/arcgis-image-tile-source-loader.ts +0 -206
- package/src/arcgis/arcgis-map-tile-source-loader.ts +0 -286
- package/src/arcgis/arcgis-scene-aggregation.ts +0 -90
- package/src/arcgis/arcgis-scene-server-source-loader.ts +0 -258
- package/src/arcgis/arcgis-server.ts +0 -61
- package/src/arcgis/arcgis-url-utils.ts +0 -26
- package/src/arcgis/arcgis-vector-tile-server-source-loader.ts +0 -233
- package/src/service-registry.ts +0 -43
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {CoreAPI, DataSourceOptions, SourceLoader} from '@loaders.gl/loader-utils';
|
|
6
|
-
import {DataSource} from '@loaders.gl/loader-utils';
|
|
7
|
-
import {
|
|
8
|
-
createI3SLayerSource,
|
|
9
|
-
normalizeI3SServiceMetadata,
|
|
10
|
-
parseI3SSceneLayerMetadata
|
|
11
|
-
} from '@loaders.gl/i3s';
|
|
12
|
-
import type {I3SLayerSource, I3SServiceMetadata, SceneLayer3D} from '@loaders.gl/i3s';
|
|
13
|
-
import {buildArcGISResourceURL} from './arcgis-url-utils';
|
|
14
|
-
|
|
15
|
-
/** Parameters accepted by the ArcGIS SceneServer query endpoint. */
|
|
16
|
-
export type ArcGISSceneQueryOptions = {
|
|
17
|
-
/** SQL where clause. */
|
|
18
|
-
where?: string;
|
|
19
|
-
/** Object IDs to include. */
|
|
20
|
-
objectIds?: number[] | string;
|
|
21
|
-
/** Geometry filter encoded using ArcGIS REST geometry syntax. */
|
|
22
|
-
geometry?: unknown;
|
|
23
|
-
/** Geometry type for the geometry filter. */
|
|
24
|
-
geometryType?: string;
|
|
25
|
-
/** Spatial relationship for the geometry filter. */
|
|
26
|
-
spatialRel?: string;
|
|
27
|
-
/** Fields to return. */
|
|
28
|
-
outFields?: string | string[];
|
|
29
|
-
/** Whether feature geometry should be included. */
|
|
30
|
-
returnGeometry?: boolean;
|
|
31
|
-
/** Input spatial reference. */
|
|
32
|
-
inSR?: string | number | object;
|
|
33
|
-
/** Output spatial reference. */
|
|
34
|
-
outSR?: string | number | object;
|
|
35
|
-
/** ArcGIS result type. */
|
|
36
|
-
resultType?: string;
|
|
37
|
-
/** Result page offset. */
|
|
38
|
-
resultOffset?: number;
|
|
39
|
-
/** Maximum records in one page. */
|
|
40
|
-
resultRecordCount?: number;
|
|
41
|
-
/** Response format. */
|
|
42
|
-
f?: 'json' | 'pjson';
|
|
43
|
-
/** Abort signal for the request. */
|
|
44
|
-
signal?: AbortSignal;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/** Normalized result returned by a SceneServer query. */
|
|
48
|
-
export type ArcGISSceneQueryResult = {
|
|
49
|
-
/** Returned SceneServer features. */
|
|
50
|
-
features: unknown[];
|
|
51
|
-
/** Field metadata advertised by the layer. */
|
|
52
|
-
fields?: unknown[];
|
|
53
|
-
/** Whether another page is available. */
|
|
54
|
-
exceededTransferLimit?: boolean;
|
|
55
|
-
/** Original response metadata for advanced consumers. */
|
|
56
|
-
rawMetadata?: unknown;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/** Error raised when a SceneServer query cannot be completed or decoded. */
|
|
60
|
-
export class ArcGISSceneServerQueryError extends Error {
|
|
61
|
-
/** HTTP status code, when the failure came from a response. */
|
|
62
|
-
readonly status?: number;
|
|
63
|
-
|
|
64
|
-
/** Creates a typed SceneServer query error. */
|
|
65
|
-
constructor(message: string, status?: number) {
|
|
66
|
-
super(message);
|
|
67
|
-
this.name = 'ArcGISSceneServerQueryError';
|
|
68
|
-
this.status = status;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Options for an ArcGIS SceneServer source. */
|
|
73
|
-
export type ArcGISSceneServerSourceOptions = DataSourceOptions & {
|
|
74
|
-
'arcgis-scene-server'?: {
|
|
75
|
-
/** Layer identifier used when the input URL ends at `/SceneServer`. */
|
|
76
|
-
layerId?: number | string;
|
|
77
|
-
/** ArcGIS token applied to metadata and tile-resource requests. */
|
|
78
|
-
token?: string;
|
|
79
|
-
/** Optional metadata document for offline or preloaded use. */
|
|
80
|
-
metadata?: unknown;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/** Source facade for an ArcGIS SceneServer I3S layer. */
|
|
85
|
-
export class ArcGISSceneServerSource extends DataSource<string, ArcGISSceneServerSourceOptions> {
|
|
86
|
-
/** Cached normalized layer metadata. */
|
|
87
|
-
private metadataPromise: Promise<I3SServiceMetadata> | null = null;
|
|
88
|
-
/** Cached profile-specific tileset source. */
|
|
89
|
-
private sourcePromise: Promise<I3SLayerSource> | null = null;
|
|
90
|
-
|
|
91
|
-
/** Creates a SceneServer source. */
|
|
92
|
-
constructor(url: string, options: ArcGISSceneServerSourceOptions = {}, coreApi?: CoreAPI) {
|
|
93
|
-
super(url.replace(/\/+$/, ''), options, ArcGISSceneServerSourceLoader.defaultOptions, coreApi);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Returns normalized SceneServer layer metadata. */
|
|
97
|
-
async getMetadata(): Promise<I3SServiceMetadata> {
|
|
98
|
-
this.metadataPromise ||= this.loadMetadata();
|
|
99
|
-
return await this.metadataPromise;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** Creates the existing mesh or Point Cloud source for this layer. */
|
|
103
|
-
async getTilesetSource(): Promise<I3SLayerSource> {
|
|
104
|
-
this.sourcePromise ||= this.createTilesetSource();
|
|
105
|
-
return await this.sourcePromise;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** Queries feature attributes and geometry from a SceneServer layer. */
|
|
109
|
-
async query(options: ArcGISSceneQueryOptions = {}): Promise<ArcGISSceneQueryResult> {
|
|
110
|
-
const {signal, f = 'json', ...queryParameters} = options;
|
|
111
|
-
const queryURL = buildArcGISResourceURL(this.getLayerURL(), 'query', {
|
|
112
|
-
where: '1=1',
|
|
113
|
-
outFields: '*',
|
|
114
|
-
returnGeometry: true,
|
|
115
|
-
f,
|
|
116
|
-
...queryParameters,
|
|
117
|
-
token: this.getToken()
|
|
118
|
-
});
|
|
119
|
-
const response = await this.fetch(queryURL, signal ? {signal} : undefined);
|
|
120
|
-
if (!response.ok) {
|
|
121
|
-
throw new ArcGISSceneServerQueryError(
|
|
122
|
-
`ArcGIS SceneServer query failed: ${response.status} ${response.statusText}`,
|
|
123
|
-
response.status
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
const document = (await response.json()) as Record<string, unknown>;
|
|
127
|
-
if (document.error) {
|
|
128
|
-
throw new ArcGISSceneServerQueryError(
|
|
129
|
-
`ArcGIS SceneServer query returned an error: ${JSON.stringify(document.error)}`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
features: Array.isArray(document.features) ? document.features : [],
|
|
134
|
-
fields: Array.isArray(document.fields) ? document.fields : undefined,
|
|
135
|
-
exceededTransferLimit:
|
|
136
|
-
typeof document.exceededTransferLimit === 'boolean'
|
|
137
|
-
? document.exceededTransferLimit
|
|
138
|
-
: undefined,
|
|
139
|
-
rawMetadata: document
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** Alias for query used by applications that consume generic feature sources. */
|
|
144
|
-
async getFeatures(options: ArcGISSceneQueryOptions = {}): Promise<ArcGISSceneQueryResult> {
|
|
145
|
-
return await this.query(options);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** Returns the layer URL, resolving an explicit layer ID when needed. */
|
|
149
|
-
getLayerURL(): string {
|
|
150
|
-
const url = new URL(this.url);
|
|
151
|
-
url.pathname = url.pathname.replace(/\/+$/, '');
|
|
152
|
-
if (/\/SceneServer\/layers\/[^/]+$/i.test(url.pathname)) {
|
|
153
|
-
url.search = '';
|
|
154
|
-
url.hash = '';
|
|
155
|
-
return url.toString();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (!/\/SceneServer$/i.test(url.pathname)) {
|
|
159
|
-
throw new Error(
|
|
160
|
-
'ArcGISSceneServerSource requires a /SceneServer/layers/{id} URL or a /SceneServer URL with arcgis-scene-server.layerId'
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const layerId = this.options['arcgis-scene-server']?.layerId;
|
|
165
|
-
if (layerId === undefined) {
|
|
166
|
-
throw new Error(
|
|
167
|
-
'ArcGISSceneServerSource requires a /SceneServer/layers/{id} URL or a /SceneServer URL with arcgis-scene-server.layerId'
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
url.pathname = `${url.pathname.replace(/\/$/, '')}/layers/${encodeURIComponent(String(layerId))}`;
|
|
171
|
-
url.search = '';
|
|
172
|
-
url.hash = '';
|
|
173
|
-
return url.toString();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** Returns the metadata request URL with ArcGIS JSON and authentication parameters. */
|
|
177
|
-
metadataURL(): string {
|
|
178
|
-
const url = new URL(this.getLayerURL());
|
|
179
|
-
url.searchParams.set('f', 'pjson');
|
|
180
|
-
const token = this.getToken();
|
|
181
|
-
if (token && !url.searchParams.has('token')) {
|
|
182
|
-
url.searchParams.set('token', token);
|
|
183
|
-
}
|
|
184
|
-
return url.toString();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
private async loadMetadata(): Promise<I3SServiceMetadata> {
|
|
188
|
-
const configuredMetadata = this.options['arcgis-scene-server']?.metadata;
|
|
189
|
-
const layer = configuredMetadata
|
|
190
|
-
? parseI3SSceneLayerMetadata(configuredMetadata)
|
|
191
|
-
: await this.fetchLayerMetadata();
|
|
192
|
-
return normalizeI3SServiceMetadata(this.getLayerURL(), layer);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
private async fetchLayerMetadata(): Promise<SceneLayer3D> {
|
|
196
|
-
const response = await this.fetch(this.metadataURL());
|
|
197
|
-
if (!response.ok) {
|
|
198
|
-
throw new Error(
|
|
199
|
-
`ArcGIS SceneServer metadata request failed: ${response.status} ${response.statusText}`
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
return parseI3SSceneLayerMetadata(await response.json());
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
private async createTilesetSource(): Promise<I3SLayerSource> {
|
|
206
|
-
const metadata = await this.getMetadata();
|
|
207
|
-
return createI3SLayerSource(
|
|
208
|
-
metadata.url,
|
|
209
|
-
metadata.layer,
|
|
210
|
-
this.getSourceOptions(),
|
|
211
|
-
this.coreApi
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private getSourceOptions(): DataSourceOptions {
|
|
216
|
-
const i3sOptions = (this.options['i3s'] as Record<string, unknown> | undefined) || {};
|
|
217
|
-
const token = this.getToken();
|
|
218
|
-
return {
|
|
219
|
-
...this.options,
|
|
220
|
-
i3s: token ? {...i3sOptions, token} : i3sOptions
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
private getToken(): string | undefined {
|
|
225
|
-
const serviceToken = this.options['arcgis-scene-server']?.token;
|
|
226
|
-
const i3sToken = (this.options['i3s'] as Record<string, unknown> | undefined)?.token;
|
|
227
|
-
if (serviceToken) {
|
|
228
|
-
return serviceToken;
|
|
229
|
-
}
|
|
230
|
-
if (typeof i3sToken === 'string' && i3sToken) {
|
|
231
|
-
return i3sToken;
|
|
232
|
-
}
|
|
233
|
-
return new URL(this.url).searchParams.get('token') || undefined;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/** Source loader for ArcGIS SceneServer I3S layers. */
|
|
238
|
-
export const ArcGISSceneServerSourceLoader = {
|
|
239
|
-
dataType: null as unknown as ArcGISSceneServerSource,
|
|
240
|
-
batchType: null as never,
|
|
241
|
-
name: 'ArcGIS SceneServer',
|
|
242
|
-
id: 'arcgis-scene-server',
|
|
243
|
-
module: 'services',
|
|
244
|
-
version: '0.0.0',
|
|
245
|
-
extensions: [],
|
|
246
|
-
mimeTypes: ['application/json'],
|
|
247
|
-
type: 'arcgis-scene-server',
|
|
248
|
-
fromUrl: true,
|
|
249
|
-
fromBlob: false,
|
|
250
|
-
options: {'arcgis-scene-server': {}},
|
|
251
|
-
defaultOptions: {'arcgis-scene-server': {}},
|
|
252
|
-
testURL: (url: string): boolean => /\/SceneServer(?:[\/?#]|$)/i.test(url),
|
|
253
|
-
createDataSource: (
|
|
254
|
-
url: string,
|
|
255
|
-
options: ArcGISSceneServerSourceOptions = {},
|
|
256
|
-
coreApi?: CoreAPI
|
|
257
|
-
) => new ArcGISSceneServerSource(url, options, coreApi)
|
|
258
|
-
} as const satisfies SourceLoader<ArcGISSceneServerSource>;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
export type Service = {name: string; type: string; url: string};
|
|
6
|
-
|
|
7
|
-
type FetchLike = typeof fetch;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* (Recursively) load the service directory from an ArcGIS Server URL
|
|
11
|
-
* @param url
|
|
12
|
-
* @param fetchFile= Optional fetch function override
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export async function getArcGISServices(
|
|
16
|
-
url: string,
|
|
17
|
-
fetchFile: FetchLike = fetch
|
|
18
|
-
): Promise<Service[] | null> {
|
|
19
|
-
if (url.includes('rest/services')) {
|
|
20
|
-
const serverUrl = url.replace(/rest\/services.*$/i, 'rest/services');
|
|
21
|
-
return loadServiceDirectory(serverUrl, fetchFile, []);
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function loadServiceDirectory(
|
|
27
|
-
serverUrl: string,
|
|
28
|
-
fetch: FetchLike,
|
|
29
|
-
path: string[]
|
|
30
|
-
): Promise<Service[]> {
|
|
31
|
-
const serviceUrl = path.length ? `${serverUrl}/${path.join('/')}` : serverUrl;
|
|
32
|
-
|
|
33
|
-
const response = await fetch(`${serviceUrl}?f=pjson`);
|
|
34
|
-
const directory = await response.json();
|
|
35
|
-
|
|
36
|
-
const services = extractServices(directory, serviceUrl, serverUrl);
|
|
37
|
-
|
|
38
|
-
const folders = (directory.folders || []) as string[];
|
|
39
|
-
const promises = folders.map(folder =>
|
|
40
|
-
loadServiceDirectory(`${serverUrl}`, fetch, [...path, folder])
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
for (const folderServices of await Promise.all(promises)) {
|
|
44
|
-
services.push(...folderServices);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return services;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function extractServices(directory: unknown, url: string, serverUrl: string): Service[] {
|
|
51
|
-
const arcgisServices = ((directory as any).services || []) as {name: string; type: string}[];
|
|
52
|
-
const services: Service[] = [];
|
|
53
|
-
for (const service of arcgisServices) {
|
|
54
|
-
services.push({
|
|
55
|
-
name: service.name,
|
|
56
|
-
type: `arcgis-${service.type.toLocaleLowerCase().replace('server', '-server')}`,
|
|
57
|
-
url: `${service.name.includes('/') ? serverUrl : url}/${service.name}/${service.type}`
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return services;
|
|
61
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
/** Builds an ArcGIS REST resource URL while preserving authentication query parameters. */
|
|
6
|
-
export function buildArcGISResourceURL(
|
|
7
|
-
serviceURL: string,
|
|
8
|
-
resourcePath: string,
|
|
9
|
-
parameters: Record<string, unknown>
|
|
10
|
-
): string {
|
|
11
|
-
const url = new URL(serviceURL);
|
|
12
|
-
if (resourcePath) {
|
|
13
|
-
url.pathname = `${url.pathname.replace(/\/$/, '')}/${resourcePath.replace(/^\//, '')}`;
|
|
14
|
-
}
|
|
15
|
-
for (const [key, value] of Object.entries(parameters)) {
|
|
16
|
-
if (value === undefined || value === null) continue;
|
|
17
|
-
url.searchParams.set(key, encodeArcGISParameter(value));
|
|
18
|
-
}
|
|
19
|
-
return url.toString();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Converts a generic request value to ArcGIS REST query syntax. */
|
|
23
|
-
function encodeArcGISParameter(value: unknown): string {
|
|
24
|
-
if (Array.isArray(value)) return value.join(',');
|
|
25
|
-
return typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
26
|
-
}
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
CoreAPI,
|
|
7
|
-
DataSourceOptions,
|
|
8
|
-
GetTileDataParameters,
|
|
9
|
-
GetTileParameters,
|
|
10
|
-
SourceLoader,
|
|
11
|
-
TileSourceMetadata,
|
|
12
|
-
VectorTile,
|
|
13
|
-
VectorTileSource
|
|
14
|
-
} from '@loaders.gl/loader-utils';
|
|
15
|
-
import {DataSource} from '@loaders.gl/loader-utils';
|
|
16
|
-
import {MVTLoader, type MVTLoaderOptions} from '@loaders.gl/mvt';
|
|
17
|
-
import type {Schema} from '@loaders.gl/schema';
|
|
18
|
-
|
|
19
|
-
/** ArcGIS vector tile service metadata. */
|
|
20
|
-
export type ArcGISVectorTileServiceMetadata = {
|
|
21
|
-
/** Human-readable service description. */
|
|
22
|
-
serviceDescription?: string;
|
|
23
|
-
/** Map name exposed by the service. */
|
|
24
|
-
mapName?: string;
|
|
25
|
-
/** Tile grid information. */
|
|
26
|
-
tileInfo?: {
|
|
27
|
-
/** Tile width in pixels. */
|
|
28
|
-
cols?: number;
|
|
29
|
-
/** Tile height in pixels. */
|
|
30
|
-
rows?: number;
|
|
31
|
-
/** Tile format, normally pbf. */
|
|
32
|
-
format?: string;
|
|
33
|
-
/** Tile origin. */
|
|
34
|
-
origin?: {x: number; y: number};
|
|
35
|
-
/** Tile grid spatial reference. */
|
|
36
|
-
spatialReference?: {wkid?: number; latestWkid?: number};
|
|
37
|
-
/** Levels of detail. */
|
|
38
|
-
lods?: Array<{level: number; resolution: number; scale?: number}>;
|
|
39
|
-
};
|
|
40
|
-
/** Full service extent. */
|
|
41
|
-
fullExtent?: {xmin: number; ymin: number; xmax: number; ymax: number};
|
|
42
|
-
/** Initial service extent. */
|
|
43
|
-
initialExtent?: {xmin: number; ymin: number; xmax: number; ymax: number};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/** Options for the ArcGIS VectorTileServer source. */
|
|
47
|
-
export type ArcGISVectorTileServerSourceLoaderOptions = DataSourceOptions & {
|
|
48
|
-
'arcgis-vector-tile-server'?: {
|
|
49
|
-
/** Optional MVT parser options. */
|
|
50
|
-
mvt?: MVTLoaderOptions['mvt'];
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/** A source for ArcGIS VectorTileServer metadata and PBF tiles. */
|
|
55
|
-
export class ArcGISVectorTileServerSource
|
|
56
|
-
extends DataSource<string, ArcGISVectorTileServerSourceLoaderOptions>
|
|
57
|
-
implements VectorTileSource
|
|
58
|
-
{
|
|
59
|
-
/** Decoded tile family consumed by generic tile renderers. */
|
|
60
|
-
readonly mimeType = 'application/vnd.mapbox-vector-tile';
|
|
61
|
-
/** ArcGIS tiles are decoded to WGS84 coordinates before rendering. */
|
|
62
|
-
readonly localCoordinates = false;
|
|
63
|
-
/** Cached service metadata request. */
|
|
64
|
-
private serviceMetadata: Promise<ArcGISVectorTileServiceMetadata> | null = null;
|
|
65
|
-
/** Query parameters supplied with the service URL, such as an access token. */
|
|
66
|
-
private readonly serviceQueryParameters: URLSearchParams;
|
|
67
|
-
|
|
68
|
-
/** Creates an ArcGIS VectorTileServer source. */
|
|
69
|
-
constructor(
|
|
70
|
-
url: string,
|
|
71
|
-
options: ArcGISVectorTileServerSourceLoaderOptions = {},
|
|
72
|
-
coreApi?: CoreAPI
|
|
73
|
-
) {
|
|
74
|
-
const serviceURL = new URL(url);
|
|
75
|
-
serviceURL.pathname = serviceURL.pathname.replace(/\/$/, '');
|
|
76
|
-
super(
|
|
77
|
-
`${serviceURL.origin}${serviceURL.pathname}`,
|
|
78
|
-
options,
|
|
79
|
-
ArcGISVectorTileServerSourceLoader.defaultOptions,
|
|
80
|
-
coreApi
|
|
81
|
-
);
|
|
82
|
-
this.serviceQueryParameters = new URLSearchParams(serviceURL.search);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Returns normalized service and tile-grid metadata. */
|
|
86
|
-
async getMetadata(): Promise<TileSourceMetadata> {
|
|
87
|
-
const metadata = await this.getServiceMetadata();
|
|
88
|
-
const tileInfo = metadata.tileInfo;
|
|
89
|
-
const lods = tileInfo?.lods || [];
|
|
90
|
-
const extent = metadata.fullExtent || metadata.initialExtent;
|
|
91
|
-
return {
|
|
92
|
-
name: metadata.mapName || this.url.split('/').pop() || '',
|
|
93
|
-
title: metadata.mapName,
|
|
94
|
-
abstract: metadata.serviceDescription,
|
|
95
|
-
format: 'application/vnd.mapbox-vector-tile',
|
|
96
|
-
minZoom: lods[0]?.level,
|
|
97
|
-
maxZoom: lods.at(-1)?.level,
|
|
98
|
-
boundingBox: extent
|
|
99
|
-
? [
|
|
100
|
-
[extent.xmin, extent.ymin],
|
|
101
|
-
[extent.xmax, extent.ymax]
|
|
102
|
-
]
|
|
103
|
-
: undefined,
|
|
104
|
-
layer: {
|
|
105
|
-
name: metadata.mapName || '',
|
|
106
|
-
srs: tileInfo?.spatialReference ? [getSpatialReference(tileInfo.spatialReference)] : [],
|
|
107
|
-
layers: []
|
|
108
|
-
},
|
|
109
|
-
formatHeader: {
|
|
110
|
-
tileInfo,
|
|
111
|
-
styleURL: this.getStyleURL(),
|
|
112
|
-
spriteURL: this.getSpriteURL()
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Fetches one raw PBF tile from the ArcGIS tile endpoint. */
|
|
118
|
-
async getTile(parameters: GetTileParameters, signal?: AbortSignal): Promise<ArrayBuffer | null> {
|
|
119
|
-
const response = await this.fetch(this.getTileURL(parameters), {
|
|
120
|
-
signal,
|
|
121
|
-
headers: {Accept: 'application/vnd.mapbox-vector-tile, application/x-protobuf'}
|
|
122
|
-
});
|
|
123
|
-
if (!response.ok) return null;
|
|
124
|
-
return response.arrayBuffer();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** Returns the schema advertised by decoded vector tiles. */
|
|
128
|
-
async getSchema(): Promise<Schema> {
|
|
129
|
-
return {fields: [], metadata: {}};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** Fetches and decodes one ArcGIS vector tile to geographic coordinates. */
|
|
133
|
-
async getVectorTile(parameters: GetTileParameters): Promise<VectorTile | null> {
|
|
134
|
-
const arrayBuffer = await this.getTile(parameters, parameters.signal);
|
|
135
|
-
if (!arrayBuffer) {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
const inheritedOptions = (this.loadOptions as MVTLoaderOptions).mvt;
|
|
139
|
-
const sourceOptions = this.options['arcgis-vector-tile-server']?.mvt;
|
|
140
|
-
return (await this.coreApi.parse(arrayBuffer, MVTLoader, {
|
|
141
|
-
...this.loadOptions,
|
|
142
|
-
mvt: {
|
|
143
|
-
...inheritedOptions,
|
|
144
|
-
...sourceOptions,
|
|
145
|
-
coordinates: 'wgs84',
|
|
146
|
-
tileIndex: {x: parameters.x, y: parameters.y, z: parameters.z},
|
|
147
|
-
layers:
|
|
148
|
-
normalizeLayers(parameters.layers) || sourceOptions?.layers || inheritedOptions?.layers
|
|
149
|
-
}
|
|
150
|
-
})) as VectorTile;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/** Provides decoded vector tiles through the deck.gl source interface. */
|
|
154
|
-
async getTileData(parameters: GetTileDataParameters): Promise<VectorTile | null> {
|
|
155
|
-
return this.getVectorTile({...parameters.index, signal: parameters.signal});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** Builds the ArcGIS cached vector tile URL. */
|
|
159
|
-
getTileURL(parameters: GetTileParameters): string {
|
|
160
|
-
return this.getResourceURL(`/tile/${parameters.z}/${parameters.y}/${parameters.x}.pbf`);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** Returns the service metadata URL. */
|
|
164
|
-
getMetadataURL(): string {
|
|
165
|
-
const url = new URL(this.getResourceURL(''));
|
|
166
|
-
url.searchParams.set('f', 'pjson');
|
|
167
|
-
return url.toString();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** Returns the ArcGIS Mapbox style resource URL. */
|
|
171
|
-
getStyleURL(): string {
|
|
172
|
-
return this.getResourceURL('/resources/styles/root.json');
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** Returns the ArcGIS sprite resource base URL. */
|
|
176
|
-
getSpriteURL(): string {
|
|
177
|
-
return this.getResourceURL('/resources/sprites/sprite');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/** Loads and caches the ArcGIS VectorTileServer metadata document. */
|
|
181
|
-
private async getServiceMetadata(): Promise<ArcGISVectorTileServiceMetadata> {
|
|
182
|
-
this.serviceMetadata ||= this.fetch(this.getMetadataURL()).then(async response => {
|
|
183
|
-
if (!response.ok)
|
|
184
|
-
throw new Error(`ArcGIS VectorTileServer request failed: ${response.status}`);
|
|
185
|
-
return (await response.json()) as ArcGISVectorTileServiceMetadata;
|
|
186
|
-
});
|
|
187
|
-
return this.serviceMetadata;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** Builds a resource URL while retaining service query parameters. */
|
|
191
|
-
private getResourceURL(resourcePath: string): string {
|
|
192
|
-
const url = new URL(this.url);
|
|
193
|
-
url.pathname = `${url.pathname.replace(/\/$/, '')}${resourcePath}`;
|
|
194
|
-
for (const [key, value] of this.serviceQueryParameters) {
|
|
195
|
-
url.searchParams.set(key, value);
|
|
196
|
-
}
|
|
197
|
-
return url.toString();
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/** Source loader for ArcGIS VectorTileServer services. */
|
|
202
|
-
export const ArcGISVectorTileServerSourceLoader = {
|
|
203
|
-
dataType: null as unknown as ArcGISVectorTileServerSource,
|
|
204
|
-
batchType: null as never,
|
|
205
|
-
name: 'ArcGIS VectorTileServer',
|
|
206
|
-
id: 'arcgis-vector-tile-server',
|
|
207
|
-
module: 'services',
|
|
208
|
-
version: '0.0.0',
|
|
209
|
-
extensions: [],
|
|
210
|
-
mimeTypes: ['application/vnd.mapbox-vector-tile', 'application/x-protobuf'],
|
|
211
|
-
type: 'arcgis-vector-tile-server',
|
|
212
|
-
fromUrl: true,
|
|
213
|
-
fromBlob: false,
|
|
214
|
-
options: {'arcgis-vector-tile-server': {}},
|
|
215
|
-
defaultOptions: {'arcgis-vector-tile-server': {}},
|
|
216
|
-
testURL: (url: string): boolean => /\/vectortileserver(?:[\/?#]|$)/i.test(url),
|
|
217
|
-
createDataSource: (
|
|
218
|
-
url: string,
|
|
219
|
-
options: ArcGISVectorTileServerSourceLoaderOptions = {},
|
|
220
|
-
coreApi?: CoreAPI
|
|
221
|
-
) => new ArcGISVectorTileServerSource(url, options, coreApi)
|
|
222
|
-
} as const satisfies SourceLoader<ArcGISVectorTileServerSource>;
|
|
223
|
-
|
|
224
|
-
/** Converts an ArcGIS spatial reference to an EPSG identifier. */
|
|
225
|
-
function getSpatialReference(spatialReference: {wkid?: number; latestWkid?: number}): string {
|
|
226
|
-
return `EPSG:${spatialReference.latestWkid || spatialReference.wkid}`;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/** Normalizes generic tile layer selection for the MVT parser. */
|
|
230
|
-
function normalizeLayers(layers?: string | string[]): string[] | undefined {
|
|
231
|
-
if (!layers) return undefined;
|
|
232
|
-
return Array.isArray(layers) ? layers : [layers];
|
|
233
|
-
}
|
package/src/service-registry.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {ArcGISFeatureServerSourceLoader} from './arcgis/arcgis-feature-server-source-loader';
|
|
6
|
-
import {ArcGISImageServerSourceLoader} from './arcgis/arcgis-image-server-source-loader';
|
|
7
|
-
import {ArcGISImageTileSourceLoader} from './arcgis/arcgis-image-tile-source-loader';
|
|
8
|
-
import {ArcGISMapTileSourceLoader} from './arcgis/arcgis-map-tile-source-loader';
|
|
9
|
-
import {ArcGISSceneServerSourceLoader} from './arcgis/arcgis-scene-server-source-loader';
|
|
10
|
-
import {ArcGISVectorTileServerSourceLoader} from './arcgis/arcgis-vector-tile-server-source-loader';
|
|
11
|
-
|
|
12
|
-
/** A source loader currently exposed through the services package. */
|
|
13
|
-
export type ServiceLoader =
|
|
14
|
-
| typeof ArcGISFeatureServerSourceLoader
|
|
15
|
-
| typeof ArcGISImageServerSourceLoader
|
|
16
|
-
| typeof ArcGISImageTileSourceLoader
|
|
17
|
-
| typeof ArcGISMapTileSourceLoader
|
|
18
|
-
| typeof ArcGISVectorTileServerSourceLoader
|
|
19
|
-
| typeof ArcGISSceneServerSourceLoader;
|
|
20
|
-
|
|
21
|
-
/** All source loaders owned by `@loaders.gl/services`, in URL-selection order. */
|
|
22
|
-
export const SERVICE_LOADERS: ServiceLoader[] = [
|
|
23
|
-
ArcGISFeatureServerSourceLoader,
|
|
24
|
-
ArcGISImageServerSourceLoader,
|
|
25
|
-
ArcGISImageTileSourceLoader,
|
|
26
|
-
ArcGISMapTileSourceLoader,
|
|
27
|
-
ArcGISVectorTileServerSourceLoader,
|
|
28
|
-
ArcGISSceneServerSourceLoader
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Finds a service loader by its canonical loader id or service type.
|
|
33
|
-
*
|
|
34
|
-
* The lookup is intentionally small and explicit. It provides discovery without
|
|
35
|
-
* introducing a second request lifecycle or hiding provider-specific options.
|
|
36
|
-
*/
|
|
37
|
-
export function getServiceLoader(serviceType: string): ServiceLoader | undefined {
|
|
38
|
-
const normalizedServiceType = serviceType.toLowerCase();
|
|
39
|
-
return SERVICE_LOADERS.find(
|
|
40
|
-
serviceLoader =>
|
|
41
|
-
serviceLoader.id === normalizedServiceType || serviceLoader.type === normalizedServiceType
|
|
42
|
-
);
|
|
43
|
-
}
|