diff options
author | etienne <etienne@9215b0d5-fb2c-4bbd-8d3e-bd2e9090e864> | 2009-01-14 00:05:56 +0000 |
---|---|---|
committer | etienne <etienne@9215b0d5-fb2c-4bbd-8d3e-bd2e9090e864> | 2009-01-14 00:05:56 +0000 |
commit | 0d1b6ecd08c24cca9aa283fcb4f30a456899a5f3 (patch) | |
tree | 765ee8b20f577a8e6756c3403bf471451c9aa296 | |
parent | 5577411f505db728e778a9bda8cd8a958c805317 (diff) | |
download | Chimère-0d1b6ecd08c24cca9aa283fcb4f30a456899a5f3.tar.bz2 Chimère-0d1b6ecd08c24cca9aa283fcb4f30a456899a5f3.zip |
Keep zoom level and bounds between pages
git-svn-id: http://www.peacefrogs.net/svn/chimere/trunk@13 9215b0d5-fb2c-4bbd-8d3e-bd2e9090e864
-rw-r--r-- | main/actions.py | 5 | ||||
-rw-r--r-- | main/views.py | 4 | ||||
-rw-r--r-- | main/widgets.py | 2 | ||||
-rw-r--r-- | settings.py | 1 | ||||
-rw-r--r-- | static/base.js | 32 | ||||
-rw-r--r-- | static/edit_map.js | 6 | ||||
-rw-r--r-- | static/main_map.js | 6 | ||||
-rw-r--r-- | templates/base.html | 3 | ||||
-rw-r--r-- | templates/edit.html | 2 |
9 files changed, 47 insertions, 14 deletions
diff --git a/main/actions.py b/main/actions.py index 77f8a46..89ba987 100644 --- a/main/actions.py +++ b/main/actions.py @@ -29,5 +29,6 @@ class Action: def __init__(self, id, path, label): self.id, self.path, self.label = id, main_path + path, label -actions = [Action('view', '', _('View')), Action('edit', 'edit', _('Add')), - Action('edit_route', 'edit_route', _('Add route'))] +actions = [Action('view', '', _('View')), + Action('edit', 'edit', _('Add a new point of interest')), + Action('edit_route', 'edit_route', _('Add a new route'))] diff --git a/main/views.py b/main/views.py index 8c26a36..0aadb18 100644 --- a/main/views.py +++ b/main/views.py @@ -110,7 +110,6 @@ def editRoute(request): # If the form has been submited if request.method == 'POST': form = RouteForm(request.POST, request.FILES) - print request.POST # All validation rules pass if form.is_valid(): route = form.save() @@ -149,7 +148,6 @@ def submited(request, action): """ Successful submission page """ - print action response_dct = {'actions':actions, 'action_selected':action, 'media_path':settings.MEDIA_URL,} return render_to_response('submited.html', response_dct) @@ -186,4 +184,4 @@ def getGeoObjects(request, category_ids, status='A'): return HttpResponse('no results') data = '{"type": "FeatureCollection", "features":[%s]}' % \ ",".join([geo_object.getGeoJSON() for geo_object in geo_objects]) - return HttpResponse(data)
\ No newline at end of file + return HttpResponse(data) diff --git a/main/widgets.py b/main/widgets.py index 1e12c19..2f2154b 100644 --- a/main/widgets.py +++ b/main/widgets.py @@ -42,8 +42,6 @@ def getMapJS(): js += u"var centerLonLat = new OpenLayers.LonLat(%f,\ %f).transform(epsg_display_projection, epsg_projection);\n" % \ settings.DEFAULT_CENTER - js += u"var maxExtent = new OpenLayers.Bounds(%f, %f, %f, %f);\n" % \ - settings.MAP_BOUNDS js += u"var media_path = '%s';\n" % settings.MEDIA_URL js = u"""<script type="text/javascript"><!-- %s// !--></script> diff --git a/settings.py b/settings.py index 347ffbf..74b7995 100644 --- a/settings.py +++ b/settings.py @@ -3,7 +3,6 @@ ROOT_PATH = '/var/local/django/chimere/' # chimere specific -MAP_BOUNDS = (-20037508.34, -20037508.34, 20037508.34, 20037508.34) DEFAULT_CENTER = (-1.679444, 48.114722) EPSG_PROJECTION = 900913 EPSG_DISPLAY_PROJECTION = 4326 diff --git a/static/base.js b/static/base.js new file mode 100644 index 0000000..19b3945 --- /dev/null +++ b/static/base.js @@ -0,0 +1,32 @@ + +function saveExtent() { + /* save the current extent in a cookie */ + if(!map) return; + document.cookie = "MAP_EXTENT=" + map.getExtent().toArray().join('_') + + ';path="/"'; +} + +function getExtent() { + /* get the current extent from a cookie */ + var cookies = document.cookie.split(';'); + var map_extent; + for (i in cookies){ + var items = cookies[i].split('='); + if (items[0] == 'MAP_EXTENT') map_extent = items[1].split('_'); + } + return map_extent; +} + +function zoomToCurrentExtent(map){ + /* zoom to current extent */ + var current_extent = getExtent(); + if (OpenLayers && current_extent && current_extent.length == 4){ + extent = new OpenLayers.Bounds(current_extent[0], current_extent[1], + current_extent[2], current_extent[3]); + map.zoomToExtent(extent, true); + return true; + } + else{ + return; + } +}
\ No newline at end of file diff --git a/static/edit_map.js b/static/edit_map.js index 6aedc73..fa13dbb 100644 --- a/static/edit_map.js +++ b/static/edit_map.js @@ -58,7 +58,6 @@ function init(){ controls:[new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.Attribution()], - maxExtent: maxExtent, maxResolution: 156543.0399, units: 'm', projection: epsg_projection, @@ -67,7 +66,10 @@ function init(){ layerMarkers.setOpacity(0.5); map.addLayers([layerMapnik, layerMarkers]); map.events.register('click', map, setMarker); - map.setCenter(centerLonLat, 12); + /* zoom to the appropriate extent */ + if (!zoomToCurrentExtent(map)){ + map.setCenter(centerLonLat, 12); + } } diff --git a/static/main_map.js b/static/main_map.js index adb97c1..6370117 100644 --- a/static/main_map.js +++ b/static/main_map.js @@ -239,7 +239,6 @@ function init(){ controls:[new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.ScaleLine()], - maxExtent: maxExtent, maxResolution: 156543.0399, units: 'm', projection: new OpenLayers.Projection('EPSG:4326') @@ -247,6 +246,9 @@ function init(){ /*projection: new OpenLayers.Projection('EPSG:900913'), displayProjection: new OpenLayers.Projection('EPSG:4326')*/ map.addLayers([layerMapnik, cyclemap]); + /* zoom to the appropriate extent */ + if (!zoomToCurrentExtent(map)){ + map.setCenter(centerLonLat, 12); + } loadGeoObjects(); - map.setCenter(centerLonLat, 12); } diff --git a/templates/base.html b/templates/base.html index e30e1e6..f54450d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -8,6 +8,7 @@ <script type="text/javascript"><!-- var media_path = '{{ media_path }}'; // --></script> + <script src="{{ media_path }}base.js"></script> {% block extra_head %}{{extra_head|safe}}{% endblock %} </head> @@ -15,7 +16,7 @@ <div id="topbar"> <ul id='action'> {% for action in actions %} - <li{% ifequal action.id action_selected %} id='selected'{% endifequal %}><a href='/{{ action.path }}'>{{ action.label }}</a></li> + <li{% ifequal action.id action_selected %} id='selected'{% endifequal %}><a href='/{{ action.path }}' onclick='saveExtent();'>{{ action.label }}</a></li> {% endfor %} </ul> </div> diff --git a/templates/edit.html b/templates/edit.html index 9d3ee8c..99dc99b 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -45,7 +45,7 @@ {{ field }} </div> {%endifequal%}{%endfor%}{%endfor%} -<p><input type='submit' value="{% trans 'Propose'%}"/></p> +<p><input type='submit' onclick='saveExtent();' value="{% trans 'Propose'%}"/></p> </form> </fieldset> {% endblock %} |