flip every y,x to x,y
This commit is contained in:
parent
cce476c37a
commit
a3be7b2842
7 changed files with 19 additions and 17 deletions
|
@ -63,7 +63,7 @@ editor = {
|
||||||
for (var i = 0; i < sources.length; i++) {
|
for (var i = 0; i < sources.length; i++) {
|
||||||
source = sources[i];
|
source = sources[i];
|
||||||
editor.sources[source.id] = source;
|
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);
|
editor._sources_control.addOverlay(source.layer, source.name);
|
||||||
}
|
}
|
||||||
if (sources.length) editor._sources_control.addTo(editor.map);
|
if (sources.length) editor._sources_control.addTo(editor.map);
|
||||||
|
@ -322,8 +322,9 @@ editor = {
|
||||||
$.getJSON('/api/editor/geometrystyles/', function(geometrystyles) {
|
$.getJSON('/api/editor/geometrystyles/', function(geometrystyles) {
|
||||||
editor.geometrystyles = geometrystyles;
|
editor.geometrystyles = geometrystyles;
|
||||||
$.getJSON('/api/editor/bounds/', function(bounds) {
|
$.getJSON('/api/editor/bounds/', function(bounds) {
|
||||||
editor.map.setMaxBounds(bounds.bounds);
|
bounds = L.GeoJSON.coordsToLatLngs(bounds.bounds);
|
||||||
editor.map.fitBounds(bounds.bounds, {padding: [30, 50]});
|
editor.map.setMaxBounds(bounds);
|
||||||
|
editor.map.fitBounds(bounds, {padding: [30, 50]});
|
||||||
editor.init_sidebar();
|
editor.init_sidebar();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -207,7 +207,7 @@ class MapHistory:
|
||||||
|
|
||||||
def to_image(self):
|
def to_image(self):
|
||||||
from c3nav.mapdata.models import Source
|
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
|
height, width = self.data.shape
|
||||||
image_data = np.zeros((int(math.ceil((maxy-miny)/self.resolution)),
|
image_data = np.zeros((int(math.ceil((maxy-miny)/self.resolution)),
|
||||||
|
|
|
@ -82,10 +82,10 @@ class BoundsMixin(SerializableMixin, models.Model):
|
||||||
result = cache.get(cache_key, None)
|
result = cache.get(cache_key, None)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
return result
|
return result
|
||||||
result = cls.objects.all().aggregate(models.Min('bottom'), models.Min('left'),
|
result = cls.objects.all().aggregate(models.Min('left'), models.Min('bottom'),
|
||||||
models.Max('top'), models.Max('right'))
|
models.Max('right'), models.Max('top'))
|
||||||
result = ((float(result['bottom__min']), float(result['left__min'])),
|
result = ((float(result['left__min']), float(result['bottom__min'])),
|
||||||
(float(result['top__max']), float(result['right__max'])))
|
(float(result['right__max']), float(result['top__max'])))
|
||||||
cache.set(cache_key, result, 900)
|
cache.set(cache_key, result, 900)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -97,4 +97,4 @@ class BoundsMixin(SerializableMixin, models.Model):
|
||||||
@property
|
@property
|
||||||
def bounds(self):
|
def bounds(self):
|
||||||
# noinspection PyTypeChecker
|
# 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))
|
||||||
|
|
|
@ -11,12 +11,12 @@ from c3nav.mapdata.utils.svg import SVGImage
|
||||||
|
|
||||||
|
|
||||||
class SVGRenderer:
|
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.level = level
|
||||||
self.miny = miny
|
|
||||||
self.minx = minx
|
self.minx = minx
|
||||||
self.maxy = maxy
|
self.miny = miny
|
||||||
self.maxx = maxx
|
self.maxx = maxx
|
||||||
|
self.maxy = maxy
|
||||||
self.scale = scale
|
self.scale = scale
|
||||||
self.access_permissions = access_permissions
|
self.access_permissions = access_permissions
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class SVGRenderer:
|
||||||
return self.update_cache_key + ':' + self.access_cache_key
|
return self.update_cache_key + ':' + self.access_cache_key
|
||||||
|
|
||||||
def render(self):
|
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
|
# add no access restriction to “unlocked“ access restrictions so lookup gets easier
|
||||||
unlocked_access_restrictions = self.unlocked_access_restrictions | set([None])
|
unlocked_access_restrictions = self.unlocked_access_restrictions | set([None])
|
||||||
|
|
|
@ -39,7 +39,7 @@ class SVGImage:
|
||||||
def __init__(self, bounds, scale: float=1, buffer=0):
|
def __init__(self, bounds, scale: float=1, buffer=0):
|
||||||
# get image dimensions.
|
# get image dimensions.
|
||||||
# note that these values describe the „viewport“ of the image, not its dimensions in pixels.
|
# 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.width = self.right-self.left
|
||||||
self.height = self.top-self.bottom
|
self.height = self.top-self.bottom
|
||||||
self.scale = scale
|
self.scale = scale
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache import cache
|
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
|
# error 404 if tiles is out of bounds
|
||||||
bounds = Source.max_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
|
raise Http404
|
||||||
|
|
||||||
# is this a valid level?
|
# is this a valid level?
|
||||||
|
@ -46,7 +47,7 @@ def tile(request, level, zoom, x, y, format):
|
||||||
access_permissions = get_tile_access_cookie(request)
|
access_permissions = get_tile_access_cookie(request)
|
||||||
|
|
||||||
# init renderer
|
# 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
|
tile_cache_key = renderer.cache_key
|
||||||
update_cache_key = renderer.update_cache_key
|
update_cache_key = renderer.update_cache_key
|
||||||
|
|
||||||
|
|
|
@ -259,7 +259,7 @@ c3nav = {
|
||||||
maxZoom: 10,
|
maxZoom: 10,
|
||||||
minZoom: 0,
|
minZoom: 0,
|
||||||
crs: L.CRS.Simple,
|
crs: L.CRS.Simple,
|
||||||
maxBounds: c3nav.bounds,
|
maxBounds: L.GeoJSON.coordsToLatLngs(c3nav.bounds),
|
||||||
closePopupOnClick: false,
|
closePopupOnClick: false,
|
||||||
zoomControl: false
|
zoomControl: false
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue