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 .DS_Store
__pycache__/ __pycache__/
*.egg-info/
dist-env/ dist-env/
dist/ dist/

View File

@@ -32,6 +32,10 @@ class Place(models.Model):
# 'tileOptions': { # 'tileOptions': {
# attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>', # 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`) | 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"`) | 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: `{}`) | 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 ## Usage

View File

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

View File

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

View File

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

View File

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