@classic-homes/maps-core 0.1.1
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 +281 -0
- package/dist/chunk-2NISJ7WE.js +534 -0
- package/dist/data-DDS6ok7I.d.cts +141 -0
- package/dist/data-DDS6ok7I.d.ts +141 -0
- package/dist/index.cjs +3284 -0
- package/dist/index.d.cts +1247 -0
- package/dist/index.d.ts +1247 -0
- package/dist/index.js +2638 -0
- package/dist/spatial-J48Btm8f.d.cts +435 -0
- package/dist/spatial-VV-zd88V.d.ts +435 -0
- package/dist/theme/index.cjs +552 -0
- package/dist/theme/index.d.cts +188 -0
- package/dist/theme/index.d.ts +188 -0
- package/dist/theme/index.js +1 -0
- package/dist/types/index.cjs +2 -0
- package/dist/types/index.d.cts +758 -0
- package/dist/types/index.d.ts +758 -0
- package/dist/types/index.js +1 -0
- package/dist/workers/index.cjs +390 -0
- package/dist/workers/index.d.cts +372 -0
- package/dist/workers/index.d.ts +372 -0
- package/dist/workers/index.js +387 -0
- package/dist/workers/spatial.worker.js +1138 -0
- package/package.json +77 -0
- package/src/styles/controls.css +212 -0
- package/src/styles/popup.css +224 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { G as GeoJSONFeatureCollection, B as BoundsArray } from '../data-DDS6ok7I.js';
|
|
2
|
+
import { Q as QueryStats, P as PanVelocity, R as RTreeQueryStats } from '../spatial-VV-zd88V.js';
|
|
3
|
+
import 'rbush';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SpatialWorkerClient
|
|
7
|
+
*
|
|
8
|
+
* A clean, type-safe API for interacting with the spatial worker.
|
|
9
|
+
* Handles worker lifecycle, request tracking, and graceful degradation.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Worker factory function type
|
|
14
|
+
*/
|
|
15
|
+
type WorkerFactory = () => Worker;
|
|
16
|
+
/**
|
|
17
|
+
* Options for creating a SpatialWorkerClient
|
|
18
|
+
*/
|
|
19
|
+
interface SpatialWorkerClientOptions {
|
|
20
|
+
/** Timeout for requests in ms. Default: 30000 */
|
|
21
|
+
requestTimeout?: number;
|
|
22
|
+
/** Whether to use R-tree (true) or grid index (false). Default: true */
|
|
23
|
+
useRTree?: boolean;
|
|
24
|
+
/** Target cells for grid index. Default: 1024 */
|
|
25
|
+
gridTargetCells?: number;
|
|
26
|
+
/** Max entries per R-tree node. Default: 9 */
|
|
27
|
+
rtreeMaxEntries?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Worker factory function or Worker URL.
|
|
30
|
+
* Required for the client to create the worker.
|
|
31
|
+
*
|
|
32
|
+
* @example Vite
|
|
33
|
+
* ```ts
|
|
34
|
+
* import SpatialWorker from '@classic-homes/maps-core/workers/spatial.worker?worker';
|
|
35
|
+
* const client = createSpatialWorkerClient({
|
|
36
|
+
* workerFactory: () => new SpatialWorker(),
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Webpack
|
|
41
|
+
* ```ts
|
|
42
|
+
* const client = createSpatialWorkerClient({
|
|
43
|
+
* workerFactory: () => new Worker(
|
|
44
|
+
* new URL('@classic-homes/maps-core/workers/spatial.worker', import.meta.url)
|
|
45
|
+
* ),
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
workerFactory?: WorkerFactory;
|
|
50
|
+
/**
|
|
51
|
+
* URL to the worker script. Alternative to workerFactory.
|
|
52
|
+
*/
|
|
53
|
+
workerUrl?: string | URL;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Result of initializing the worker
|
|
57
|
+
*/
|
|
58
|
+
interface WorkerInitResult {
|
|
59
|
+
success: boolean;
|
|
60
|
+
featureCount: number;
|
|
61
|
+
indexType: 'rtree' | 'grid';
|
|
62
|
+
buildTimeMs: number;
|
|
63
|
+
error?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Result of a viewport query
|
|
67
|
+
*/
|
|
68
|
+
interface WorkerQueryResult {
|
|
69
|
+
success: boolean;
|
|
70
|
+
data: GeoJSONFeatureCollection;
|
|
71
|
+
stats: QueryStats;
|
|
72
|
+
queryTimeMs: number;
|
|
73
|
+
error?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Result of a predictive query
|
|
77
|
+
*/
|
|
78
|
+
interface WorkerPredictiveQueryResult extends WorkerQueryResult {
|
|
79
|
+
velocity: PanVelocity;
|
|
80
|
+
updated: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Client for interacting with the spatial worker
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* // Create client
|
|
88
|
+
* const client = new SpatialWorkerClient({ useRTree: true });
|
|
89
|
+
*
|
|
90
|
+
* // Initialize with data
|
|
91
|
+
* await client.initialize(geojsonData);
|
|
92
|
+
*
|
|
93
|
+
* // Query viewport
|
|
94
|
+
* const result = await client.query(viewportBounds);
|
|
95
|
+
* if (result.success) {
|
|
96
|
+
* console.log(`Found ${result.data.features.length} features`);
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* // Use predictive queries for smooth panning
|
|
100
|
+
* const predictiveResult = await client.queryPredictive(bounds);
|
|
101
|
+
*
|
|
102
|
+
* // Cleanup when done
|
|
103
|
+
* client.terminate();
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare class SpatialWorkerClient {
|
|
107
|
+
private worker;
|
|
108
|
+
private pendingRequests;
|
|
109
|
+
private requestCounter;
|
|
110
|
+
private options;
|
|
111
|
+
private initialized;
|
|
112
|
+
private ready;
|
|
113
|
+
private readyPromise;
|
|
114
|
+
private readyResolve;
|
|
115
|
+
constructor(options?: SpatialWorkerClientOptions);
|
|
116
|
+
/**
|
|
117
|
+
* Check if Web Workers are supported
|
|
118
|
+
*/
|
|
119
|
+
static isSupported(): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Create the worker instance
|
|
122
|
+
*/
|
|
123
|
+
private createWorker;
|
|
124
|
+
/**
|
|
125
|
+
* Set the worker instance manually
|
|
126
|
+
*
|
|
127
|
+
* Use this when you need to create the worker yourself,
|
|
128
|
+
* or when using a bundler-specific worker import.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import SpatialWorker from './spatial.worker?worker';
|
|
133
|
+
* const client = new SpatialWorkerClient();
|
|
134
|
+
* client.setWorker(new SpatialWorker());
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
setWorker(worker: Worker): void;
|
|
138
|
+
/**
|
|
139
|
+
* Handle messages from the worker
|
|
140
|
+
*/
|
|
141
|
+
private handleMessage;
|
|
142
|
+
/**
|
|
143
|
+
* Handle worker errors
|
|
144
|
+
*/
|
|
145
|
+
private handleError;
|
|
146
|
+
/**
|
|
147
|
+
* Generate a unique request ID
|
|
148
|
+
*/
|
|
149
|
+
private generateRequestId;
|
|
150
|
+
/**
|
|
151
|
+
* Send a request to the worker and wait for response
|
|
152
|
+
*/
|
|
153
|
+
private sendRequest;
|
|
154
|
+
/**
|
|
155
|
+
* Initialize the worker with GeoJSON data
|
|
156
|
+
*
|
|
157
|
+
* @param data The GeoJSON FeatureCollection to index
|
|
158
|
+
* @returns Initialization result with build statistics
|
|
159
|
+
*/
|
|
160
|
+
initialize(data: GeoJSONFeatureCollection): Promise<WorkerInitResult>;
|
|
161
|
+
/**
|
|
162
|
+
* Query features within the given bounds
|
|
163
|
+
*
|
|
164
|
+
* @param bounds Viewport bounds [[swLng, swLat], [neLng, neLat]]
|
|
165
|
+
* @param options Query options
|
|
166
|
+
* @returns Query result with features and statistics
|
|
167
|
+
*/
|
|
168
|
+
query(bounds: BoundsArray, options?: {
|
|
169
|
+
bufferFraction?: number;
|
|
170
|
+
buffer?: number;
|
|
171
|
+
}): Promise<WorkerQueryResult>;
|
|
172
|
+
/**
|
|
173
|
+
* Query with predictive pan loading
|
|
174
|
+
*
|
|
175
|
+
* Tracks viewport movement and expands buffer in the predicted
|
|
176
|
+
* direction of panning to eliminate pop-in.
|
|
177
|
+
*
|
|
178
|
+
* @param bounds Current viewport bounds
|
|
179
|
+
* @param options Predictive query options
|
|
180
|
+
* @returns Query result with velocity info
|
|
181
|
+
*/
|
|
182
|
+
queryPredictive(bounds: BoundsArray, options?: {
|
|
183
|
+
bufferFraction?: number;
|
|
184
|
+
minMovement?: number;
|
|
185
|
+
predictiveMultiplier?: number;
|
|
186
|
+
}): Promise<WorkerPredictiveQueryResult>;
|
|
187
|
+
/**
|
|
188
|
+
* Reset predictive pan state
|
|
189
|
+
*
|
|
190
|
+
* Call this when the user stops panning or when you want
|
|
191
|
+
* to clear the velocity tracking.
|
|
192
|
+
*/
|
|
193
|
+
resetPredictive(): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Get current index statistics
|
|
196
|
+
*/
|
|
197
|
+
getStats(): Promise<{
|
|
198
|
+
featureCount: number;
|
|
199
|
+
indexType: 'rtree' | 'grid';
|
|
200
|
+
bounds: BoundsArray;
|
|
201
|
+
} | null>;
|
|
202
|
+
/**
|
|
203
|
+
* Check if the client is initialized
|
|
204
|
+
*/
|
|
205
|
+
isInitialized(): boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Check if the worker is ready
|
|
208
|
+
*/
|
|
209
|
+
isReady(): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Terminate the worker and clean up resources
|
|
212
|
+
*/
|
|
213
|
+
terminate(): void;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Create a spatial worker client
|
|
217
|
+
*
|
|
218
|
+
* Factory function for creating SpatialWorkerClient instances.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* const client = createSpatialWorkerClient({ useRTree: true });
|
|
223
|
+
* await client.initialize(data);
|
|
224
|
+
* const result = await client.query(bounds);
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
declare function createSpatialWorkerClient(options?: SpatialWorkerClientOptions): SpatialWorkerClient;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Type definitions for spatial worker communication
|
|
231
|
+
*
|
|
232
|
+
* Uses discriminated unions for type-safe message handling
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Initialize the worker with GeoJSON data
|
|
237
|
+
*/
|
|
238
|
+
interface InitializeRequest {
|
|
239
|
+
type: 'initialize';
|
|
240
|
+
requestId: string;
|
|
241
|
+
data: GeoJSONFeatureCollection;
|
|
242
|
+
options?: {
|
|
243
|
+
/** Use R-tree (true) or grid index (false). Default: true */
|
|
244
|
+
useRTree?: boolean;
|
|
245
|
+
/** Target cells for grid index. Default: 1024 */
|
|
246
|
+
gridTargetCells?: number;
|
|
247
|
+
/** Max entries per R-tree node. Default: 9 */
|
|
248
|
+
rtreeMaxEntries?: number;
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Query features within bounds
|
|
253
|
+
*/
|
|
254
|
+
interface QueryRequest {
|
|
255
|
+
type: 'query';
|
|
256
|
+
requestId: string;
|
|
257
|
+
bounds: BoundsArray;
|
|
258
|
+
options?: {
|
|
259
|
+
/** Buffer fraction of viewport. Default: 0.25 */
|
|
260
|
+
bufferFraction?: number;
|
|
261
|
+
/** Fixed buffer in degrees */
|
|
262
|
+
buffer?: number;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Query with predictive pan loading
|
|
267
|
+
*/
|
|
268
|
+
interface PredictiveQueryRequest {
|
|
269
|
+
type: 'predictive-query';
|
|
270
|
+
requestId: string;
|
|
271
|
+
bounds: BoundsArray;
|
|
272
|
+
timestamp: number;
|
|
273
|
+
options?: {
|
|
274
|
+
/** Buffer fraction of viewport. Default: 0.25 */
|
|
275
|
+
bufferFraction?: number;
|
|
276
|
+
/** Minimum movement before updating. Default: 0.1 */
|
|
277
|
+
minMovement?: number;
|
|
278
|
+
/** Predictive buffer multiplier. Default: 2.0 */
|
|
279
|
+
predictiveMultiplier?: number;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Reset the predictive manager state
|
|
284
|
+
*/
|
|
285
|
+
interface ResetPredictiveRequest {
|
|
286
|
+
type: 'reset-predictive';
|
|
287
|
+
requestId: string;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get current index statistics
|
|
291
|
+
*/
|
|
292
|
+
interface GetStatsRequest {
|
|
293
|
+
type: 'get-stats';
|
|
294
|
+
requestId: string;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Terminate the worker
|
|
298
|
+
*/
|
|
299
|
+
interface TerminateRequest {
|
|
300
|
+
type: 'terminate';
|
|
301
|
+
requestId: string;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Union of all request types
|
|
305
|
+
*/
|
|
306
|
+
type WorkerRequest = InitializeRequest | QueryRequest | PredictiveQueryRequest | ResetPredictiveRequest | GetStatsRequest | TerminateRequest;
|
|
307
|
+
/**
|
|
308
|
+
* Base response with common fields
|
|
309
|
+
*/
|
|
310
|
+
interface BaseResponse {
|
|
311
|
+
requestId: string;
|
|
312
|
+
success: boolean;
|
|
313
|
+
error?: string;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Response to initialize request
|
|
317
|
+
*/
|
|
318
|
+
interface InitializeResponse extends BaseResponse {
|
|
319
|
+
type: 'initialize';
|
|
320
|
+
stats?: {
|
|
321
|
+
featureCount: number;
|
|
322
|
+
indexType: 'rtree' | 'grid';
|
|
323
|
+
buildTimeMs: number;
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Response to query request
|
|
328
|
+
*/
|
|
329
|
+
interface QueryResponse extends BaseResponse {
|
|
330
|
+
type: 'query';
|
|
331
|
+
data?: GeoJSONFeatureCollection;
|
|
332
|
+
stats?: QueryStats | RTreeQueryStats;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Response to predictive query request
|
|
336
|
+
*/
|
|
337
|
+
interface PredictiveQueryResponse extends BaseResponse {
|
|
338
|
+
type: 'predictive-query';
|
|
339
|
+
data?: GeoJSONFeatureCollection;
|
|
340
|
+
stats?: QueryStats;
|
|
341
|
+
velocity?: PanVelocity;
|
|
342
|
+
updated: boolean;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Response to reset predictive request
|
|
346
|
+
*/
|
|
347
|
+
interface ResetPredictiveResponse extends BaseResponse {
|
|
348
|
+
type: 'reset-predictive';
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Response to get stats request
|
|
352
|
+
*/
|
|
353
|
+
interface GetStatsResponse extends BaseResponse {
|
|
354
|
+
type: 'get-stats';
|
|
355
|
+
stats?: {
|
|
356
|
+
featureCount: number;
|
|
357
|
+
indexType: 'rtree' | 'grid';
|
|
358
|
+
bounds: BoundsArray;
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Response to terminate request
|
|
363
|
+
*/
|
|
364
|
+
interface TerminateResponse extends BaseResponse {
|
|
365
|
+
type: 'terminate';
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Union of all response types
|
|
369
|
+
*/
|
|
370
|
+
type WorkerResponse = InitializeResponse | QueryResponse | PredictiveQueryResponse | ResetPredictiveResponse | GetStatsResponse | TerminateResponse;
|
|
371
|
+
|
|
372
|
+
export { type GetStatsRequest, type GetStatsResponse, type InitializeRequest, type InitializeResponse, type PredictiveQueryRequest, type PredictiveQueryResponse, type QueryRequest, type QueryResponse, type ResetPredictiveRequest, type ResetPredictiveResponse, SpatialWorkerClient, type SpatialWorkerClientOptions, type TerminateRequest, type TerminateResponse, type WorkerFactory, type WorkerInitResult, type WorkerPredictiveQueryResult, type WorkerQueryResult, type WorkerRequest, type WorkerResponse, createSpatialWorkerClient };
|