Use OSM-based map image
This commit is contained in:
parent
1e66e294a8
commit
2c1b5c844e
4 changed files with 19 additions and 19 deletions
|
@ -1,4 +0,0 @@
|
|||
libpq-dev
|
||||
build-essential
|
||||
libpython3-dev
|
||||
postgis
|
5
debian_setup.sh
Normal file
5
debian_setup.sh
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
apt install libpq-dev build-essential libpython3-dev postgis python3-pip python3-venv -y
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install -Ur requirements.txt
|
|
@ -1,24 +1,22 @@
|
|||
from django import template
|
||||
|
||||
import requests
|
||||
import base64
|
||||
import io
|
||||
|
||||
from staticmap import StaticMap, CircleMarker
|
||||
|
||||
from dbsettings.models import Setting
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.simple_tag
|
||||
def mapimage(location, zoom=8, width=348, height=250):
|
||||
payload = {
|
||||
'center': f"{location.y},{location.x}",
|
||||
'zoom': str(zoom),
|
||||
"size": "%ix%i" % (width, height),
|
||||
'sensor': "false",
|
||||
'key': Setting.objects.get(key="google.api.key").value # pylint: disable=no-member
|
||||
}
|
||||
|
||||
r = requests.get('https://maps.googleapis.com/maps/api/staticmap', params=payload)
|
||||
image = r.content
|
||||
def mapimage(location, zoom=7, width=348, height=250):
|
||||
smap = StaticMap(width, height, url_template="http://a.tile.osm.org/{z}/{x}/{y}.png")
|
||||
marker = CircleMarker((location.x, location.y), color="orange", width=20)
|
||||
smap.add_marker(marker)
|
||||
image = smap.render(zoom)
|
||||
bio = io.BytesIO()
|
||||
image.save(bio, format="JPEG")
|
||||
data_uri = 'data:image/jpg;base64,'
|
||||
data_uri += base64.b64encode(image).decode().replace('\n', '')
|
||||
data_uri += base64.b64encode(bio.getvalue()).decode().replace('\n', '')
|
||||
return data_uri
|
||||
|
|
|
@ -3,7 +3,6 @@ django-polymorphic
|
|||
psycopg2
|
||||
dbsettings
|
||||
django-bootstrap4
|
||||
pyinvoice
|
||||
django-countries
|
||||
paypal-checkout-serversdk
|
||||
python-dateutil
|
||||
|
@ -16,3 +15,5 @@ django-phonenumber-field
|
|||
phonenumbers
|
||||
googlemaps
|
||||
Babel
|
||||
staticmap
|
||||
git+https://kumig.it/kumisystems/PyInvoice
|
Loading…
Reference in a new issue