| [5e16955] | 1 | '''
|
|---|
| 2 | Copyright (C) 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 3 |
|
|---|
| 4 | This program is free software: you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 16 | '''
|
|---|
| 17 |
|
|---|
| 18 | import connexion
|
|---|
| 19 | import flask
|
|---|
| 20 | import os
|
|---|
| 21 |
|
|---|
| 22 | from ..HttpErrors import MapserviceInternalServerError, MapserviceBadRequest, MapserviceNotFound
|
|---|
| 23 |
|
|---|
| 24 | def tiles_tile_get(accuracy, resolution, zoom, x_tile, y_tile):
|
|---|
| 25 | if not 'TILES_CACHE_PATH' in flask.current_app.config or not os.access(flask.current_app.config['TILES_CACHE_PATH'], os.R_OK):
|
|---|
| 26 | raise MapserviceInternalServerError(detail='TILES_CACHE_PATH not configured or not accessible')
|
|---|
| 27 | tiles_cache_path = flask.current_app.config['TILES_CACHE_PATH']
|
|---|
| 28 |
|
|---|
| 29 | if not 'TILES_DENSITIES' in flask.current_app.config:
|
|---|
| 30 | raise MapserviceInternalServerError(details='TILES_DENSITIES not configured')
|
|---|
| 31 | tiles_densities = flask.current_app.config['TILES_DENSITIES']
|
|---|
| 32 |
|
|---|
| 33 | if not 'TILES_DENSITY_BASEE' in flask.current_app.config:
|
|---|
| 34 | raise MapserviceInternalServerError(details='TILES_DENSITY_BASEE not configured')
|
|---|
| 35 | tiles_densitiy_base = flask.current_app.config['TILES_DENSITY_BASEE']
|
|---|
| 36 |
|
|---|
| [c5ca247] | 37 | if not 'TILES_SKIP_EMPTY' in flask.current_app.config:
|
|---|
| 38 | raise MapserviceInternalServerError(details='TILES_SKIP_EMPTY not configured')
|
|---|
| 39 | tiles_skip_empty = flask.current_app.config['TILES_SKIP_EMPTY']
|
|---|
| 40 |
|
|---|
| [5e16955] | 41 | if accuracy == 'high':
|
|---|
| 42 | accuracy = '{}_{}'.format(max(tiles_densities), tiles_densitiy_base)
|
|---|
| 43 | elif accuracy == 'low':
|
|---|
| 44 | accuracy = '{}_{}'.format(min(tiles_densities), tiles_densitiy_base)
|
|---|
| 45 | else:
|
|---|
| 46 | raise MapserviceBadRequest(details='No valid accuracy requested. Valid are high, low. Requested was: {}'.format(accuracy))
|
|---|
| 47 |
|
|---|
| [c5ca247] | 48 | tile__empty_path = os.path.join(tiles_cache_path, '{}/{}/empty_tile.png'.format(accuracy, resolution))
|
|---|
| [5e16955] | 49 | tile_path = os.path.join(tiles_cache_path, '{}/{}/{}/{}/{}.png'.format(accuracy, resolution, zoom, x_tile, y_tile))
|
|---|
| 50 | if not os.path.isfile(tile_path):
|
|---|
| [c5ca247] | 51 | if not tiles_skip_empty or not os.path.isfile(tile__empty_path):
|
|---|
| 52 | raise MapserviceNotFound(detail='Tile ({}, {}) for accuracy {} with resolution {} at zoomlevel {} not found'.format(x_tile, y_tile, accuracy, resolution, zoom))
|
|---|
| 53 | tile_path = tile__empty_path
|
|---|
| 54 |
|
|---|
| 55 | response = flask.send_file(tile_path, mimetype='image/png', as_attachment=True, attachment_filename='{}.png'.format(y_tile))
|
|---|
| 56 | response.direct_passthrough = False
|
|---|
| 57 | #response.headers['Content-Transfer-Encoding']='base64'
|
|---|
| 58 | return response
|
|---|