Skip to content

Commit

Permalink
Merge pull request #73 from geoadmin/develop
Browse files Browse the repository at this point in the history
New Release v1.8.0 - #minor
  • Loading branch information
rebert authored May 3, 2023
2 parents 147a098 + a746d43 commit 8787456
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
11 changes: 10 additions & 1 deletion app/helpers/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hashlib
import logging
import math
import re
from datetime import datetime

Expand Down Expand Up @@ -70,7 +71,15 @@ def set_cache_control(headers, restriction):
return headers


def get_closest_zoom(resolution, epsg):
def resolution_factor_at_latitude(latitude):
return math.cos(latitude * (math.pi / 180.0))


# Zoom is defined at the Equator for WebMercator, layer defined at the
# latitude of Switzerland have to be corrected.
def get_closest_zoom(resolution, epsg, latitude=0.0):
if int(epsg) == 3857:
resolution /= resolution_factor_at_latitude(latitude)
tilegrid = getTileGrid(int(epsg))()
return tilegrid.getClosestZoom(float(resolution))

Expand Down
2 changes: 1 addition & 1 deletion app/templates/Layers.xml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{% endfor %}
</Dimension>
<TileMatrixSetLink>
<TileMatrixSet>{{ epsg }}_{{ layer.resolution_max|get_closest_zoom(epsg) }}</TileMatrixSet>
<TileMatrixSet>{{ epsg }}_{{ layer.resolution_max|get_closest_zoom(epsg, latitude=standard_latitude) }}</TileMatrixSet>
</TileMatrixSetLink>
{# ## ATTENTION: s3 tiles have a row/col order, mapproxy ones the standard col/row #}
{% for format in layer.formats %}
Expand Down
5 changes: 4 additions & 1 deletion app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

logger = logging.getLogger(__name__)

STANDARD_LATITUDE_FOR_SWITZERLAND = 47.0


class GetCapabilities(View):
methods = ['GET']
Expand Down Expand Up @@ -107,7 +109,8 @@ def get_context(cls, models, epsg, lang):
'epsg': epsg,
'default_tile_matrix_set': get_default_tile_matrix_set(epsg),
'legend_base_url': app.config["LEGENDS_BASE_URL"],
'language': lang
'language': lang,
'standard_latitude': STANDARD_LATITUDE_FOR_SWITZERLAND
}
logger.debug('Data context created in %fs', time.time() - start)
return context

0 comments on commit 8787456

Please sign in to comment.