flip every y,x to x,y

This commit is contained in:
Laura Klünder 2017-10-29 11:32:44 +01:00
parent cce476c37a
commit a3be7b2842
7 changed files with 19 additions and 17 deletions

View file

@ -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();
});
});

View file

@ -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)),

View file

@ -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))

View file

@ -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])

View file

@ -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

View file

@ -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

View file

@ -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
});