diff --git a/src/c3nav/editor/static/editor/js/editor.js b/src/c3nav/editor/static/editor/js/editor.js index 6a8a9e50..9f5dacc0 100644 --- a/src/c3nav/editor/static/editor/js/editor.js +++ b/src/c3nav/editor/static/editor/js/editor.js @@ -63,7 +63,7 @@ editor = { for (var i = 0; i < sources.length; i++) { source = sources[i]; editor.sources[source.id] = source; - source.layer = L.imageOverlay('/api/sources/'+source.id+'/image/', source.bounds, {opacity: 0.3}); + source.layer = L.imageOverlay('/api/sources/'+source.id+'/image/', L.GeoJSON.coordsToLatLngs(source.bounds), {opacity: 0.3}); editor._sources_control.addOverlay(source.layer, source.name); } if (sources.length) editor._sources_control.addTo(editor.map); @@ -322,8 +322,9 @@ editor = { $.getJSON('/api/editor/geometrystyles/', function(geometrystyles) { editor.geometrystyles = geometrystyles; $.getJSON('/api/editor/bounds/', function(bounds) { - editor.map.setMaxBounds(bounds.bounds); - editor.map.fitBounds(bounds.bounds, {padding: [30, 50]}); + bounds = L.GeoJSON.coordsToLatLngs(bounds.bounds); + editor.map.setMaxBounds(bounds); + editor.map.fitBounds(bounds, {padding: [30, 50]}); editor.init_sidebar(); }); }); diff --git a/src/c3nav/mapdata/cache.py b/src/c3nav/mapdata/cache.py index a4b4de33..08f9ec81 100644 --- a/src/c3nav/mapdata/cache.py +++ b/src/c3nav/mapdata/cache.py @@ -207,7 +207,7 @@ class MapHistory: def to_image(self): from c3nav.mapdata.models import Source - (miny, minx), (maxy, maxx) = Source.max_bounds() + (minx, miny), (maxx, maxy) = Source.max_bounds() height, width = self.data.shape image_data = np.zeros((int(math.ceil((maxy-miny)/self.resolution)), diff --git a/src/c3nav/mapdata/models/base.py b/src/c3nav/mapdata/models/base.py index 308fab57..bcbb2965 100644 --- a/src/c3nav/mapdata/models/base.py +++ b/src/c3nav/mapdata/models/base.py @@ -82,10 +82,10 @@ class BoundsMixin(SerializableMixin, models.Model): result = cache.get(cache_key, None) if result is not None: return result - result = cls.objects.all().aggregate(models.Min('bottom'), models.Min('left'), - models.Max('top'), models.Max('right')) - result = ((float(result['bottom__min']), float(result['left__min'])), - (float(result['top__max']), float(result['right__max']))) + result = cls.objects.all().aggregate(models.Min('left'), models.Min('bottom'), + models.Max('right'), models.Max('top')) + result = ((float(result['left__min']), float(result['bottom__min'])), + (float(result['right__max']), float(result['top__max']))) cache.set(cache_key, result, 900) return result @@ -97,4 +97,4 @@ class BoundsMixin(SerializableMixin, models.Model): @property def bounds(self): # noinspection PyTypeChecker - return (float(self.bottom), float(self.left)), (float(self.top), float(self.right)) + return (float(self.left), float(self.bottom)), (float(self.right), float(self.top)) diff --git a/src/c3nav/mapdata/render/svg.py b/src/c3nav/mapdata/render/svg.py index bd93412e..3131482d 100644 --- a/src/c3nav/mapdata/render/svg.py +++ b/src/c3nav/mapdata/render/svg.py @@ -11,12 +11,12 @@ from c3nav.mapdata.utils.svg import SVGImage class SVGRenderer: - def __init__(self, level, miny, minx, maxy, maxx, scale=1, access_permissions=None): + def __init__(self, level, minx, miny, maxx, maxy, scale=1, access_permissions=None): self.level = level - self.miny = miny self.minx = minx - self.maxy = maxy + self.miny = miny self.maxx = maxx + self.maxy = maxy self.scale = scale self.access_permissions = access_permissions @@ -61,7 +61,7 @@ class SVGRenderer: return self.update_cache_key + ':' + self.access_cache_key def render(self): - svg = SVGImage(bounds=((self.miny, self.minx), (self.maxy, self.maxx)), scale=self.scale, buffer=1) + svg = SVGImage(bounds=((self.minx, self.miny), (self.maxx, self.maxy)), scale=self.scale, buffer=1) # add no access restriction to “unlocked“ access restrictions so lookup gets easier unlocked_access_restrictions = self.unlocked_access_restrictions | set([None]) diff --git a/src/c3nav/mapdata/utils/svg.py b/src/c3nav/mapdata/utils/svg.py index ea3d4759..32abe19f 100644 --- a/src/c3nav/mapdata/utils/svg.py +++ b/src/c3nav/mapdata/utils/svg.py @@ -39,7 +39,7 @@ class SVGImage: def __init__(self, bounds, scale: float=1, buffer=0): # get image dimensions. # note that these values describe the „viewport“ of the image, not its dimensions in pixels. - (self.bottom, self.left), (self.top, self.right) = bounds + (self.left, self.bottom), (self.right, self.top) = bounds self.width = self.right-self.left self.height = self.top-self.bottom self.scale = scale diff --git a/src/c3nav/mapdata/views.py b/src/c3nav/mapdata/views.py index e9450c74..d1f03690 100644 --- a/src/c3nav/mapdata/views.py +++ b/src/c3nav/mapdata/views.py @@ -1,5 +1,6 @@ import hashlib import os +from itertools import chain from django.conf import settings from django.core.cache import cache @@ -33,7 +34,7 @@ def tile(request, level, zoom, x, y, format): # error 404 if tiles is out of bounds bounds = Source.max_bounds() - if not box(bounds[0][1], bounds[0][0], bounds[1][1], bounds[1][0]).intersects(box(minx, miny, maxx, maxy)): + if not box(*chain(*bounds)).intersects(box(minx, miny, maxx, maxy)): raise Http404 # is this a valid level? @@ -46,7 +47,7 @@ def tile(request, level, zoom, x, y, format): access_permissions = get_tile_access_cookie(request) # init renderer - renderer = SVGRenderer(level, miny, minx, maxy, maxx, scale=2**zoom, access_permissions=access_permissions) + renderer = SVGRenderer(level, minx, miny, maxx, maxy, scale=2**zoom, access_permissions=access_permissions) tile_cache_key = renderer.cache_key update_cache_key = renderer.update_cache_key diff --git a/src/c3nav/site/static/site/js/c3nav.js b/src/c3nav/site/static/site/js/c3nav.js index 1c5ea795..f3202ed5 100644 --- a/src/c3nav/site/static/site/js/c3nav.js +++ b/src/c3nav/site/static/site/js/c3nav.js @@ -259,7 +259,7 @@ c3nav = { maxZoom: 10, minZoom: 0, crs: L.CRS.Simple, - maxBounds: c3nav.bounds, + maxBounds: L.GeoJSON.coordsToLatLngs(c3nav.bounds), closePopupOnClick: false, zoomControl: false });