add settings to use external cached tile server

This commit is contained in:
Laura Klünder 2017-11-21 04:34:43 +01:00
parent 0fec7ff89c
commit 443d58965d
5 changed files with 17 additions and 8 deletions

View file

@ -27,8 +27,9 @@ def set_tile_access_cookie(func):
access_permissions = AccessPermission.get_for_request(request)
if access_permissions:
bla = build_tile_access_cookie(access_permissions, settings.SECRET_TILE_KEY)
response.set_cookie(settings.TILE_ACCESS_COOKIE_NAME, bla, max_age=60)
cookie = build_tile_access_cookie(access_permissions, settings.SECRET_TILE_KEY)
response.set_cookie(settings.TILE_ACCESS_COOKIE_NAME, cookie, max_age=60,
domain=settings.TILE_ACCESS_COOKIE_DOMAIN)
else:
response.delete_cookie(settings.TILE_ACCESS_COOKIE_NAME)

View file

@ -13,6 +13,8 @@ config = configparser.RawConfigParser()
config.read(['/etc/c3nav/c3nav.cfg', os.path.expanduser('~/.c3nav.cfg'), os.environ.get('C3NAV_CONFIG', 'c3nav.cfg')],
encoding='utf-8')
INSTANCE_NAME = config.get('c3nav', 'name', fallback='noname')
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DATA_DIR = config.get('c3nav', 'datadir', fallback=os.environ.get('DATA_DIR', 'data'))
@ -161,13 +163,16 @@ CELERY_RESULT_SERIALIZER = 'json'
SESSION_COOKIE_DOMAIN = config.get('c3nav', 'cookie_domain', fallback=None)
SESSION_COOKIE_SECURE = config.getboolean('c3nav', 'session_cookie_secure', fallback=False)
TILE_CACHE_SERVER = config.get('c3nav', 'tile_cache_server', fallback=None)
TILE_ACCESS_COOKIE_DOMAIN = config.get('c3nav', 'tile_access_cookie_domain', fallback=None)
# Internal settings
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static.dist')
SESSION_COOKIE_NAME = 'c3nav_session'
LANGUAGE_COOKIE_NAME = 'c3nav_language'
CSRF_COOKIE_NAME = 'c3nav_csrftoken'
TILE_ACCESS_COOKIE_NAME = 'c3nav_tile_access'
SESSION_COOKIE_NAME = 'c3nav_%s_session' % INSTANCE_NAME
LANGUAGE_COOKIE_NAME = 'c3nav_%s_language' % INSTANCE_NAME
CSRF_COOKIE_NAME = 'c3nav_%s_csrftoken' % INSTANCE_NAME
TILE_ACCESS_COOKIE_NAME = 'c3nav_%s_tile_access' % INSTANCE_NAME
SESSION_COOKIE_HTTPONLY = True
# Application definition

View file

@ -438,6 +438,7 @@ c3nav = {
var $map = $('#map'), i;
c3nav.bounds = JSON.parse($map.attr('data-bounds'));
c3nav.levels = JSON.parse($map.attr('data-levels'));
c3nav.tile_server = $map.attr('data-tile-server');
c3nav.level_labels_by_id = {};
for (i = 0; i < c3nav.levels.length; i ++) {
@ -630,7 +631,7 @@ LevelControl = L.Control.extend({
},
addLevel: function (id, title) {
this._tileLayers[id] = L.tileLayer('/map/' + String(id) + '/{z}/{x}/{y}.png', {
this._tileLayers[id] = L.tileLayer((c3nav.tile_server || '/map/') + String(id) + '/{z}/{x}/{y}.png', {
bounds: L.GeoJSON.coordsToLatLngs(c3nav.bounds)
});
var overlay = L.layerGroup();

View file

@ -27,7 +27,7 @@
<button class="button-clear as-destination">Route to here</button>
<button class="button-clear as-origin">Route from here</button>
</section>
<section id="map" data-bounds="{{ bounds }}" data-levels="{{ levels }}"></section>
<section id="map" data-bounds="{{ bounds }}" data-levels="{{ levels }}"{% if tile_cache_server %} data-tile-server="{{ tile_cache_server }}"{% endif %}></section>
<section id="sidebar">
<section id="search" class="loading">
<div class="location locationinput empty" id="origin-input">

View file

@ -5,6 +5,7 @@ from datetime import timedelta
from typing import Mapping, Optional
import qrcode
from django.conf import settings
from django.core.cache import cache
from django.http import Http404, HttpResponse, JsonResponse
from django.shortcuts import redirect, render
@ -145,6 +146,7 @@ def map_index(request, mode=None, slug=None, slug2=None, level=None, x=None, y=N
'bounds': json.dumps(Source.max_bounds(), separators=(',', ':')),
'levels': json.dumps(tuple(levels.values()), separators=(',', ':')),
'state': json.dumps(state, separators=(',', ':')),
'tile_cache_server': settings.TILE_CACHE_SERVER,
}
return render(request, 'site/map.html', ctx)