Use OSM-based map image

This commit is contained in:
Kumi 2021-04-19 12:51:28 +02:00
parent 1e66e294a8
commit 2c1b5c844e
4 changed files with 19 additions and 19 deletions

View file

@ -1,4 +0,0 @@
libpq-dev
build-essential
libpython3-dev
postgis

5
debian_setup.sh Normal file
View 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

View file

@ -1,24 +1,22 @@
from django import template from django import template
import requests
import base64 import base64
import io
from staticmap import StaticMap, CircleMarker
from dbsettings.models import Setting from dbsettings.models import Setting
register = template.Library() register = template.Library()
@register.simple_tag @register.simple_tag
def mapimage(location, zoom=8, width=348, height=250): def mapimage(location, zoom=7, width=348, height=250):
payload = { smap = StaticMap(width, height, url_template="http://a.tile.osm.org/{z}/{x}/{y}.png")
'center': f"{location.y},{location.x}", marker = CircleMarker((location.x, location.y), color="orange", width=20)
'zoom': str(zoom), smap.add_marker(marker)
"size": "%ix%i" % (width, height), image = smap.render(zoom)
'sensor': "false", bio = io.BytesIO()
'key': Setting.objects.get(key="google.api.key").value # pylint: disable=no-member image.save(bio, format="JPEG")
}
r = requests.get('https://maps.googleapis.com/maps/api/staticmap', params=payload)
image = r.content
data_uri = 'data:image/jpg;base64,' 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 return data_uri

View file

@ -3,7 +3,6 @@ django-polymorphic
psycopg2 psycopg2
dbsettings dbsettings
django-bootstrap4 django-bootstrap4
pyinvoice
django-countries django-countries
paypal-checkout-serversdk paypal-checkout-serversdk
python-dateutil python-dateutil
@ -16,3 +15,5 @@ django-phonenumber-field
phonenumbers phonenumbers
googlemaps googlemaps
Babel Babel
staticmap
git+https://kumig.it/kumisystems/PyInvoice