Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce33e15a59 | ||
|
|
539aa0fcf8 | ||
|
|
880bca3501 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
*.egg-info/
|
||||||
|
|
||||||
dist-env/
|
dist-env/
|
||||||
dist/
|
dist/
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
@@ -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>
|
||||||
2
setup.py
2
setup.py
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user