3 Commits
v0.9 ... v0.9.1

Author SHA1 Message Date
relikd
ce33e15a59 chore: bump version 2024-06-27 01:51:49 +02:00
relikd
539aa0fcf8 feat: add locate options 2024-06-27 01:51:33 +02:00
relikd
880bca3501 fix: options as json 2024-06-27 01:50:08 +02:00
6 changed files with 17 additions and 7 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
.DS_Store
__pycache__/
*.egg-info/
dist-env/
dist/

View File

@@ -32,6 +32,10 @@ class Place(models.Model):
# 'tileOptions': {
# attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
# },
# 'locate': {
# 'returnToPrevBounds': True,
# 'showPopup': False,
# },
})
```
@@ -44,6 +48,7 @@ class Place(models.Model):
| markerZoom | Initial zoom scale (on load) if a marker is set. (default: `18`)
| tileLayer | [TileLayer](https://leafletjs.com/reference.html#tilelayer) urlTemplate (default: `"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"`)
| tileOptions | [TileLayer Options](https://leafletjs.com/reference.html#tilelayer-option) (default: `{}`)
| locate | [Leaflet.Locate Options](https://github.com/domoritz/leaflet-locatecontrol#possible-options) (default: `{returnToPrevBounds: true, showPopup: false}`)
## Usage

View File

@@ -1,7 +1,9 @@
from typing import NamedTuple
from django.db import models
from django.forms import Widget
import json
from typing import NamedTuple
class Position(NamedTuple):
lat: float
@@ -24,10 +26,11 @@ class MapLocationWidget(Widget):
'leaflet/locate/L.Control.Locate.min.js',
'map-location.js']
# def get_context(self, name, value, attrs):
# context = super().get_context(name, value, attrs)
# context['id'] = attrs.get('id')
# return context
def get_context(self, name, value, attrs):
context = super().get_context(name, value, attrs)
context['map_options'] = json.dumps(
context['widget']['attrs'].get('options'))
return context
class LocationField(models.Field):

View File

@@ -17,6 +17,7 @@ function MapLocationInit(mapId, options = {}) {
L.control.locate({
returnToPrevBounds: true,
showPopup: false,
...(options.locate || {})
}).addTo(map);
function loadPos() {

View File

@@ -3,6 +3,6 @@
<div id="{{ widget.attrs.id }}_map" style="width: 100%; height: 400px"></div>
<a href="" id="{{ widget.attrs.id }}_reset">Remove</a>
<script>
MapLocationInit("{{ widget.attrs.id }}", {{ widget.attrs.options|safe }});
MapLocationInit("{{ widget.attrs.id }}", {{ map_options|safe }});
</script>
</div>

View File

@@ -6,7 +6,7 @@ with open('README.md', 'r') as f:
setuptools.setup(
name='django-map-location',
description='Django Map-Location Field',
version='0.9',
version='0.9.1',
author='relikd',
license='MIT',
long_description=long_description,