|
| 1 | +# Geoman |
| 2 | + |
| 3 | +The Geoman plugin provides an interactive drawing and editing interface for polygons, polylines, circles, and other geometric shapes on your Folium map. It's based on the [Leaflet-Geoman](https://github.com/geoman-io/leaflet-geoman/) library. |
| 4 | + |
| 5 | +## Basic Usage |
| 6 | + |
| 7 | +```{code-cell} ipython3 |
| 8 | +import folium |
| 9 | +from folium.plugins import GeoMan |
| 10 | +
|
| 11 | +# Create a map |
| 12 | +m = folium.Map(location=[45.5236, -122.6750], zoom_start=13) |
| 13 | +
|
| 14 | +# Add Geoman plugin |
| 15 | +GeoMan().add_to(m) |
| 16 | +
|
| 17 | +m |
| 18 | +``` |
| 19 | + |
| 20 | +## Customizing Controls |
| 21 | + |
| 22 | +You can customize which drawing controls are available and their position: |
| 23 | + |
| 24 | +```{code-cell} ipython3 |
| 25 | +import folium |
| 26 | +from folium.plugins import GeoMan |
| 27 | +
|
| 28 | +m = folium.Map(location=[45.5236, -122.6750], zoom_start=13) |
| 29 | +
|
| 30 | +# Add Geoman with custom options |
| 31 | +GeoMan( |
| 32 | + position='topright', |
| 33 | + drawMarker=True, |
| 34 | + drawCircleMarker=True, |
| 35 | + drawPolyline=True, |
| 36 | + drawRectangle=True, |
| 37 | + drawPolygon=True, |
| 38 | + drawCircle=True, |
| 39 | + drawText=False, |
| 40 | + editMode=True, |
| 41 | + dragMode=True, |
| 42 | + cutPolygon=True, |
| 43 | + removalMode=True, |
| 44 | + rotateMode=False |
| 45 | +).add_to(m) |
| 46 | +
|
| 47 | +m |
| 48 | +``` |
| 49 | + |
| 50 | +## Available Methods |
| 51 | + |
| 52 | +The GeoMan plugin provides several methods for programmatic control: |
| 53 | + |
| 54 | +### Drawing Controls |
| 55 | +- `enable_draw(shape, **kwargs)`: Enable drawing mode for a specific shape |
| 56 | +- `disable_draw()`: Disable drawing mode |
| 57 | +- `set_path_options(**options)`: Set default styling options for drawn shapes |
| 58 | + |
| 59 | +### Edit Controls |
| 60 | +- `enable_global_edit_mode(**options)`: Enable edit mode for all shapes |
| 61 | +- `disable_global_edit_mode()`: Disable edit mode |
| 62 | +- `enable_global_drag_mode()`: Enable drag mode for all shapes |
| 63 | +- `disable_global_drag_mode()`: Disable drag mode |
| 64 | + |
| 65 | +### Other Controls |
| 66 | +- `enable_global_removal_mode()`: Enable removal mode |
| 67 | +- `disable_global_removal_mode()`: Disable removal mode |
| 68 | +- `enable_global_cut_mode()`: Enable polygon cutting mode |
| 69 | +- `disable_global_cut_mode()`: Disable polygon cutting mode |
| 70 | +- `enable_global_rotation_mode()`: Enable rotation mode |
| 71 | +- `disable_global_rotation_mode()`: Disable rotation mode |
| 72 | + |
| 73 | +## Configuration Options |
| 74 | + |
| 75 | +The GeoMan plugin accepts the following parameters: |
| 76 | + |
| 77 | +- `position` (str): Position of the toolbar ('topleft', 'topright', 'bottomleft', 'bottomright') |
| 78 | +- `feature_group` (FeatureGroup): Feature group to store drawn items |
| 79 | +- `on` (dict): Event handlers for drawing events |
| 80 | +- `drawMarker` (bool): Enable/disable marker drawing |
| 81 | +- `drawCircleMarker` (bool): Enable/disable circle marker drawing |
| 82 | +- `drawPolyline` (bool): Enable/disable polyline drawing |
| 83 | +- `drawRectangle` (bool): Enable/disable rectangle drawing |
| 84 | +- `drawPolygon` (bool): Enable/disable polygon drawing |
| 85 | +- `drawCircle` (bool): Enable/disable circle drawing |
| 86 | +- `drawText` (bool): Enable/disable text drawing |
| 87 | +- `editMode` (bool): Enable/disable edit mode |
| 88 | +- `dragMode` (bool): Enable/disable drag mode |
| 89 | +- `cutPolygon` (bool): Enable/disable polygon cutting |
| 90 | +- `removalMode` (bool): Enable/disable removal mode |
| 91 | +- `rotateMode` (bool): Enable/disable rotation mode |
| 92 | + |
| 93 | +For more advanced usage and configuration options, refer to the [Leaflet-Geoman documentation](https://geoman.io/docs/leaflet). |
0 commit comments