maplibre-gl-geo-editor 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -14,6 +14,7 @@ A powerful MapLibre GL plugin for creating and editing geometries. Extends the f
14
14
  - **Rectangle** - Draw rectangles
15
15
  - **Circle** - Draw circles
16
16
  - **Marker** - Place point markers
17
+ - **Freehand** - Draw shapes by dragging (custom implementation)
17
18
 
18
19
  ### Basic Edit Tools (via Geoman Free)
19
20
  - **Drag** - Move features on the map
@@ -23,6 +24,7 @@ A powerful MapLibre GL plugin for creating and editing geometries. Extends the f
23
24
  - **Delete** - Remove selected features (supports multi-select)
24
25
 
25
26
  ### Advanced Edit Tools (Custom Implementation)
27
+ - **Select** - Click to select features (shows properties popup when enabled)
26
28
  - **Scale** - Resize features with interactive handles
27
29
  - **Copy** - Duplicate features (Ctrl+C/V support)
28
30
  - **Split** - Split polygons/lines with a drawn line
@@ -32,6 +34,10 @@ A powerful MapLibre GL plugin for creating and editing geometries. Extends the f
32
34
  - **Lasso** - Select multiple features by drawing a polygon (supports union/difference/drag)
33
35
  - **Reset** - Clear selection and disable active tools (toolbar button)
34
36
 
37
+ ### File Operations
38
+ - **Open** - Load GeoJSON file from disk (auto-zooms to extent when enabled)
39
+ - **Save** - Download current features as GeoJSON file
40
+
35
41
  ## Installation
36
42
 
37
43
  ```bash
@@ -68,11 +74,14 @@ map.on('load', () => {
68
74
  const geoEditor = new GeoEditor({
69
75
  position: 'top-left',
70
76
  toolbarOrientation: 'vertical',
71
- drawModes: ['polygon', 'line', 'rectangle', 'circle', 'marker'],
77
+ columns: 2, // Display buttons in 2 columns (reduces toolbar height)
78
+ drawModes: ['polygon', 'line', 'rectangle', 'circle', 'marker', 'freehand'],
72
79
  editModes: [
73
- 'drag', 'change', 'rotate', 'cut', 'delete',
80
+ 'select', 'drag', 'change', 'rotate', 'cut', 'delete',
74
81
  'scale', 'copy', 'split', 'union', 'difference', 'simplify', 'lasso'
75
82
  ],
83
+ showFeatureProperties: true, // Show popup with properties on selection
84
+ fitBoundsOnLoad: true, // Auto-zoom to extent when loading GeoJSON
76
85
  onFeatureCreate: (feature) => console.log('Created:', feature),
77
86
  onSelectionChange: (features) => console.log('Selected:', features.length),
78
87
  });
@@ -130,8 +139,10 @@ function App() {
130
139
  map={map}
131
140
  geoman={geoman}
132
141
  position="top-left"
133
- drawModes={['polygon', 'line', 'marker']}
134
- editModes={['drag', 'change', 'scale', 'copy', 'union', 'split']}
142
+ drawModes={['polygon', 'line', 'marker', 'freehand']}
143
+ editModes={['select', 'drag', 'change', 'scale', 'copy', 'union', 'split']}
144
+ showFeatureProperties={true}
145
+ fitBoundsOnLoad={true}
135
146
  />
136
147
  )}
137
148
  </div>
@@ -149,14 +160,21 @@ function App() {
149
160
  | `collapsed` | `boolean` | `false` | Start with toolbar collapsed |
150
161
  | `drawModes` | `DrawMode[]` | All modes | Draw modes to enable |
151
162
  | `editModes` | `EditMode[]` | All modes | Edit modes to enable |
163
+ | `fileModes` | `FileMode[]` | `['open', 'save']` | File operations to enable |
152
164
  | `toolbarOrientation` | `'vertical' \| 'horizontal'` | `'vertical'` | Toolbar layout |
165
+ | `columns` | `number` | `1` | Number of button columns (vertical orientation only) |
153
166
  | `showLabels` | `boolean` | `false` | Show text labels on buttons |
154
167
  | `simplifyTolerance` | `number` | `0.001` | Default simplification tolerance |
168
+ | `saveFilename` | `string` | `'features.geojson'` | Default filename for saving |
169
+ | `showFeatureProperties` | `boolean` | `false` | Show popup with feature properties when selected |
170
+ | `fitBoundsOnLoad` | `boolean` | `true` | Auto-zoom to extent when loading GeoJSON |
155
171
  | `onFeatureCreate` | `(feature) => void` | - | Callback when feature is created |
156
172
  | `onFeatureEdit` | `(feature, oldFeature) => void` | - | Callback when feature is edited |
157
173
  | `onFeatureDelete` | `(featureId) => void` | - | Callback when feature is deleted |
158
174
  | `onSelectionChange` | `(features) => void` | - | Callback when selection changes |
159
175
  | `onModeChange` | `(mode) => void` | - | Callback when mode changes |
176
+ | `onGeoJsonLoad` | `(result) => void` | - | Callback when GeoJSON is loaded |
177
+ | `onGeoJsonSave` | `(result) => void` | - | Callback when GeoJSON is saved |
160
178
 
161
179
  ### Methods
162
180
 
@@ -181,6 +199,14 @@ geoEditor.deleteSelectedFeatures();
181
199
  geoEditor.getFeatures();
182
200
  geoEditor.getAllFeatureCollection();
183
201
 
202
+ // File operations
203
+ geoEditor.openFileDialog(); // Open file picker dialog
204
+ geoEditor.loadGeoJson(geoJson); // Load GeoJSON programmatically
205
+ geoEditor.saveGeoJson('filename.geojson'); // Save/download GeoJSON
206
+
207
+ // Map view
208
+ geoEditor.fitToAllFeatures(); // Zoom map to show all features
209
+
184
210
  // Operation snapshots
185
211
  geoEditor.getLastCreatedFeature();
186
212
  geoEditor.getLastEditedFeature();
@@ -211,6 +237,16 @@ map.getContainer().addEventListener('gm:simplify', (e) => {
211
237
  map.getContainer().addEventListener('gm:lassoend', (e) => {
212
238
  console.log('Lasso selection:', e.detail);
213
239
  });
240
+
241
+ map.getContainer().addEventListener('gm:geojsonload', (e) => {
242
+ console.log('GeoJSON loaded:', e.detail);
243
+ // detail: { features, count, filename }
244
+ });
245
+
246
+ map.getContainer().addEventListener('gm:geojsonsave', (e) => {
247
+ console.log('GeoJSON saved:', e.detail);
248
+ // detail: { featureCollection, count, filename }
249
+ });
214
250
  ```
215
251
 
216
252
  ## Keyboard Shortcuts
@@ -238,6 +274,7 @@ import {
238
274
  DifferenceFeature,
239
275
  ScaleFeature,
240
276
  SplitFeature,
277
+ FreehandFeature,
241
278
  } from 'maplibre-gl-geo-editor';
242
279
 
243
280
  // Union polygons