initial level and initial bounds
This commit is contained in:
parent
a006d8a9ec
commit
19cd24f389
4 changed files with 35 additions and 3 deletions
|
@ -81,6 +81,17 @@ SVG_RENDERER = config.get('c3nav', 'svg_renderer', fallback='rsvg-convert')
|
|||
CACHE_TILES = config.get('c3nav', 'cache_tiles', fallback=not DEBUG)
|
||||
CACHE_RESOLUTION = config.get('c3nav', 'cache_resolution', fallback=4)
|
||||
|
||||
INITIAL_LEVEL = config.get('c3nav', 'initial_level', fallback=None)
|
||||
INITIAL_BOUNDS = config.get('c3nav', 'initial_bounds', fallback=None).split(' ')
|
||||
|
||||
if len(INITIAL_BOUNDS) == 4:
|
||||
try:
|
||||
INITIAL_BOUNDS = tuple(float(i) for i in INITIAL_BOUNDS)
|
||||
except ValueError:
|
||||
INITIAL_BOUNDS = None
|
||||
else:
|
||||
INITIAL_BOUNDS = None
|
||||
|
||||
db_backend = config.get('database', 'backend', fallback='sqlite3')
|
||||
DATABASES = {
|
||||
'default': {
|
||||
|
|
|
@ -907,6 +907,20 @@ c3nav = {
|
|||
c3nav.levels = JSON.parse($map.attr('data-levels'));
|
||||
c3nav.tile_server = $map.attr('data-tile-server');
|
||||
|
||||
if ($map.is('[data-initial-bounds]')) {
|
||||
var bounds = JSON.parse($map.attr('data-initial-bounds'));
|
||||
bounds = [bounds.slice(0, 2), bounds.slice(2)];
|
||||
c3nav.initial_bounds = bounds;
|
||||
} else {
|
||||
c3nav.initial_bounds = c3nav.bounds
|
||||
}
|
||||
|
||||
if ($map.is('[data-initial-level]')) {
|
||||
c3nav.initial_level = parseInt($map.attr('data-initial-level'));
|
||||
} else {
|
||||
c3nav.initial_level = c3nav.levels[0][0];
|
||||
}
|
||||
|
||||
c3nav.level_labels_by_id = {};
|
||||
for (i = 0; i < c3nav.levels.length; i ++) {
|
||||
c3nav.level_labels_by_id[c3nav.levels[i][0]] = c3nav.levels[i][1];
|
||||
|
@ -933,7 +947,7 @@ c3nav = {
|
|||
$('.leaflet-touch').removeClass('leaflet-touch');
|
||||
}
|
||||
|
||||
c3nav.map.fitBounds(L.GeoJSON.coordsToLatLngs(c3nav.bounds), c3nav._add_map_padding({}));
|
||||
c3nav.map.fitBounds(L.GeoJSON.coordsToLatLngs(c3nav.initial_bounds), c3nav._add_map_padding({}));
|
||||
|
||||
c3nav.map.on('moveend', c3nav._map_moved);
|
||||
c3nav.map.on('zoomend', c3nav._map_zoomed);
|
||||
|
@ -960,7 +974,7 @@ c3nav = {
|
|||
c3nav._routeLayers[level[0]] = L.layerGroup().addTo(layerGroup);
|
||||
}
|
||||
c3nav._levelControl.finalize();
|
||||
c3nav._levelControl.setLevel(c3nav.levels[0][0]);
|
||||
c3nav._levelControl.setLevel(c3nav.initial_level);
|
||||
|
||||
c3nav.map.on('click', c3nav._click_anywhere);
|
||||
|
||||
|
|
|
@ -15,7 +15,12 @@
|
|||
<a href="https://twitter.com/c3nav/" rel="external" target="_blank">Twitter</a> //
|
||||
<a href="https://github.com/c3nav/c3nav/" rel="external" target="_blank">GitHub</a>
|
||||
</section>
|
||||
<section id="map" data-bounds="{{ bounds }}" data-levels="{{ levels }}"{% if tile_cache_server %} data-tile-server="{{ tile_cache_server }}"{% endif %}></section>
|
||||
<section id="map" data-bounds="{{ bounds }}"
|
||||
data-levels="{{ levels }}"
|
||||
{% if tile_cache_server %}data-tile-server="{{ tile_cache_server }}"{% endif %}
|
||||
{% if initial_level %}data-initial-level="{{ initial_level }}"{% endif %}
|
||||
{% if initial_bounds %}data-initial-bounds="{{ initial_bounds }}"{% endif %}>
|
||||
</section>
|
||||
{% if not embed %}
|
||||
<section id="messages">{% include 'site/fragment_messages.html' %}</section>
|
||||
<section id="popup-buttons">
|
||||
|
|
|
@ -118,6 +118,8 @@ def map_index(request, mode=None, slug=None, slug2=None, details=None, options=N
|
|||
'levels': json.dumps(tuple((level.pk, level.short_label) for level in levels.values()), separators=(',', ':')),
|
||||
'state': json.dumps(state, separators=(',', ':'), cls=DjangoJSONEncoder),
|
||||
'tile_cache_server': settings.TILE_CACHE_SERVER,
|
||||
'initial_level': settings.INITIAL_LEVEL,
|
||||
'initial_bounds': json.dumps(settings.INITIAL_BOUNDS, separators=(',', ':')),
|
||||
'embed': bool(embed),
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue