@zwishing/emap 0.1.3 → 0.3.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 (39) hide show
  1. package/CHANGELOG.md +250 -1
  2. package/FEATURES.md +455 -0
  3. package/README.md +415 -205
  4. package/dist/core/event-map.d.ts +67 -0
  5. package/dist/core/feature-event-dispatcher.d.ts +70 -0
  6. package/dist/core/handler-manager.d.ts +49 -0
  7. package/dist/core/handler.d.ts +48 -0
  8. package/dist/core/handlers/box-select.d.ts +54 -0
  9. package/dist/core/handlers/click-select.d.ts +31 -0
  10. package/dist/core/handlers/drag-pan.d.ts +28 -0
  11. package/dist/core/handlers/draw-feature.d.ts +76 -0
  12. package/dist/core/handlers/lasso-select.d.ts +57 -0
  13. package/dist/core/handlers/scroll-zoom.d.ts +24 -0
  14. package/dist/core/handlers/select-geometry.d.ts +24 -0
  15. package/dist/core/handlers/select-mode.d.ts +14 -0
  16. package/dist/core/handlers/transform-feature.d.ts +41 -0
  17. package/dist/core/handlers/vertex-edit.d.ts +98 -0
  18. package/dist/core/pointer-event-dispatcher.d.ts +40 -0
  19. package/dist/core/tween.d.ts +1 -0
  20. package/dist/emap.css +42 -8
  21. package/dist/emap.js +2 -2
  22. package/dist/emap.mjs +1 -1
  23. package/dist/geo/camera.d.ts +100 -0
  24. package/dist/geo/projection.d.ts +8 -1
  25. package/dist/geo/viewport.d.ts +18 -0
  26. package/dist/index.d.ts +26 -2
  27. package/dist/map/edit-state-store.d.ts +1 -1
  28. package/dist/map/map.d.ts +89 -2
  29. package/dist/map/selection.d.ts +5 -2
  30. package/dist/renderer/edit-overlay-renderer.d.ts +2 -1
  31. package/dist/source/source.d.ts +2 -2
  32. package/dist/source/topology-source.d.ts +33 -4
  33. package/dist/ui/box-select-control.d.ts +13 -37
  34. package/dist/ui/draw-feature-control.d.ts +6 -71
  35. package/dist/ui/lasso-select-control.d.ts +14 -61
  36. package/dist/ui/status-control.d.ts +2 -2
  37. package/dist/ui/vertex-edit-control.d.ts +5 -100
  38. package/package.json +5 -1
  39. package/dist/core/drag-pan-handler.d.ts +0 -28
package/FEATURES.md ADDED
@@ -0,0 +1,455 @@
1
+ # emap Feature Overview
2
+
3
+ This document lists the current public capabilities of `emap`. It complements
4
+ the quick-start focused [README.md](README.md).
5
+
6
+ ## 1. Runtime and Packaging
7
+
8
+ - Browser-only TypeScript library.
9
+ - Framework-agnostic: usable from vanilla HTML, React, Vue, Svelte, Angular, or
10
+ any other browser app.
11
+ - IIFE and ESM builds.
12
+ - Self-contained browser bundler path with Mapshaper supplied as package
13
+ sibling bundles.
14
+ - Optional worker bundle for off-thread dataset operations.
15
+ - Public CSS entry: `@zwishing/emap/style.css`.
16
+
17
+ ## 2. Public API Stability
18
+
19
+ Recommended stable integration surface:
20
+
21
+ - `Emap`
22
+ - `TopologySource`
23
+ - map source/layer/camera APIs
24
+ - named handlers exposed on `map.*`
25
+ - feature events and typed map events
26
+ - `map.ops.*`
27
+ - `map.features`, `map.validators`, `map.editSession`
28
+ - built-in controls
29
+ - documented types exported from the package root
30
+
31
+ Advanced but less stable surfaces:
32
+
33
+ - `HandlerManager`
34
+ - concrete handler classes
35
+ - `CanvasPainter` and `EditOverlayRenderer`
36
+ - `MapshaperAdapter` replacement hooks
37
+ - edit command classes
38
+ - raw Mapshaper topology types
39
+
40
+ These advanced exports are useful for custom integrations and tests, but they
41
+ may change faster than the main `Emap` and `TopologySource` API while the
42
+ project is still pre-production.
43
+
44
+ ## 3. Data Sources
45
+
46
+ Supported inputs:
47
+
48
+ | Input | Entry |
49
+ |---|---|
50
+ | GeoJSON | `TopologySource.fromUrl()`, `fromBytes()`, `setData()` |
51
+ | TopoJSON | `TopologySource.fromUrl()`, `fromBytes()`, `setData()` |
52
+ | ZIP Shapefile | `TopologySource.fromUrl()`, `fromBytes()`, `setData()` |
53
+ | Mapshaper snapshot | `map.loadSnapshot()` |
54
+
55
+ Source capabilities:
56
+
57
+ - Awaitable loading contract: `setData()` resolves after data is ready.
58
+ - Order-independent `map.addSource()`.
59
+ - CRS inference from GeoJSON defaults and Shapefile `.prj`.
60
+ - ZIP extraction limits for archive count, decompressed size, and ratio checks.
61
+ - `getLayers()`, `getDataset()`, `getExtent()`, `getArcs()`, and export helpers.
62
+ - `DisplayArcs` LOD wrapper for large datasets.
63
+
64
+ ## 4. Layers and Rendering
65
+
66
+ Layer types:
67
+
68
+ - `line`
69
+ - `fill`
70
+ - `circle`
71
+
72
+ Layer APIs:
73
+
74
+ - `map.addLayer(layer, before?)`
75
+ - `map.removeLayer(id)`
76
+ - `map.getLayer(id)`
77
+ - `map.getLayers()`
78
+ - `map.moveLayer(id, beforeId?)`
79
+ - `map.setLayerVisibility(id, visibility)`
80
+ - `map.setPaintProperty(id, name, value)`
81
+
82
+ Rendering capabilities:
83
+
84
+ - HTML5 Canvas 2D renderer.
85
+ - Batched stroke drawing for topology arcs.
86
+ - Shared-arc line rendering so polygon boundaries can be drawn once.
87
+ - Polygon fill rendering with even-odd fill handling.
88
+ - Point rendering.
89
+ - Highlight overlay rendering.
90
+ - Edit and draw overlay rendering.
91
+
92
+ ## 5. Camera and View
93
+
94
+ Camera methods:
95
+
96
+ - `jumpTo()`
97
+ - `setCenter()`
98
+ - `setZoom()`
99
+ - `easeTo()`
100
+ - `flyTo()`
101
+ - `panTo()`
102
+ - `panBy()`
103
+ - `zoomTo()`
104
+ - `fitBounds()`
105
+ - `stop()`
106
+
107
+ View and coordinate methods:
108
+
109
+ - `getCenter()`
110
+ - `getZoom()`
111
+ - `getExtent()`
112
+ - `setExtent()`
113
+ - `reset()`
114
+ - `project()`
115
+ - `unproject()`
116
+ - `resize()`
117
+
118
+ Camera events:
119
+
120
+ - `movestart`
121
+ - `move`
122
+ - `moveend`
123
+ - `zoomstart`
124
+ - `zoom`
125
+ - `zoomend`
126
+
127
+ ## 6. Named Interaction Handlers
128
+
129
+ `emap` exposes built-in interactions as named handlers. Third-party apps can use
130
+ these directly without using bundled UI controls.
131
+
132
+ | Handler | Purpose |
133
+ |---|---|
134
+ | `map.dragPan` | Pointer drag map panning |
135
+ | `map.scrollZoom` | Wheel zoom |
136
+ | `map.clickSelect` | Click selection |
137
+ | `map.boxSelect` | Shift-drag rectangular selection |
138
+ | `map.lassoSelect` | Free-form lasso selection |
139
+ | `map.vertexEdit` | Topology-aware vertex editing |
140
+ | `map.drawFeature` | Point, polyline, and polygon drawing |
141
+ | `map.transformFeature` | Translate, rotate, or scale selected features |
142
+
143
+ Uniform handler surface:
144
+
145
+ - `enable()`
146
+ - `disable()`
147
+ - `isEnabled()`
148
+ - `setOptions()`
149
+ - `getOptions()`
150
+ - `handlePointer()`
151
+ - optional `getCursor()`
152
+
153
+ `HandlerManager` arbitrates pointer events with priority ordering, exclusive
154
+ gesture locking, and cursor resolution.
155
+
156
+ ## 7. Selection, Hit Testing, and Feature Events
157
+
158
+ Selection APIs:
159
+
160
+ - `map.select(features, { mode })`
161
+ - `map.deselect(features)`
162
+ - `map.clearSelection()`
163
+ - `map.getSelection()`
164
+ - `map.isSelected(feature)`
165
+ - `map.deleteSelected()`
166
+
167
+ Selection modes:
168
+
169
+ - `replace`
170
+ - `add`
171
+ - `toggle`
172
+
173
+ Feature querying:
174
+
175
+ - Point query: `map.queryFeatures([x, y], options?)`
176
+ - BBox query: `map.queryFeatures([[x1, y1], [x2, y2]], options?)`
177
+ - Layer filtering through `{ layers: [...] }`
178
+ - Lazy Flatbush spatial indexes.
179
+ - `map.prebuildSpatialIndex(sourceId?)`
180
+ - `map.clearSpatialIndex(sourceId?)`
181
+
182
+ Delegated events:
183
+
184
+ - `feature:click`
185
+ - `feature:hover`
186
+ - `feature:enter`
187
+ - `feature:leave`
188
+ - `mousemove`
189
+
190
+ Feature accessor:
191
+
192
+ - `map.features.get(ref)`
193
+ - `map.features.iter(sourceId, layerId)`
194
+ - `map.features.count(sourceId, layerId)`
195
+
196
+ Highlighting:
197
+
198
+ - `map.setHighlightedFeatures(features, style?)`
199
+ - `map.clearHighlightedFeatures()`
200
+ - `map.setHighlightStyle(style)`
201
+
202
+ ## 8. Editing Model
203
+
204
+ Undoable command families:
205
+
206
+ - Vertex commands: `VertexMoveCommand`, `VertexInsertCommand`,
207
+ `VertexDeleteCommand`.
208
+ - Feature commands: `FeatureCreateCommand`, `FeatureDeleteCommand`,
209
+ `BulkFeatureDeleteCommand`, `FeatureTranslateCommand`, `FeatureAffineCommand`.
210
+ - Topology commands: `SplitSharedArcsCommand`.
211
+ - Dataset replace: `DatasetReplaceCommand`.
212
+ - Attribute and schema commands: `FeaturePropertyChangeCommand`,
213
+ `FieldAddCommand`, `FieldRemoveCommand`, `FieldRenameCommand`.
214
+ - Multi-command envelope: `CompositeCommand`.
215
+
216
+ Session editing:
217
+
218
+ - `map.editSession.translateSelected(dx, dy)`
219
+ - `map.editSession.rotateSelected(angle, origin?)`
220
+ - `map.editSession.scaleSelected(sx, sy?, origin?)`
221
+ - `map.editSession.beginTranslateSession(options?)`
222
+ - `map.editSession.beginAffineSession(matrix?, origin?)`
223
+
224
+ Transactions:
225
+
226
+ - `map.beginTransaction()`
227
+ - `tx.commit(label?)`
228
+ - `tx.rollback()`
229
+
230
+ Undo/redo:
231
+
232
+ - `map.undo()`
233
+ - `map.redo()`
234
+ - `map.canUndo()`
235
+ - `map.canRedo()`
236
+ - `map.clearHistory()`
237
+ - `map.bindHistoryShortcuts()`
238
+
239
+ ## 9. Mapshaper Operations
240
+
241
+ All operations live under `map.ops` and return `Promise<OpResult>`.
242
+
243
+ Geometry and topology:
244
+
245
+ - `clipLayer`
246
+ - `eraseLayer`
247
+ - `dissolveLayer`
248
+ - `bufferLayer`
249
+ - `simplifyLayer`
250
+ - `projectLayer`
251
+ - `affineLayer`
252
+ - `cleanLayer`
253
+ - `snapLayer`
254
+ - `rebuildTopology`
255
+ - `checkGeometry`
256
+
257
+ Set and overlay operations:
258
+
259
+ - `mosaicLayer`
260
+ - `unionLayers`
261
+ - `divideLayer`
262
+ - `intersectionPointsLayer`
263
+
264
+ Geometry conversion:
265
+
266
+ - `pointsLayer`
267
+ - `linesLayer`
268
+ - `polygonsLayer`
269
+ - `innerlinesLayer`
270
+ - `explodeLayer`
271
+
272
+ Layer management:
273
+
274
+ - `renameLayer`
275
+ - `mergeLayers`
276
+ - `splitLayer`
277
+ - `dropLayer`
278
+
279
+ Filtering and attributes:
280
+
281
+ - `applyExpression`
282
+ - `filterFeatures`
283
+ - `filterIslands`
284
+ - `filterSlivers`
285
+ - `filterGeom`
286
+ - `sortFeatures`
287
+ - `uniqueFeatures`
288
+ - `filterFields`
289
+ - `renameFields`
290
+ - `joinTable`
291
+ - `dataFill`
292
+
293
+ Selection-driven:
294
+
295
+ - `mergeSelected`
296
+
297
+ Operation runtime features:
298
+
299
+ - Parsed command objects instead of shell strings.
300
+ - Effect-aware selection preservation.
301
+ - Dataset-replace undo barriers.
302
+ - Optional worker routing.
303
+ - Structured `OpResult` and `OpError` responses.
304
+
305
+ ## 10. Validation
306
+
307
+ Validator registry:
308
+
309
+ - `map.validators.register(validator)`
310
+ - returned unregister function
311
+ - `validationfailed` event
312
+
313
+ Built-in validator:
314
+
315
+ - `topologyValidator(options)`
316
+
317
+ Validation runs after committed history changes. The engine reports failures and
318
+ leaves application policy decisions to the host app.
319
+
320
+ ## 11. Worker Offloading
321
+
322
+ Worker options:
323
+
324
+ - `useWorker: false | true | 'auto'`
325
+ - `workerMode` compatibility alias
326
+ - `workerThreshold`
327
+ - `workerUrl`
328
+ - `workerPoolSize`
329
+ - `workerPool`
330
+ - `workerRouting(info)`
331
+
332
+ Worker features:
333
+
334
+ - Lazy worker creation.
335
+ - Multiple worker instances through `MapshaperWorkerPool`.
336
+ - Command-family-aware routing.
337
+ - Cancellation through `map.cancelWorkerJobs()`.
338
+ - Transferable arc buffers where supported by the Mapshaper pack/unpack path.
339
+
340
+ ## 12. Snapshots and Export
341
+
342
+ Map snapshot APIs:
343
+
344
+ - `map.exportSnapshot(options?)`
345
+ - `map.loadSnapshot(input, options?)`
346
+
347
+ Source export formats:
348
+
349
+ - GeoJSON
350
+ - TopoJSON
351
+ - Shapefile ZIP
352
+
353
+ Snapshots use Mapshaper pack data with `emap` source metadata for multi-source
354
+ restore.
355
+
356
+ ## 13. Built-In Controls
357
+
358
+ | Control | Purpose |
359
+ |---|---|
360
+ | `NavigationControl` | Zoom in, zoom out, reset |
361
+ | `StatusControl` | Pointer coordinates and CRS |
362
+ | `BasemapControl` | MapLibre raster basemap toggle |
363
+ | `HistoryControl` | Undo/redo |
364
+ | `EditToolbar` | Combined edit toolbar |
365
+ | `VertexEditControl` | Button shell over `map.vertexEdit` |
366
+ | `DrawFeatureControl` | Button shell over `map.drawFeature` |
367
+ | `BoxSelectControl` | Thin shell over `map.boxSelect` |
368
+ | `LassoSelectControl` | Thin shell over `map.lassoSelect` |
369
+ | `SimplifyControl` | Simplification UI |
370
+
371
+ Custom controls implement:
372
+
373
+ - `onAdd(map): HTMLElement`
374
+ - `onRemove(map?)`
375
+
376
+ Control positions:
377
+
378
+ - `top-left`
379
+ - `top-right`
380
+ - `bottom-left`
381
+ - `bottom-right`
382
+
383
+ ## 14. Events
384
+
385
+ Typed map events include:
386
+
387
+ - `data`
388
+ - `error`
389
+ - `selectionchange`
390
+ - `historychange`
391
+ - `editmodechange`
392
+ - `validationfailed`
393
+ - `crschange`
394
+ - `resize`
395
+ - camera lifecycle events
396
+
397
+ `EmapEventMap` is augmentable through TypeScript module augmentation for
398
+ application-specific events.
399
+
400
+ ## 15. CRS and Geometry Utilities
401
+
402
+ Exports:
403
+
404
+ - `Bounds`
405
+ - `AffineTransform`
406
+ - `Viewport`
407
+ - `Projection`
408
+ - `DEFAULT_CRS`
409
+ - `inferFromPrj`
410
+ - `normalizeCrsString`
411
+ - `resolveDatasetCRS`
412
+
413
+ Mapshaper topology types are also exported for consumers that need to build
414
+ custom commands or inspect raw datasets.
415
+
416
+ ## 16. Public Advanced Surfaces
417
+
418
+ Advanced exports include:
419
+
420
+ - `DefaultMapshaperAdapter`
421
+ - `getDefaultMapshaperAdapter`
422
+ - `setDefaultMapshaperAdapter`
423
+ - `MapshaperWorkerPool`
424
+ - `HandlerManager`
425
+ - built-in handler classes
426
+ - `CanvasPainter`
427
+ - `EditOverlayRenderer`
428
+ - edit command classes
429
+ - `ValidatorRegistry`
430
+ - `Err`, `OK`, and `okValue`
431
+ - layer paint resolvers
432
+ - CLI safety helpers: `quoteCliArg`, `isValidLayerName`, `isValidFieldName`
433
+
434
+ ## 17. Security and Constraints
435
+
436
+ - Browser runtime only.
437
+ - No server dependency.
438
+ - Mapshaper internals are isolated behind `MapshaperAdapter`.
439
+ - Expression-bearing APIs default to `expressionPolicy: 'disabled'`.
440
+ - Apps must opt in to `expressionPolicy: 'trusted'` before executing trusted
441
+ expression strings.
442
+ - Worker assets must be served by the host app when worker offloading is used.
443
+
444
+ ## 18. Examples and Tests
445
+
446
+ - Manual examples: `test/examples/*.html`.
447
+ - Unit tests: `src/**/*.test.ts`.
448
+ - Type tests: `*.test-d.ts`.
449
+ - Build and verification:
450
+
451
+ ```bash
452
+ cmd /c npm run typecheck
453
+ cmd /c npm run test:run
454
+ cmd /c npm run build
455
+ ```