maplibre-gl-components 0.7.0 → 0.8.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 +110 -4
- package/dist/{ViewStateControl-DLs9HXSx.js → ControlGrid-CbLTUHJu.js} +500 -79
- package/dist/ControlGrid-CbLTUHJu.js.map +1 -0
- package/dist/{ViewStateControl-BZNDy3xx.cjs → ControlGrid-CeLIAj43.cjs} +443 -22
- package/dist/ControlGrid-CeLIAj43.cjs.map +1 -0
- package/dist/index.cjs +76 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +58 -57
- package/dist/maplibre-gl-components.css +108 -0
- package/dist/react.cjs +189 -37
- package/dist/react.cjs.map +1 -1
- package/dist/react.mjs +180 -28
- package/dist/react.mjs.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/core/Basemap.d.ts.map +1 -1
- package/dist/types/lib/core/Colorbar.d.ts.map +1 -1
- package/dist/types/lib/core/ControlGrid.d.ts +75 -0
- package/dist/types/lib/core/ControlGrid.d.ts.map +1 -0
- package/dist/types/lib/core/ControlGridReact.d.ts +32 -0
- package/dist/types/lib/core/ControlGridReact.d.ts.map +1 -0
- package/dist/types/lib/core/HtmlControl.d.ts.map +1 -1
- package/dist/types/lib/core/InspectControl.d.ts.map +1 -1
- package/dist/types/lib/core/Legend.d.ts.map +1 -1
- package/dist/types/lib/core/SearchControl.d.ts.map +1 -1
- package/dist/types/lib/core/Terrain.d.ts.map +1 -1
- package/dist/types/lib/core/VectorDataset.d.ts.map +1 -1
- package/dist/types/lib/core/ViewStateControl.d.ts.map +1 -1
- package/dist/types/lib/core/types.d.ts +80 -1
- package/dist/types/lib/core/types.d.ts.map +1 -1
- package/dist/types/lib/hooks/index.d.ts +1 -0
- package/dist/types/lib/hooks/index.d.ts.map +1 -1
- package/dist/types/lib/hooks/useControlGrid.d.ts +41 -0
- package/dist/types/lib/hooks/useControlGrid.d.ts.map +1 -0
- package/dist/types/react.d.ts +3 -2
- package/dist/types/react.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/ViewStateControl-BZNDy3xx.cjs.map +0 -1
- package/dist/ViewStateControl-DLs9HXSx.js.map +0 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ Legend, colorbar, basemap switcher, terrain toggle, search, vector data loader,
|
|
|
16
16
|
- **SearchControl** - Collapsible place search with geocoding and fly-to functionality
|
|
17
17
|
- **VectorDatasetControl** - Load GeoJSON files via file upload or drag-and-drop
|
|
18
18
|
- **InspectControl** - Click on features to view their properties/attributes
|
|
19
|
+
- **ViewStateControl** - Display live map state (center, bounds, zoom, pitch, bearing) with optional bbox drawing
|
|
19
20
|
- **HtmlControl** - Flexible HTML content control for custom info panels
|
|
20
21
|
- **Zoom-based Visibility** - Show/hide components at specific zoom levels with `minzoom`/`maxzoom`
|
|
21
22
|
- **React Support** - First-class React components and hooks
|
|
@@ -34,7 +35,7 @@ npm install maplibre-gl-components
|
|
|
34
35
|
|
|
35
36
|
```typescript
|
|
36
37
|
import maplibregl from 'maplibre-gl';
|
|
37
|
-
import { Colorbar, Legend, HtmlControl, BasemapControl, TerrainControl, SearchControl, VectorDatasetControl } from 'maplibre-gl-components';
|
|
38
|
+
import { Colorbar, Legend, HtmlControl, BasemapControl, TerrainControl, SearchControl, VectorDatasetControl, ViewStateControl } from 'maplibre-gl-components';
|
|
38
39
|
import 'maplibre-gl-components/style.css';
|
|
39
40
|
|
|
40
41
|
const map = new maplibregl.Map({
|
|
@@ -69,6 +70,18 @@ vectorControl.on('load', (event) => {
|
|
|
69
70
|
console.log('Loaded:', event.dataset?.filename);
|
|
70
71
|
});
|
|
71
72
|
|
|
73
|
+
// Add a view state control
|
|
74
|
+
const viewStateControl = new ViewStateControl({
|
|
75
|
+
collapsed: false,
|
|
76
|
+
enableBBox: true,
|
|
77
|
+
precision: 4,
|
|
78
|
+
});
|
|
79
|
+
map.addControl(viewStateControl, 'bottom-left');
|
|
80
|
+
|
|
81
|
+
viewStateControl.on('bboxdraw', (event) => {
|
|
82
|
+
console.log('Drawn bbox:', event.bbox);
|
|
83
|
+
});
|
|
84
|
+
|
|
72
85
|
// Add a basemap switcher
|
|
73
86
|
const basemapControl = new BasemapControl({
|
|
74
87
|
defaultBasemap: 'OpenStreetMap.Mapnik',
|
|
@@ -115,7 +128,7 @@ htmlControl.setHtml('<div><strong>Stats:</strong> 5,678 features</div>');
|
|
|
115
128
|
```tsx
|
|
116
129
|
import { useState, useEffect, useRef } from 'react';
|
|
117
130
|
import maplibregl from 'maplibre-gl';
|
|
118
|
-
import { ColorbarReact, LegendReact, HtmlControlReact, BasemapReact, TerrainReact, SearchControlReact, VectorDatasetReact } from 'maplibre-gl-components/react';
|
|
131
|
+
import { ColorbarReact, LegendReact, HtmlControlReact, BasemapReact, TerrainReact, SearchControlReact, VectorDatasetReact, ViewStateControlReact } from 'maplibre-gl-components/react';
|
|
119
132
|
import 'maplibre-gl-components/style.css';
|
|
120
133
|
|
|
121
134
|
function MyMap() {
|
|
@@ -151,6 +164,15 @@ function MyMap() {
|
|
|
151
164
|
onDatasetLoad={(dataset) => console.log('Loaded:', dataset.filename)}
|
|
152
165
|
/>
|
|
153
166
|
|
|
167
|
+
<ViewStateControlReact
|
|
168
|
+
map={map}
|
|
169
|
+
collapsed={false}
|
|
170
|
+
enableBBox
|
|
171
|
+
precision={4}
|
|
172
|
+
position="bottom-left"
|
|
173
|
+
onBBoxDraw={(bbox) => console.log('Drawn bbox:', bbox)}
|
|
174
|
+
/>
|
|
175
|
+
|
|
154
176
|
<SearchControlReact
|
|
155
177
|
map={map}
|
|
156
178
|
placeholder="Search for a place..."
|
|
@@ -640,6 +662,74 @@ inspectControl.on('clear', handler) // Fired when inspection is cleared
|
|
|
640
662
|
4. Use < > buttons to navigate when multiple features are at the same location
|
|
641
663
|
5. Click elsewhere or the button again to disable
|
|
642
664
|
|
|
665
|
+
### ViewStateControl
|
|
666
|
+
|
|
667
|
+
A control that displays live map view state (center, bounds, zoom, pitch, bearing) with optional bounding box drawing.
|
|
668
|
+
|
|
669
|
+
```typescript
|
|
670
|
+
interface ViewStateControlOptions {
|
|
671
|
+
position?: ControlPosition;
|
|
672
|
+
className?: string; // Custom CSS class
|
|
673
|
+
visible?: boolean; // Default: true
|
|
674
|
+
collapsed?: boolean; // Start collapsed (button only). Default: true
|
|
675
|
+
precision?: number; // Decimal precision for coordinates. Default: 4
|
|
676
|
+
showCenter?: boolean; // Show center coordinates. Default: true
|
|
677
|
+
showBounds?: boolean; // Show map bounds. Default: true
|
|
678
|
+
showZoom?: boolean; // Show zoom level. Default: true
|
|
679
|
+
showPitch?: boolean; // Show pitch value. Default: true
|
|
680
|
+
showBearing?: boolean; // Show bearing value. Default: true
|
|
681
|
+
enableBBox?: boolean; // Enable bounding box drawing. Default: false
|
|
682
|
+
bboxFillColor?: string; // BBox fill color. Default: 'rgba(0, 120, 215, 0.1)'
|
|
683
|
+
bboxStrokeColor?: string; // BBox stroke color. Default: '#0078d7'
|
|
684
|
+
bboxStrokeWidth?: number; // BBox stroke width. Default: 2
|
|
685
|
+
panelWidth?: number; // Panel width in pixels. Default: 280
|
|
686
|
+
backgroundColor?: string;
|
|
687
|
+
borderRadius?: number;
|
|
688
|
+
opacity?: number;
|
|
689
|
+
fontSize?: number;
|
|
690
|
+
fontColor?: string;
|
|
691
|
+
minzoom?: number;
|
|
692
|
+
maxzoom?: number;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
interface ViewStateControlState {
|
|
696
|
+
visible: boolean;
|
|
697
|
+
collapsed: boolean;
|
|
698
|
+
center: [number, number]; // [lng, lat]
|
|
699
|
+
bounds: [number, number, number, number]; // [west, south, east, north]
|
|
700
|
+
zoom: number;
|
|
701
|
+
pitch: number; // Degrees
|
|
702
|
+
bearing: number; // Degrees
|
|
703
|
+
drawingBBox: boolean; // Whether bbox drawing is active
|
|
704
|
+
drawnBBox: [number, number, number, number] | null; // Drawn bbox or null
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// Methods
|
|
708
|
+
viewStateControl.show()
|
|
709
|
+
viewStateControl.hide()
|
|
710
|
+
viewStateControl.expand() // Expand the panel
|
|
711
|
+
viewStateControl.collapse() // Collapse to button only
|
|
712
|
+
viewStateControl.toggle() // Toggle expanded/collapsed
|
|
713
|
+
viewStateControl.isCollapsed() // Check if collapsed
|
|
714
|
+
viewStateControl.startBBoxDraw() // Start bounding box drawing mode
|
|
715
|
+
viewStateControl.stopBBoxDraw() // Stop bounding box drawing mode
|
|
716
|
+
viewStateControl.clearBBox() // Clear the drawn bounding box
|
|
717
|
+
viewStateControl.update(options)
|
|
718
|
+
viewStateControl.getState()
|
|
719
|
+
viewStateControl.on('viewchange', handler) // Fired when map view changes
|
|
720
|
+
viewStateControl.on('bboxdraw', handler) // Fired when bbox is drawn
|
|
721
|
+
viewStateControl.on('bboxclear', handler) // Fired when bbox is cleared
|
|
722
|
+
viewStateControl.on('drawstart', handler) // Fired when drawing mode starts
|
|
723
|
+
viewStateControl.on('drawend', handler) // Fired when drawing mode ends
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
**Usage:**
|
|
727
|
+
1. Click the target button to expand/collapse the panel
|
|
728
|
+
2. Pan, zoom, or tilt the map to see live updates
|
|
729
|
+
3. Click "Draw BBox" to enter drawing mode
|
|
730
|
+
4. Click and drag on the map to draw a bounding box
|
|
731
|
+
5. Copy coordinates using the copy button next to each value
|
|
732
|
+
|
|
643
733
|
## Built-in Colormaps
|
|
644
734
|
|
|
645
735
|
### Sequential
|
|
@@ -745,7 +835,7 @@ const colorbar = new Colorbar({
|
|
|
745
835
|
## React Hooks
|
|
746
836
|
|
|
747
837
|
```typescript
|
|
748
|
-
import { useColorbar, useLegend, useHtmlControl, useBasemap, useTerrain, useSearchControl, useVectorDataset } from 'maplibre-gl-components/react';
|
|
838
|
+
import { useColorbar, useLegend, useHtmlControl, useBasemap, useTerrain, useSearchControl, useVectorDataset, useViewState } from 'maplibre-gl-components/react';
|
|
749
839
|
|
|
750
840
|
function MyComponent() {
|
|
751
841
|
const colorbar = useColorbar({ colormap: 'viridis', vmin: 0, vmax: 100 });
|
|
@@ -755,6 +845,7 @@ function MyComponent() {
|
|
|
755
845
|
const terrain = useTerrain({ enabled: false, exaggeration: 1.5 });
|
|
756
846
|
const search = useSearchControl({ collapsed: true });
|
|
757
847
|
const vectorDataset = useVectorDataset();
|
|
848
|
+
const viewState = useViewState({ collapsed: false, enableBBox: true });
|
|
758
849
|
|
|
759
850
|
return (
|
|
760
851
|
<>
|
|
@@ -853,14 +944,29 @@ The default styles can be customized using CSS:
|
|
|
853
944
|
.maplibre-gl-vector-dataset-dropzone {
|
|
854
945
|
background: rgba(0, 120, 215, 0.2);
|
|
855
946
|
}
|
|
947
|
+
|
|
948
|
+
/* Override view state control styles */
|
|
949
|
+
.maplibre-gl-view-state-button:hover {
|
|
950
|
+
color: #0078d7;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
.maplibre-gl-view-state-panel {
|
|
954
|
+
background: rgba(255, 255, 255, 0.95);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
.maplibre-gl-view-state-bbox-toggle--active {
|
|
958
|
+
background: #0078d7;
|
|
959
|
+
color: white;
|
|
960
|
+
}
|
|
856
961
|
```
|
|
857
962
|
|
|
858
963
|
## Examples
|
|
859
964
|
|
|
860
965
|
See the [examples](./examples/) directory for complete working examples:
|
|
861
966
|
|
|
862
|
-
- **Basic Example** - Vanilla TypeScript with all
|
|
967
|
+
- **Basic Example** - Vanilla TypeScript with all components
|
|
863
968
|
- **React Example** - React with hooks and dynamic updates
|
|
969
|
+
- **View State Example** - View state control with bounding box drawing
|
|
864
970
|
|
|
865
971
|
## Development
|
|
866
972
|
|