summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chimere/locale/fr/LC_MESSAGES/django.po117
-rw-r--r--chimere/route.py87
-rw-r--r--chimere/static/chimere/css/styles.css45
-rw-r--r--chimere/static/chimere/img/flag-finish.pngbin0 -> 1652 bytes
-rw-r--r--chimere/static/chimere/img/flag-start.pngbin0 -> 1165 bytes
-rw-r--r--chimere/static/chimere/img/images_licences7
-rw-r--r--chimere/static/chimere/js/jquery.chimere.js102
-rw-r--r--chimere/templates/chimere/blocks/map_menu.html8
-rw-r--r--chimere/templates/chimere/blocks/map_params.html1
-rw-r--r--chimere/templatetags/chimere_tags.py2
-rw-r--r--chimere/urls.py8
-rw-r--r--chimere/views.py21
-rw-r--r--example_project/settings.py7
13 files changed, 337 insertions, 68 deletions
diff --git a/chimere/locale/fr/LC_MESSAGES/django.po b/chimere/locale/fr/LC_MESSAGES/django.po
index 53cf4d4..c188f77 100644
--- a/chimere/locale/fr/LC_MESSAGES/django.po
+++ b/chimere/locale/fr/LC_MESSAGES/django.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.2\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-08-02 20:40+0200\n"
+"POT-Creation-Date: 2012-08-15 01:31+0200\n"
"PO-Revision-Date: 2010-03-20 20:00+0100\n"
"Last-Translator: Étienne Loks <etienne.loks@peacefrogs.net>\n"
"MIME-Version: 1.0\n"
@@ -107,26 +107,26 @@ msgstr "Courriel (optionnel) "
msgid "Object"
msgstr "Objet"
-#: forms.py:147
+#: forms.py:155
msgid "End date has been set with no start date"
msgstr "Une date de fin a été donnée sans date de début"
-#: forms.py:358
+#: forms.py:369
msgid "File"
msgstr "Fichier"
-#: forms.py:364
+#: forms.py:375
msgid "Bad file format: this must be a GPX or KML file"
msgstr "Mauvais format de fichier : KML et GPX sont supportés"
-#: forms.py:369 models.py:48 models.py:101 models.py:122 models.py:135
+#: forms.py:380 models.py:48 models.py:101 models.py:122 models.py:135
#: models.py:149 models.py:232 models.py:437 models.py:480 models.py:524
#: models.py:555 models.py:792 models.py:804 models.py:889
#: templates/chimere/edit.html:39 templates/chimere/edit_route.html:36
msgid "Name"
msgstr "Nom"
-#: forms.py:378 models.py:841
+#: forms.py:389 models.py:841
msgid "Area"
msgstr "Zone"
@@ -515,91 +515,91 @@ msgstr "Valeur"
msgid "Property"
msgstr "Propriété"
-#: tasks.py:47
+#: tasks.py:61
msgid "Import pending"
msgstr "Import en attente"
-#: tasks.py:48
+#: tasks.py:62
msgid "Import processing"
msgstr "Import en cours"
-#: tasks.py:49
+#: tasks.py:63
msgid "Import successfuly done"
msgstr "Import fait avec succès"
-#: tasks.py:50
+#: tasks.py:64
#, python-format
msgid " %(new)d new item(s), %(updated)d updated item(s)"
msgstr " %(new)d nouveau(x) élément(s), %(updated)d élément(s) mis à jour"
-#: tasks.py:51
+#: tasks.py:65
msgid "Import failed"
msgstr "Import échoué"
-#: tasks.py:52
+#: tasks.py:66
msgid "Import canceled"
msgstr "Import annulé"
-#: tasks.py:53
+#: tasks.py:67
msgid "Export pending"
msgstr "Export en attente"
-#: tasks.py:54
+#: tasks.py:68
msgid "Export processing"
msgstr "Export en cours"
-#: tasks.py:55
+#: tasks.py:69
msgid "Export successfuly done"
msgstr "Export réalisé avec succès"
-#: tasks.py:56
+#: tasks.py:70
#, python-format
msgid " %(updated)d updated item(s)"
msgstr " %(updated)d éléments mis à jour"
-#: tasks.py:57
+#: tasks.py:71
msgid "Export failed"
msgstr "Export échoué"
-#: tasks.py:58
+#: tasks.py:72
msgid "Export canceled"
msgstr "Export annulé"
-#: utils.py:104 utils.py:152
+#: utils.py:113 utils.py:161
msgid "Bad zip file"
msgstr "Mauvais fichier zip"
-#: utils.py:155
+#: utils.py:164
msgid "Missing file(s) inside the zip file"
msgstr "Fichier(s) manquant(s) dans l'archive zip"
-#: utils.py:284
+#: utils.py:293
msgid "Error while reading the data source."
msgstr "Erreur lors de la lecture de la source."
-#: utils.py:319
+#: utils.py:328
msgid "Type of geographic item of this shapefile is not managed by Chimère."
msgstr ""
"Les types des éléments géographiques de ce fichier Shapefile ne sont pas "
"gérés par Chimère."
-#: utils.py:400
+#: utils.py:385
msgid "Could not create file!"
msgstr "Ne peut pas créer le fichier !"
-#: utils.py:411
+#: utils.py:396
msgid "Failed to create field"
msgstr "Ne peut pas créer un champ"
-#: utils.py:482
+#: utils.py:467
msgid "Nothing to import"
msgstr "Rien à importer"
-#: utils.py:562
+#: utils.py:547
msgid "New items imported - validate them before exporting"
msgstr "Nouveaux éléments importés - valider ceux-ci avant d'exporter"
-#: utils.py:564
+#: utils.py:549
msgid ""
"There are items from a former import not yet validated - validate them "
"before exporting"
@@ -607,23 +607,23 @@ msgstr ""
"Il y a des éléments d'un import précédent pas encore validé - Validez les "
"avant d'exporter"
-#: utils.py:574
+#: utils.py:559
msgid "Bad param"
msgstr "Mauvais paramètre"
-#: views.py:223
+#: views.py:226
msgid "There are missing field(s) and/or errors in the submited form."
msgstr "Il y a des champs manquants ou des erreurs dans ce formulaire."
-#: views.py:302
+#: views.py:305
msgid "Bad file. Please check it with an external software."
msgstr "Fichier incohérent. Merci de le vérifier avec un logiciel externe."
-#: views.py:424
+#: views.py:427
msgid "Comments/request on the map"
msgstr "Commentaires/requètes sur la carte"
-#: views.py:427
+#: views.py:430
msgid ""
"Thank you for your contribution. It will be taken into account. If you have "
"left your email you may be contacted soon for more details."
@@ -632,15 +632,15 @@ msgstr ""
"laissé votre courriel vous serez peut-être contacté bientôt pour plus de "
"détails."
-#: views.py:431
+#: views.py:434
msgid "Temporary error. Renew your message later."
msgstr "Erreur temporaire. Réenvoyez votre message plus tard."
-#: views.py:562
+#: views.py:565
msgid "No category available in this area."
msgstr "Pas de catégorie disponible sur cette zone."
-#: views.py:669
+#: views.py:690
msgid "Incorrect choice in the list"
msgstr "Choix incorrect dans la liste"
@@ -790,10 +790,6 @@ msgstr "Partager sur"
msgid "Share"
msgstr "Partager"
-#: templates/chimere/detail.html:37
-msgid "Submit a modification"
-msgstr "Proposer une modification"
-
#: templates/chimere/edit.html:20
msgid "Error"
msgstr "Erreur"
@@ -873,6 +869,32 @@ msgstr "Ce site utilise Chimère"
msgid "Map"
msgstr "Carte"
+#: templates/chimere/blocks/map_menu.html:5
+msgctxt "routing"
+msgid "From"
+msgstr "En partir"
+
+#: templates/chimere/blocks/map_menu.html:6
+msgctxt "routing"
+msgid "To"
+msgstr "Y aller"
+
+#: templates/chimere/blocks/map_menu.html:8
+msgid "Zoom in"
+msgstr "Zoomer en avant"
+
+#: templates/chimere/blocks/map_menu.html:9
+msgid "Zoom out"
+msgstr "Zoomer en arrière"
+
+#: templates/chimere/blocks/map_menu.html:10
+msgid "Center the map here"
+msgstr "Centrer la carte ici"
+
+#: templates/chimere/blocks/map_menu.html:16
+msgid "Itinerary"
+msgstr "Itinéraire"
+
#: templates/chimere/blocks/map_params.html:6
msgid "Permalink"
msgstr "Lien permanent"
@@ -947,20 +969,3 @@ msgstr "Choisir une zone pré-définie"
msgid "Or select the area by zooming and panning this map"
msgstr "Ou sélectionner une zone en zoomant et en se déplaçant sur cette carte"
-#~ msgid "Categorys"
-#~ msgstr "Catégories"
-
-#~ msgid "Theme"
-#~ msgstr "Thème"
-
-#~ msgid "Subtheme"
-#~ msgstr "Sous-thème"
-
-#~ msgid "Subthemes"
-#~ msgstr "Sous-thèmes"
-
-#~ msgid "Themes"
-#~ msgstr "Thèmes"
-
-#~ msgid "Site name"
-#~ msgstr "Nom du site"
diff --git a/chimere/route.py b/chimere/route.py
new file mode 100644
index 0000000..efc6763
--- /dev/null
+++ b/chimere/route.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+#
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# See the file COPYING for details.
+
+"""
+Routing management
+"""
+
+import os, re, shutil, tempfile
+from BeautifulSoup import BeautifulSoup
+from subprocess import Popen, PIPE
+from django.contrib.gis.gdal import DataSource
+
+from django.conf import settings
+
+class Router:
+ def route(self, lon1, lat1, lon2, lat2, transport='foot'):
+ '''
+ Get a list of geojson polylines
+ '''
+ return []
+
+class RoutinoRouter(Router):
+ re_desc = [re.compile("<tr class='n'>"), re.compile("<tr class='s'>"),
+ re.compile("<tr class='t'>")]
+ def route(self, lon1, lat1, lon2, lat2, session_id='', transport='foot'):
+ '''
+ Get a list of geojson polylines and route description
+ '''
+ language = settings.LANGUAGE_CODE.split('-')[0]
+ args = [settings.CHIMERE_ROUTING_ENGINE['PATH'],
+ "--dir=%s" % settings.CHIMERE_ROUTING_ENGINE['DB_PATH'],
+ "--transport=%s" % transport,
+ "--language=%s" % language,
+ "--shortest",
+ "--output-html",
+ "--output-gpx-track",
+ "--lat1=%0.15f" % lat1,
+ "--lon1=%0.15f" % lon1,
+ "--lat2=%0.15f" % lat2,
+ "--lon2=%0.15f" % lon2
+ ]
+ tmp_dir = tempfile.mkdtemp(prefix='chimere_') + os.sep
+ p = Popen(args, stdout=PIPE, cwd=tmp_dir)
+ p.communicate()
+ ds = DataSource(tmp_dir + 'shortest-track.gpx')
+ if not ds:
+ return [], None
+ layer = ds[0]
+ trk_layer = None
+ for layer in ds:
+ if layer.name == 'tracks':
+ trk_layer = layer
+ break
+ multilines = trk_layer.get_geoms()
+ res = []
+ for multiline in multilines:
+ res += [geom.geojson for geom in multiline]
+ desc = ['<table>']
+ # only keeping interessant lines of the desc
+ for line in open(tmp_dir + 'shortest.html').readlines():
+ if [True for r in self.re_desc if r.match(line)]:
+ desc.append(BeautifulSoup(line).prettify())
+ desc.append('</table>')
+ desc = BeautifulSoup('\n'.join(desc)).prettify()
+ shutil.rmtree(tmp_dir)
+ return res, desc
+router = None
+if settings.CHIMERE_ROUTING_ENGINE['ENGINE'] == 'routino':
+ router = RoutinoRouter()
+
diff --git a/chimere/static/chimere/css/styles.css b/chimere/static/chimere/css/styles.css
index 92ecca6..28dafd8 100644
--- a/chimere/static/chimere/css/styles.css
+++ b/chimere/static/chimere/css/styles.css
@@ -15,7 +15,8 @@ a, a:link, a:visited, legend,
h2, h3, th, .action li, .action li a,
.action li li a, #no-js-message,
-#footer a, #footer a:link, #footer a:visited, .ui-widget-header{
+#footer a, #footer a:link, #footer a:visited, .ui-widget-header,
+#chimere_itinerary td.l{
color:#fff;
}
@@ -30,7 +31,8 @@ body, h2, h3, th,
.ui-widget-header,
.action li.selected, #no-js-message,
#content .olControlLayerSwitcher .layersDiv,
-#content .olControlLayerSwitcher span{
+#content .olControlLayerSwitcher span,
+#chimere_itinerary td.l{
background-color:#449506;
}
@@ -39,7 +41,7 @@ body, h2, h3, th,
}
fieldset, .action li, #content,
-#map-footer, #panel, #areas,
+#map-footer, #panel, #chimere_itinerary_panel, #areas,
#welcome, #detail, .detail_footer a,
#main-map, .window{
background-color:#FFF;
@@ -61,7 +63,7 @@ div.warning, .errorlist{
div.warning,
#content,
.action li.selected,
-#panel, #map-footer,
+#panel, #map-footer, #chimere_itinerary_panel,
#utils-div{
border:1px solid #327e04;
}
@@ -76,7 +78,7 @@ div.warning,
opacity:0.9;
}
-#panel, #areas, #detail, #category_detail{
+#panel, #areas, #detail, #category_detail, #chimere_itinerary_panel{
opacity:0.8;
}
@@ -410,6 +412,33 @@ ul#share li{
padding-top:0;
}
+#chimere_itinerary_panel{
+ position:absolute;
+ z-index:5;
+ top:50px;
+ left:50px;
+ width:300px;
+ padding:0.5em;
+ padding-top:0;
+ display:none;
+}
+
+#chimere_itinerary{
+ height:250px;
+ overflow:auto;
+ padding:0.2em 1em;
+ font-size:0.9em;
+}
+
+#chimere_itinerary td.l{
+ padding:6px;
+}
+
+#chimere_itinerary span.j{
+ font-style:italic;
+}
+
+
#chimere_map_menu{
z-index:4;
display:none;
@@ -417,9 +446,9 @@ ul#share li{
padding:0.5em;
background-color:#fff;
border:1px solid #bbb;
- -webkit-border-radius: 4px;
- -moz-border-radius: 4px;
- border-radius: 4px;
+ -webkit-border-radius: 0 8px 8px 8px;
+ -moz-border-radius: 0 8px 8px 8px;
+ border-radius: 0 8px 8px 8px;
}
#chimere_map_menu ul, #chimere_map_menu li{
diff --git a/chimere/static/chimere/img/flag-finish.png b/chimere/static/chimere/img/flag-finish.png
new file mode 100644
index 0000000..04bfa1d
--- /dev/null
+++ b/chimere/static/chimere/img/flag-finish.png
Binary files differ
diff --git a/chimere/static/chimere/img/flag-start.png b/chimere/static/chimere/img/flag-start.png
new file mode 100644
index 0000000..c93f2a3
--- /dev/null
+++ b/chimere/static/chimere/img/flag-start.png
Binary files differ
diff --git a/chimere/static/chimere/img/images_licences b/chimere/static/chimere/img/images_licences
index 0e732fc..000fdf0 100644
--- a/chimere/static/chimere/img/images_licences
+++ b/chimere/static/chimere/img/images_licences
@@ -30,3 +30,10 @@ Url 2: http://commons.wikimedia.org/wiki/File:Internet-web-browser.svg
Author: Sbrools
Licence: Public domain
Url: https://commons.wikimedia.org/wiki/File:8thNote.svg
+
+* Flags image credit (flag-start.png, flag-finish.png)
+
+Author: FatCow Web Hosting
+Licence: Creative Commons Attribution 3.0 United States license
+Url: https://upload.wikimedia.org/wikipedia/commons/6/64/Farm-Fresh_flag_finish.png
+ https://upload.wikimedia.org/wikipedia/commons/c/cb/Farm-Fresh_flag_1.png
diff --git a/chimere/static/chimere/js/jquery.chimere.js b/chimere/static/chimere/js/jquery.chimere.js
index 116f927..ed0ca02 100644
--- a/chimere/static/chimere/js/jquery.chimere.js
+++ b/chimere/static/chimere/js/jquery.chimere.js
@@ -211,11 +211,30 @@ See the file COPYING for details.
settings.layerVectors, helpers.featureRouteCreated);
}
}
- $('#chimere_map_menu #map_menu_zoomin').bind("click",
- methods.zoomIn);
- $('#chimere_map_menu #map_menu_zoomout').bind("click",
- methods.zoomOut);
+ $('#map_menu_zoomin').bind("click", methods.zoomIn);
+ $('#map_menu_zoomout').bind("click", methods.zoomOut);
$('#map_menu_center').bind("click", methods.mapCenter);
+ if (settings.routing){
+ settings.routing_start = null;
+ settings.routing_end = null;
+ settings.icon_start = new OpenLayers.Icon(
+ STATIC_URL + "chimere/img/flag-start.png",
+ new OpenLayers.Size(32, 32),
+ new OpenLayers.Pixel(0, -32));
+ settings.icon_end = new OpenLayers.Icon(
+ STATIC_URL + "chimere/img/flag-finish.png",
+ new OpenLayers.Size(32, 32),
+ new OpenLayers.Pixel(0, -32));
+ $('#map_menu_from').bind("click", methods.routingFrom);
+ $('#map_menu_to').bind("click", methods.routingTo);
+ settings.layerRoute = new OpenLayers.Layer.Vector("Route Layer");
+ settings.map.addLayer(settings.layerRoute);
+ settings.layerRoute.setOpacity(0.8);
+ settings.layerRouteMarker = new OpenLayers.Layer.Markers(
+ 'Route markers');
+ settings.map.addLayer(settings.layerRouteMarker);
+ settings.layerRouteMarker.setOpacity(0.8);
+ }
}, // end of init
// zoom in from the map menu
@@ -479,6 +498,81 @@ See the file COPYING for details.
settings.current_feature.geometry = linestring;
settings.layerVectors.addFeatures([settings.current_feature]);
},
+ // set the start point for routing
+ routingFrom: function(){
+ $('#chimere_map_menu').hide();
+ $('#chimere_itinerary_panel').hide();
+ settings.routing_start = new OpenLayers.Marker(
+ settings.current_position.clone(),
+ settings.icon_start);
+ settings.layerRouteMarker.addMarker(settings.routing_start);
+ if (settings.routing_end) methods.route();
+ },
+
+ // set the finish point for routing
+ routingTo: function(){
+ $('#chimere_map_menu').hide();
+ $('#chimere_itinerary_panel').hide();
+ settings.routing_end = new OpenLayers.Marker(
+ settings.current_position.clone(),
+ settings.icon_end);
+ settings.layerRouteMarker.addMarker(settings.routing_end);
+ if (settings.routing_start) methods.route();
+ },
+
+ // display a route
+ route: function(){
+ if (!settings.routing_start || !settings.routing_end){
+ return;
+ }
+ var start = settings.routing_start.lonlat.clone().transform(
+ settings.map.getProjectionObject(),
+ EPSG_DISPLAY_PROJECTION);
+ var end = settings.routing_end.lonlat.clone().transform(
+ settings.map.getProjectionObject(),
+ EPSG_DISPLAY_PROJECTION);
+ var uri = extra_url + "route/"
+ + start.lon + '_'
+ + start.lat + '_'
+ + end.lon + '_'
+ + end.lat;
+ $.ajax({url: uri,
+ dataType: "json",
+ success: function (data) {
+ settings.layerRoute.removeAllFeatures();
+ for (var i = 0; i < data.features.length; i++) {
+ methods.putRoute(data.features[i]);
+ }
+ $('#chimere_itinerary').html(
+ data.properties.description);
+ $('#chimere_itinerary_panel').show();
+ },
+ error: function (data) {
+ settings.layerRoute.removeAllFeatures();
+ }
+ });
+
+ },
+ /*
+ Put a route on the map
+ */
+ putRoute: function(polyline) {
+ var point_array = new Array();
+ for (i=0; i<polyline.coordinates.length; i++){
+ var point = new OpenLayers.Geometry.Point(polyline.coordinates[i][0],
+ polyline.coordinates[i][1]);
+ point_array.push(point);
+ }
+ var linestring = new OpenLayers.Geometry.LineString(point_array);
+ linestring.transform(EPSG_DISPLAY_PROJECTION, settings.map.getProjectionObject());
+ current_route = new OpenLayers.Feature.Vector();
+ var style = OpenLayers.Util.extend({},
+ OpenLayers.Feature.Vector.style['default']);
+ style.strokeWidth = 3;
+ current_route.style = style;
+ current_route.geometry = linestring;
+ settings.layerRoute.addFeatures([current_route]);
+ },
display_feature_detail: function (pk) {
/*
* update current detail panel with an AJAX request
diff --git a/chimere/templates/chimere/blocks/map_menu.html b/chimere/templates/chimere/blocks/map_menu.html
index 513d6ba..4c78a5b 100644
--- a/chimere/templates/chimere/blocks/map_menu.html
+++ b/chimere/templates/chimere/blocks/map_menu.html
@@ -10,3 +10,11 @@
<li id='map_menu_center'>{% trans "Center the map here" %}</li>
</ul>
</div>
+
+{% if routing %}
+<div id='chimere_itinerary_panel' class='draggable ui-widget ui-corner-all'>
+ <h2 class='ui-widget ui-state-default ui-corner-all ui-widget-header'>{% trans "Itinerary" %}</h2>
+ <div id='chimere_itinerary'>
+ </div>
+</div>
+{% endif%}
diff --git a/chimere/templates/chimere/blocks/map_params.html b/chimere/templates/chimere/blocks/map_params.html
index c8f97eb..1afd722 100644
--- a/chimere/templates/chimere/blocks/map_params.html
+++ b/chimere/templates/chimere/blocks/map_params.html
@@ -5,6 +5,7 @@
chimere_init_options["map_layers"] = [{{map_layers|safe|escape}}];
chimere_init_options['permalink_label'] = '{%trans "Permalink"%}';
chimere_init_options['permalink_element'] = document.getElementById('permalink');
+ chimere_init_options['routing'] = {{routing}};
{% if dynamic_categories %}chimere_init_options['dynamic_categories'] = true;{% endif %}
{% if default_area %}
chimere_init_options["default_area"] = new Array({{default_area.upper_left_corner.x}}, {{default_area.upper_left_corner.y}}, {{default_area.lower_right_corner.x}}, {{default_area.lower_right_corner.y}});
diff --git a/chimere/templatetags/chimere_tags.py b/chimere/templatetags/chimere_tags.py
index 70dabaa..5256518 100644
--- a/chimere/templatetags/chimere_tags.py
+++ b/chimere/templatetags/chimere_tags.py
@@ -123,6 +123,8 @@ def map_params(context):
context_data['icon_offset_y'] = settings.CHIMERE_ICON_OFFSET_Y
context_data['icon_width'] = settings.CHIMERE_ICON_WIDTH
context_data['icon_height'] = settings.CHIMERE_ICON_HEIGHT
+ context_data['routing'] = 'true' if settings.CHIMERE_ENABLE_ROUTING \
+ else 'none'
area_name = context['area_name'] if 'area_name' in context else 'area_name'
map_layers, default_area = get_map_layers(area_name)
context_data['map_layers'] = ", ".join(map_layers)
diff --git a/chimere/urls.py b/chimere/urls.py
index a232382..ad88e32 100644
--- a/chimere/urls.py
+++ b/chimere/urls.py
@@ -51,6 +51,14 @@ if settings.CHIMERE_FEEDS:
LatestPOIsByZoneID(), name='feeds-areaid'),
)
+if settings.CHIMERE_ENABLE_ROUTING:
+ urlpatterns += patterns('chimere.views',
+ url(r'^(?P<area_name>[a-zA-Z0-9_-]*/)?route/'\
+ r'(?P<lon1>[-]?[0-9]+[.]?[0-9]*)_(?P<lat1>[-]?[0-9]+[.]?[0-9]*)_'\
+ r'(?P<lon2>[-]?[0-9]+[.]?[0-9]*)_(?P<lat2>[-]?[0-9]+[.]?[0-9]*)$',
+ 'route', name="route"),
+ )
+
urlpatterns += patterns('chimere.views',
url(r'^charte/?$', 'charte', name="charte"),
url(r'^(?P<area_name>[a-zA-Z0-9_-]+/)?contact/?$', 'contactus', name="contact"),
diff --git a/chimere/views.py b/chimere/views.py
index 824d912..4af6120 100644
--- a/chimere/views.py
+++ b/chimere/views.py
@@ -26,6 +26,7 @@ Views of the project
import datetime
from itertools import groupby
+import simplejson
from django.conf import settings
from django.core import serializers
@@ -49,6 +50,8 @@ from chimere.forms import MarkerForm, RouteForm, ContactForm, FileForm, \
FullFileForm, MultimediaFileFormSet, PictureFileFormSet, notifySubmission,\
notifyStaff, AreaForm
+from chimere.route import router
+
def get_base_uri(request):
base_uri = 'http://'
if 'HTTP_REFERER' in request.META:
@@ -623,6 +626,24 @@ def redirectFromTinyURN(request, area_name='', tiny_urn=''):
return redir
return HttpResponseRedirect(response_dct['extra_url'] + parameters)
+def route(request, area_name, lon1, lat1, lon2, lat2, transport='foot'):
+ '''
+ Get the JSON for a route
+ '''
+ try:
+ lon1, lat1 = float(lon1), float(lat1)
+ lon2, lat2 = float(lon2), float(lat2)
+ except ValueError:
+ return HttpResponse('no results')
+ jsons, desc = router.route(lon1, lat1, lon2, lat2, transport=transport,
+ session_id=request.session.session_key)
+ if not jsons:
+ return HttpResponse('no results')
+ jsonencoder = simplejson.JSONEncoder()
+ data = '{"properties":{"description":%s}, "type": "FeatureCollection",'\
+ '"features":[%s]}' % (jsonencoder.encode(desc), ",".join(jsons))
+ return HttpResponse(data)
+
def rss(request, area_name=''):
'''
Redirect to RSS subscription page
diff --git a/example_project/settings.py b/example_project/settings.py
index 9b25605..ead2c93 100644
--- a/example_project/settings.py
+++ b/example_project/settings.py
@@ -77,6 +77,13 @@ CHIMERE_SHAPEFILE_ENCODING = 'ISO-8859-1'
# enable routing in Chimère
CHIMERE_ENABLE_ROUTING = False
+# available routing engine: 'routino'
+CHIMERE_ROUTING_ENGINE = {
+ 'ENGINE': 'routino',
+ 'PATH': '/usr/local/src/web/bin/router',
+ 'DB_PATH': '/var/local/routino/',
+}
+
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)