From ea4e994b8b9c8dec7f2851810533914595a773e5 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 1 Oct 2016 13:09:30 +0200 Subject: Cluster: manage item list at max zoom - now use bootstrap for the window --- chimere/static/chimere/js/jquery.chimere.js | 57 +++++++++++++++++++---------- chimere/templates/chimere/base.html | 5 +-- chimere/templates/chimere/blocks/map.html | 16 +++++++- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/chimere/static/chimere/js/jquery.chimere.js b/chimere/static/chimere/js/jquery.chimere.js index c76267e..fe75c72 100644 --- a/chimere/static/chimere/js/jquery.chimere.js +++ b/chimere/static/chimere/js/jquery.chimere.js @@ -911,6 +911,7 @@ var invisibleStyleIcon = new ol.style.Style({ var key = feature.set('key', 'cluster'); var features = feature.get('features'); var size = features.length; + feature.set('size', size); var style = settings._styleCache[size]; // no cluster for lonely marker if (!style && size > 1){ @@ -1053,22 +1054,30 @@ var invisibleStyleIcon = new ol.style.Style({ props.name + ""; } content += ""; - $('#cluster_list').html(content); - $('#cluster_list').dialog('open'); + $('#cluster_list .modal-body').html(content); + $('#cluster_list').modal('show'); /* + $('#cluster_list').dialog('open'); $("#cluster_list").on("dialogclose", methods.cleanCluster); settings.map.setCenter( feature.geometry.getBounds().getCenterLonLat()); // register after the display settings.clustered_feature = feature.cluster; */ + jQuery(".cluster_list").click( function(e){ - $('#cluster_list').dialog('close'); + $('#cluster_list').modal('hide'); var splitted = $(this).attr('id').split('_'); var index = splitted[splitted.length-1]; - feat = feats[parseInt(index)] - methods.openPopup(feat); + feat = feats[parseInt(index)]; + var size = feature.getProperties()['size'] ? feature.getProperties()['size'] : 5; + // cf. clusterGetStyle + var radius = Math.max(8, Math.min(size*0.75, 20)); + var offset_x = 0.1; + var offset_y = -(radius + radius / 2); + var geom = feature.getGeometry(); + methods.openPopup(feat, offset_x, offset_y, geom.getCoordinates()); //.attributes.marker; //m.events.triggerEvent('click'); e.stopPropagation(); @@ -1076,22 +1085,30 @@ var invisibleStyleIcon = new ol.style.Style({ }); return feature; }, - openPopup: function(feature){ - var geom = feature.getGeometry(); - if (geom.getType() == 'Point'){ - settings.popup.setPosition(geom.getCoordinates()); - settings.popup.setOffset([feature.get('popup_offset_x'), - -feature.get('popup_offset_y')]); - } else if (geom.getType() == 'Polygon'){ - settings.popup.setPosition(geom.getInteriorPoint().getCoordinates()); - settings.popup.setOffset([0, 0]); - } else if (geom.getType() == 'LineString'){ - settings.popup.setPosition(geom.getCoordinateAt(0.5)); - settings.popup.setOffset([0, 0]); - } else if (geom.getType() == 'MultipleLineString'){ - settings.popup.setPosition(geom.getLineString(0).getCoordinatesAt(0.5)); - settings.popup.setOffset([0, 0]); + openPopup: function(feature, offset_x, offset_y, alt_coordinates){ + if (!offset_x){ + offset_x = feature.get('popup_offset_x'); + if (!offset_x) offset_x = 0; + } + if (!offset_y){ + offset_y = -feature.get('popup_offset_y'); + if (!offset_y) offset_y = 0; + } + if (alt_coordinates){ + settings.popup.setPosition(alt_coordinates); + } else { + var geom = feature.getGeometry(); + if (geom.getType() == 'Point'){ + settings.popup.setPosition(geom.getCoordinates()); + } else if (geom.getType() == 'Polygon'){ + settings.popup.setPosition(geom.getInteriorPoint().getCoordinates()); + } else if (geom.getType() == 'LineString'){ + settings.popup.setPosition(geom.getCoordinateAt(0.5)); + } else if (geom.getType() == 'MultipleLineString'){ + settings.popup.setPosition(geom.getLineString(0).getCoordinatesAt(0.5)); + } } + settings.popup.setOffset([offset_x, offset_y]); $(settings.popup_item).popover({ 'placement': 'top', 'html': true, diff --git a/chimere/templates/chimere/base.html b/chimere/templates/chimere/base.html index fc3afb8..5417fea 100644 --- a/chimere/templates/chimere/base.html +++ b/chimere/templates/chimere/base.html @@ -1,6 +1,8 @@ {% extends "base.html" %} {% load chimere_tags i18n %} {% block extra_head %} + + {% if css_area %} @@ -8,10 +10,7 @@ {% if MOBILE %} {%endif%} - - -
@@ -118,5 +119,16 @@ $(function(){ */
-
+ -- cgit v1.2.3