summaryrefslogtreecommitdiff
path: root/chimere/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/widgets.py')
-rw-r--r--chimere/widgets.py39
1 files changed, 32 insertions, 7 deletions
diff --git a/chimere/widgets.py b/chimere/widgets.py
index 328605f..2637145 100644
--- a/chimere/widgets.py
+++ b/chimere/widgets.py
@@ -22,6 +22,7 @@ Extra widgets and fields
"""
from django import conf
from django import forms
+from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from django.contrib.gis.db import models
from django.contrib.gis.geos import fromstr
@@ -42,7 +43,7 @@ def getMapJS(area_name=''):
settings.CHIMERE_DEFAULT_CENTER
js += u"var media_path = '%s';\n" % settings.MEDIA_URL
js += u"var static_path = '%s';\n" % settings.STATIC_URL
- js += u"var map_layer = %s;\n" % settings.CHIMERE_MAP_LAYER
+ js += u"var map_layer = %s;\n" % settings.CHIMERE_DEFAULT_MAP_LAYER
js += u"var restricted_extent;\n"
if area_name:
@@ -56,6 +57,28 @@ def getMapJS(area_name=''):
u"%s// !--></script>\n" % js
return js
+def get_map_layers(area_name=''):
+ from chimere.models import Area
+ area = None
+ if area_name:
+ try:
+ area = Area.objects.get(name=area_name)
+ except ObjectDoesNotExist:
+ pass
+ else:
+ try:
+ area = Area.objects.get(default=True)
+ except ObjectDoesNotExist:
+ pass
+ map_layers = []
+ if area and area.layers.count():
+ map_layers = [layer.layer_code for layer in area.layers.all()]
+ elif settings.CHIMERE_DEFAULT_MAP_LAYER:
+ map_layers = [settings.CHIMERE_DEFAULT_MAP_LAYER]
+ else:
+ map_layers = ["new OpenLayers.Layer.OSM.Mapnik('Mapnik')"]
+ return map_layers
+
class ChosenSelectWidget(forms.Select):
"""
Chosen select widget.
@@ -126,21 +149,21 @@ class PointChooserWidget(forms.TextInput):
value = None
else:
value = None
+ map_layers = get_map_layers(area_name)
js = """
var EPSG_DISPLAY_PROJECTION = epsg_display_projection = new OpenLayers.Projection('EPSG:%s');
var EPSG_PROJECTION = epsg_projection = new OpenLayers.Projection('EPSG:%s');
var chimere_init_options = {};
- chimere_init_options["map_layers"] = [new OpenLayers.Layer.OSM.Mapnik('Mapnik')];
+ chimere_init_options["map_layers"] = [%s];
chimere_init_options['dynamic_categories'] = false;
chimere_init_options['edition'] = true;
chimere_init_options["checked_categories"] = [];
""" % (settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
- settings.CHIMERE_EPSG_PROJECTION)
+ settings.CHIMERE_EPSG_PROJECTION,
+ ", ".join(map_layers))
#TODO: manage area
tpl = u"<script type='text/javascript'><!--\n"\
u"%s// !--></script>\n" % js
- #tpl += u'<script src="%schimere/js/edit_map.js"></script>\n' % \
- # settings.STATIC_URL
tpl += u"<div id='map_edit'></div>"\
u"<div id='live_lonlat'>"\
u" <p><label for='live_latitude'>%s</label>"\
@@ -197,17 +220,19 @@ class RouteChooserWidget(forms.TextInput):
Render a map and latitude, longitude information field
'''
tpl = getMapJS(area_name)
+ map_layers = get_map_layers(area_name)
js = """
var EPSG_DISPLAY_PROJECTION = epsg_display_projection = new OpenLayers.Projection('EPSG:%s');
var EPSG_PROJECTION = epsg_projection = new OpenLayers.Projection('EPSG:%s');
var chimere_init_options = {};
- chimere_init_options["map_layers"] = [new OpenLayers.Layer.OSM.Mapnik('Mapnik')];
+ chimere_init_options["map_layers"] = [%s];
chimere_init_options['dynamic_categories'] = false;
chimere_init_options['edition'] = true;
chimere_init_options['edition_type_is_route'] = true;
chimere_init_options["checked_categories"] = [];
""" % (settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
- settings.CHIMERE_EPSG_PROJECTION)
+ settings.CHIMERE_EPSG_PROJECTION,
+ ", ".join(map_layers))
tpl = u"<script type='text/javascript'><!--\n"\
u"%s// !--></script>\n" % js
#TODO: manage area