@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 ADDED
@@ -0,0 +1,281 @@
1
+ # @classic-homes/maps-core
2
+
3
+ Core utilities, types, and themes for Classic Theme map components. This package provides the shared foundation for `@classic-homes/maps-react` and `@classic-homes/maps-svelte`.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @classic-homes/maps-core
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **Theme System**: Pre-configured light/dark themes with design token integration
14
+ - **MapLibre Style Generation**: Generate complete MapLibre GL styles from themes
15
+ - **Type Definitions**: Comprehensive TypeScript types for all map components
16
+ - **Utility Functions**: Bounds calculation, GeoJSON validation, coordinate formatting
17
+ - **Style Helpers**: Create hover, selection, and data-driven expressions
18
+ - **Spatial Indexing**: Grid-based and R-tree indexes for large datasets
19
+ - **LOD Utilities**: Level-of-detail management for 100k+ feature datasets
20
+ - **Polygon Simplification**: Douglas-Peucker algorithm for zoom-based simplification
21
+
22
+ ## Usage
23
+
24
+ ### Themes
25
+
26
+ ```typescript
27
+ import {
28
+ lightTheme,
29
+ darkTheme,
30
+ lightBasicStyle,
31
+ darkBasicStyle,
32
+ THEME_LIGHT,
33
+ THEME_DARK,
34
+ } from '@classic-homes/maps-core';
35
+
36
+ // Use pre-generated MapLibre styles
37
+ const mapStyle = isDark ? darkBasicStyle : lightBasicStyle;
38
+
39
+ // Or access theme colors for custom styling
40
+ const highlightColor = lightTheme.colors.highlight;
41
+ ```
42
+
43
+ ### Style Expressions
44
+
45
+ ```typescript
46
+ import {
47
+ createHoverExpression,
48
+ createSelectionExpression,
49
+ createInteractiveExpression,
50
+ createCategoricalColorExpression,
51
+ createContinuousColorExpression,
52
+ createLotFillStyle,
53
+ createLotOutlineStyle,
54
+ } from '@classic-homes/maps-core';
55
+
56
+ // Hover highlighting
57
+ const fillColor = createHoverExpression('#22c55e', '#3b82f6');
58
+
59
+ // Status-based coloring
60
+ const statusColor = createCategoricalColorExpression(
61
+ 'status',
62
+ {
63
+ available: '#22c55e',
64
+ pending: '#f59e0b',
65
+ sold: '#ef4444',
66
+ },
67
+ '#888888'
68
+ );
69
+
70
+ // Lot fill with hover/selection support
71
+ const lotStyle = createLotFillStyle({
72
+ defaultColor: '#22c55e',
73
+ hoverColor: '#3b82f6',
74
+ selectedColor: '#f59e0b',
75
+ opacity: 0.7,
76
+ });
77
+ ```
78
+
79
+ ### Bounds and Data Utilities
80
+
81
+ ```typescript
82
+ import {
83
+ calculateBounds,
84
+ combineBounds,
85
+ loadGeoJSON,
86
+ validateGeoJSON,
87
+ calculateCentroid,
88
+ filterByGeometryType,
89
+ } from '@classic-homes/maps-core';
90
+
91
+ // Calculate bounds of a GeoJSON
92
+ const bounds = calculateBounds(featureCollection);
93
+
94
+ // Load and validate GeoJSON
95
+ const { data, error, success } = await loadGeoJSON('/api/features.geojson');
96
+
97
+ // Filter by geometry type
98
+ const polygonsOnly = filterByGeometryType(featureCollection, ['Polygon', 'MultiPolygon']);
99
+ ```
100
+
101
+ ### Spatial Indexing (Large Datasets)
102
+
103
+ ```typescript
104
+ import {
105
+ buildSpatialIndex,
106
+ queryByBounds,
107
+ buildRTreeIndex,
108
+ queryRTreeByBounds,
109
+ createIdleViewportManager,
110
+ } from '@classic-homes/maps-core';
111
+
112
+ // Build a spatial index for fast viewport queries
113
+ const index = buildSpatialIndex(featureCollection, { targetCells: 100 });
114
+
115
+ // Query visible features in viewport
116
+ const visible = queryByBounds(index, viewportBounds, { buffer: 0.1 });
117
+
118
+ // For smooth panning, use the idle-aware viewport manager
119
+ const viewportManager = createIdleViewportManager(featureCollection, {
120
+ indexType: 'rtree',
121
+ bufferFraction: 0.2,
122
+ });
123
+
124
+ const result = viewportManager.query(viewportBounds);
125
+ ```
126
+
127
+ ### Level-of-Detail (LOD) for Large Datasets
128
+
129
+ ```typescript
130
+ import {
131
+ generateLODData,
132
+ generateLODDataWithSimplification,
133
+ createDynamicLODManager,
134
+ DEFAULT_SIMPLIFICATION_THRESHOLDS,
135
+ } from '@classic-homes/maps-core';
136
+
137
+ // Generate LOD boundaries
138
+ const lod = generateLODData(lotsData, {
139
+ groupBy: 'community',
140
+ subGroupBy: 'filing',
141
+ useConvexHull: true,
142
+ });
143
+
144
+ // With polygon simplification for different zoom levels
145
+ const lodWithSimplification = generateLODDataWithSimplification(lotsData, {
146
+ groupBy: 'community',
147
+ simplificationThresholds: DEFAULT_SIMPLIFICATION_THRESHOLDS,
148
+ });
149
+
150
+ // Dynamic FPS-based LOD threshold adjustment
151
+ const lodManager = createDynamicLODManager({
152
+ baseThresholds: { groupMaxZoom: 12, subGroupMaxZoom: 14 },
153
+ targetFps: 50,
154
+ });
155
+ ```
156
+
157
+ ### Fast GeoJSON Change Detection
158
+
159
+ ```typescript
160
+ import { createGeoJSONFingerprint, fingerprintEqual, geoJSONEqual } from '@classic-homes/maps-core';
161
+
162
+ // O(1) equality check instead of deep comparison
163
+ const prevFingerprint = createGeoJSONFingerprint(prevData);
164
+ const nextFingerprint = createGeoJSONFingerprint(nextData);
165
+
166
+ if (!fingerprintEqual(prevFingerprint, nextFingerprint)) {
167
+ // Data changed, update the map
168
+ updateSource(nextData);
169
+ }
170
+ ```
171
+
172
+ ## Type Exports
173
+
174
+ The package exports comprehensive TypeScript types:
175
+
176
+ ```typescript
177
+ import type {
178
+ // Coordinates
179
+ LngLat,
180
+ MapBounds,
181
+ BoundsArray,
182
+ MapViewport,
183
+
184
+ // GeoJSON
185
+ GeoJSONFeature,
186
+ GeoJSONFeatureCollection,
187
+ GeoJSONGeometry,
188
+ GeoJSONPolygon,
189
+
190
+ // Events
191
+ MapClickEventParams,
192
+ MapHoverEventParams,
193
+ FeatureClickEventParams,
194
+ FeatureHoverEventParams,
195
+ MarkerClickEventParams,
196
+
197
+ // Component Props
198
+ MapProps,
199
+ SourceProps,
200
+ FillLayerProps,
201
+ LineLayerProps,
202
+ CircleLayerProps,
203
+ MarkerProps,
204
+ PopupProps,
205
+
206
+ // Themes
207
+ MapTheme,
208
+ MapThemeColors,
209
+ MapStyleSpec,
210
+ } from '@classic-homes/maps-core';
211
+ ```
212
+
213
+ ## API Reference
214
+
215
+ ### Theme Functions
216
+
217
+ | Function | Description |
218
+ | --------------------------- | ---------------------------- |
219
+ | `generateLightTheme()` | Generate light theme colors |
220
+ | `generateDarkTheme()` | Generate dark theme colors |
221
+ | `generateBasicStyle(theme)` | Generate MapLibre style spec |
222
+ | `getTheme(name)` | Get theme by name |
223
+
224
+ ### Style Helpers
225
+
226
+ | Function | Description |
227
+ | ------------------------------------------------------ | ----------------------------------------- |
228
+ | `createFillStyle(opts)` | Create fill layer paint properties |
229
+ | `createLineStyle(opts)` | Create line layer paint/layout properties |
230
+ | `createCircleStyle(opts)` | Create circle layer paint properties |
231
+ | `createHoverExpression(base, hover)` | Feature-state based hover expression |
232
+ | `createSelectionExpression(base, selected)` | Feature-state based selection expression |
233
+ | `createInteractiveExpression(base, hover, selected)` | Combined hover + selection |
234
+ | `createCategoricalColorExpression(prop, map, default)` | Match expression for categories |
235
+ | `createContinuousColorExpression(prop, stops, interp)` | Interpolate expression |
236
+ | `createZoomExpression(stops)` | Zoom-based interpolation |
237
+
238
+ ### Data Utilities
239
+
240
+ | Function | Description |
241
+ | --------------------------------- | ------------------------------- |
242
+ | `loadGeoJSON(url, opts)` | Fetch and validate GeoJSON |
243
+ | `validateGeoJSON(data)` | Validate GeoJSON structure |
244
+ | `calculateCentroid(geojson)` | Calculate centroid of features |
245
+ | `countFeaturesByType(fc)` | Count features by geometry type |
246
+ | `filterByGeometryType(fc, types)` | Filter by geometry types |
247
+
248
+ ### Bounds Utilities
249
+
250
+ | Function | Description |
251
+ | ----------------------------- | ------------------------------ |
252
+ | `calculateBounds(geojson)` | Get bounding box of features |
253
+ | `extendBounds(bounds, point)` | Extend bounds to include point |
254
+ | `combineBounds(a, b)` | Merge two bounds |
255
+ | `isValidBounds(bounds)` | Validate bounds array |
256
+
257
+ ### Spatial Indexing
258
+
259
+ | Function | Description |
260
+ | ------------------------------------------- | ------------------------------ |
261
+ | `buildSpatialIndex(fc, opts)` | Build grid-based spatial index |
262
+ | `queryByBounds(index, bounds, opts)` | Query features in viewport |
263
+ | `buildRTreeIndex(fc, opts)` | Build R-tree spatial index |
264
+ | `queryRTreeByBounds(index, bounds, opts)` | Query R-tree by bounds |
265
+ | `createIdleViewportManager(fc, opts)` | Smooth viewport querying |
266
+ | `createPredictiveViewportManager(fc, opts)` | Predictive pan loading |
267
+
268
+ ### LOD Utilities
269
+
270
+ | Function | Description |
271
+ | ------------------------------------------ | ------------------------------ |
272
+ | `groupFeaturesByProperty(fc, opts)` | Group features by property |
273
+ | `generateLODData(fc, opts)` | Generate LOD boundaries |
274
+ | `generateConvexHull(features)` | Generate convex hull polygon |
275
+ | `simplifyPolygon(polygon, tolerance)` | Douglas-Peucker simplification |
276
+ | `simplifyFeatureCollection(fc, tolerance)` | Simplify all features |
277
+ | `createDynamicLODManager(opts)` | FPS-based threshold adjustment |
278
+
279
+ ## License
280
+
281
+ MIT