summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-09-28 10:18:55 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-09-28 10:18:55 +0200
commit1d1a786eedd6af35b70265bc39af395767e993f0 (patch)
tree37bb50f9e364cae3d4092f71cfc14e5acf0bc194
parentc337f48a8bb2941e206d7504b66a3a4f7299d572 (diff)
downloadChimère-1d1a786eedd6af35b70265bc39af395767e993f0.tar.bz2
Chimère-1d1a786eedd6af35b70265bc39af395767e993f0.zip
Contextual category for search result
-rw-r--r--chimere/models.py10
-rw-r--r--chimere/static/chimere/js/jquery.chimere.js29
-rw-r--r--chimere/templates/search/search.html3
3 files changed, 28 insertions, 14 deletions
diff --git a/chimere/models.py b/chimere/models.py
index a052b66..5a8157f 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -914,7 +914,9 @@ class GeographicItem(models.Model):
'icon_offset_y': cat.icon.offset_y,
'icon_popup_offset_x': cat.icon.popup_offset_x,
'icon_popup_offset_y': cat.icon.popup_offset_y,
- 'category_name': cat.name}
+ 'category_name': cat.name,
+ 'category_id': cat.pk,
+ }
try:
categories_icons[item['categories__pk']].update(
{'icon_width': cat.icon.image.width,
@@ -971,7 +973,7 @@ class GeographicItem(models.Model):
value['properties']['extra_colors'].append(colors)
continue
if limit_to_categories and \
- item["categories__pk"] not in limit_to_categories:
+ item["categories__pk"] not in limit_to_categories:
continue
if start:
start -= 1
@@ -1249,7 +1251,9 @@ class Marker(GeographicItem):
'icon_offset_y': cat.icon.offset_y,
'icon_popup_offset_x': cat.icon.popup_offset_x,
'icon_popup_offset_y': cat.icon.popup_offset_y,
- 'category_name': cat.name})
+ 'category_name': cat.name,
+ 'category_id': cat.pk,
+ })
try:
items['properties'].update(
{'icon_width': cat.icon.image.width,
diff --git a/chimere/static/chimere/js/jquery.chimere.js b/chimere/static/chimere/js/jquery.chimere.js
index 9075c94..f69565a 100644
--- a/chimere/static/chimere/js/jquery.chimere.js
+++ b/chimere/static/chimere/js/jquery.chimere.js
@@ -1371,7 +1371,7 @@ function transformCoordToLonLat(coord) {
return feature;
},
openPopup: function(map_id, feature, offset_x, offset_y,
- alt_coordinates, no_detail){
+ alt_coordinates, no_detail, category_id){
if (!no_detail){
settings[map_id].current_feature = feature;
}
@@ -1411,7 +1411,9 @@ function transformCoordToLonLat(coord) {
})
$(settings[map_id].popup_item).popover('show');
if (!no_detail){
- methods.display_feature_detail(map_id, feature.get('key'), feature.get('name'));
+ methods.display_feature_detail(
+ map_id, feature.get('key'), feature.get('name'),
+ category_id);
}
},
/* end of new ol3 */
@@ -3020,7 +3022,7 @@ function transformCoordToLonLat(coord) {
return;
},
- display_feature_detail: function (map_id, key, name) {
+ display_feature_detail: function (map_id, key, name, category_id) {
/*
* update current detail panel with an AJAX request
*/
@@ -3040,7 +3042,11 @@ function transformCoordToLonLat(coord) {
$(".popover").addClass('transparent');
uri += "popup/";
}
- uri += key + "?categories=" + settings[map_id].checked_categories.join('-');
+ if (category_id){
+ uri += key + "?categories=" + category_id;
+ } else {
+ uri += key + "?categories=" + settings[map_id].checked_categories.join('-');
+ }
var params = {}
if (settings[map_id].simple) { params["simple"] = 1; }
$.ajax({url: uri,
@@ -3410,7 +3416,7 @@ function transformCoordToLonLat(coord) {
var bounds = settings[map_id].layerVectors.getDataExtent();
if (bounds) settings[map_id].map.zoomToExtent(bounds);
},
- _showPopupForFeature: function (map_id, feature, slow){
+ _showPopupForFeature: function (map_id, feature, slow, category_id){
if (typeof feature != 'undefined'){
if (settings[map_id].current_feature == feature){
return
@@ -3446,13 +3452,15 @@ function transformCoordToLonLat(coord) {
if (key && key.length > 6 && key.substring(0, 7) == 'cluster'){
feature = methods.clickOnCluster(map_id, feature);
} else {
- methods.openPopup(map_id, feature);
+ methods.openPopup(map_id, feature, null, null,
+ null, null, category_id);
}
}, timeout);
}
}
},
- _showPopup: function (map_id, feature_pk, zoom, zoom_level, slow){
+ _showPopup: function (map_id, feature_pk, zoom, zoom_level, slow,
+ category_id){
if(!zoom_level) zoom_level = 14;
if(!slow) slow = false;
var feats = settings[map_id].dbFeatures.getArray();
@@ -3483,7 +3491,8 @@ function transformCoordToLonLat(coord) {
}
}
- methods._showPopupForFeature(map_id, c_marker, slow);
+ methods._showPopupForFeature(map_id, c_marker, slow,
+ category_id);
return true
}
}
@@ -3494,7 +3503,7 @@ function transformCoordToLonLat(coord) {
}
return false;
},
- showPopup: function (feature_pk, zoom, zoom_level) {
+ showPopup: function (feature_pk, zoom, zoom_level, category_id) {
var map_id = methods.map_id(this);
if (!map_id){
alert("showPopup - Public method only");
@@ -3515,7 +3524,7 @@ function transformCoordToLonLat(coord) {
}
}
return methods._showPopup(map_id, feature_pk, true, zoom_level,
- slow);
+ slow, category_id);
},
hidePopup: function () {
var map_id = methods.map_id(this);
diff --git a/chimere/templates/search/search.html b/chimere/templates/search/search.html
index ff013fd..754e641 100644
--- a/chimere/templates/search/search.html
+++ b/chimere/templates/search/search.html
@@ -19,7 +19,8 @@ var end_do_you_mean = "{% trans '?' %}";
<ul>
{% endifchanged %}
<li>
- <a href="#" onclick="$('#main-map').chimere('showPopup', '{{result.properties.key}}');return false;">
+ <a href="#"
+ onclick="$('#main-map').chimere('showPopup', '{{result.properties.key}}', null, null, {{result.properties.category_id}});return false;">
{{ result.properties.name }}
</a>
</li>