Map Picker
Click-to-pick location on a Leaflet/OSM map.
Preview
Arguments
map_picker(lat=51.5074, lng=-0.1278)
Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import MapPicker
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = MapPicker(lat=51.5074, lng=-0.1278)
@event_handler()
def set_location(self, value=None, **kwargs):
... # write to self.component; the re-render carries itmy_template.html
django
{{ component }}Events this component sends to the view: set_location.
Needs a client hook djust does not ship: dj-hook="MapPicker". The markup renders, but the interaction described above is yours to add — register window.djust.hooks.MapPicker = { mounted() { … } } before client.js loads (see the hooks guide).
Parameters
| Name | Type | Default |
|---|---|---|
| lat | float | 0.0 |
| lng | float | 0.0 |
| pick_event | str — renames the event; identity is `name` | 'set_location' |
| zoom | int | 13 |
| height | str | '400px' |
| custom_class | str | '' |
| **kwargs | — passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.map_picker | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 2 of this component's classes at line 2276, 2277. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |