fix editor bounds when no sources area accessible for the user

This commit is contained in:
Laura Klünder 2017-07-13 23:37:48 +02:00
parent 1a8c62956d
commit 0393a72c91
2 changed files with 16 additions and 14 deletions

View file

@ -9,7 +9,7 @@ from rest_framework.viewsets import ReadOnlyModelViewSet, ViewSet
from shapely.ops import cascaded_union
from c3nav.editor.models import ChangeSet
from c3nav.mapdata.models import Area
from c3nav.mapdata.models import Area, Source
from c3nav.mapdata.models.geometry.space import POI
@ -173,6 +173,12 @@ class EditorViewSet(ViewSet):
'shadow': '#000000',
})
@list_route(methods=['get'])
def bounds(self, request, *args, **kwargs):
return Response({
'bounds': Source.max_bounds(),
})
class ChangeSetViewSet(ReadOnlyModelViewSet):
"""

View file

@ -54,28 +54,19 @@ editor = {
// sources
sources: {},
get_sources: function (init_sidebar) {
get_sources: function () {
// load sources
editor._sources_control = L.control.layers([], [], {autoZIndex: true}).addTo(editor.map);
editor._sources_control = L.control.layers([], [], {autoZIndex: true});
$.getJSON('/api/sources/', function (sources) {
var bounds = [[0, 0], [0, 0]];
var source;
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});
editor._sources_control.addOverlay(source.layer, source.name);
bounds[0][0] = Math.min(source.bounds[0][0], bounds[0][0]);
bounds[0][1] = Math.min(source.bounds[0][1], bounds[0][1]);
bounds[1][0] = Math.max(source.bounds[1][0], bounds[1][0]);
bounds[1][1] = Math.max(source.bounds[1][1], bounds[1][1]);
}
editor.map.setMaxBounds(bounds);
if (init_sidebar) {
editor.map.fitBounds(bounds, {padding: [30, 50]});
editor.init_sidebar();
}
if (sources.length) editor._sources_control.addTo(editor.map);
});
},
@ -270,8 +261,13 @@ editor = {
$.getJSON('/api/editor/geometrystyles/', function(geometrystyles) {
editor.geometrystyles = geometrystyles;
editor.get_sources(true);
$.getJSON('/api/editor/bounds/', function(bounds) {
editor.map.setMaxBounds(bounds.bounds);
editor.map.fitBounds(bounds.bounds, {padding: [30, 50]});
editor.init_sidebar();
});
});
editor.get_sources();
},
_last_geometry_url: null,
load_geometries: function (geometry_url, highlight_type, editing_id) {