]> dev.renevier.net Git - syp.git/commitdiff
uses cluster strategy for items presentation
authorarno <arenevier@fdn.fr>
Thu, 30 Jul 2009 15:55:46 +0000 (17:55 +0200)
committerarno <arenevier@fdn.fr>
Thu, 30 Jul 2009 15:55:46 +0000 (17:55 +0200)
js/syp.js
syp.cfg

index 8e32d8580d4d7e86d7b0f178cfa46f627d0c8e99..fdd69ed7253b293e1d6dd9b0c1044925ee8fa4e8 100644 (file)
--- a/js/syp.js
+++ b/js/syp.js
@@ -71,21 +71,31 @@ var SYP = {
     },
 
     createDataLayer: function(map) {
+        var defaultStyle = new OpenLayers.Style({
+            externalGraphic: this.Settings.MARKER_ICON,
+            graphicHeight: "${height}"
+        }, {
+            context: {
+                height: function(feature) {
+                    var defaultHeight = SYP.Settings.MARKER_ICON_HEIGHT || 32;
+                    var increase = 4 * (feature.attributes.count - 1);
+                    return Math.min(defaultHeight + increase, 50);
+                }
+            }
+        });
+        var selectStyle = new OpenLayers.Style({
+            externalGraphic: this.Settings.MARKER_SELECT_ICON,
+            graphicHeight: this.Settings.MARKER_SELECT_ICON_HEIGHT || 32 
+        });
         var styleMap = new OpenLayers.StyleMap (
-                        {"default": {
-                            externalGraphic: this.Settings.MARKER_ICON,
-                            graphicHeight: this.Settings.MARKER_ICON_HEIGHT
-                                            || 32 
-                                    },
-                         "select": { 
-                            externalGraphic: this.Settings.MARKER_SELECT_ICON,
-                            graphicHeight: this.Settings.MARKER_SELECT_ICON_HEIGHT 
-                                            || 32 
-                                  }
-                     });
+                        {"default": defaultStyle,
+                         "select": selectStyle});
 
         var layer = new OpenLayers.Layer.GML("KML", "items.php", 
            {
+               strategies: [
+                new OpenLayers.Strategy.Cluster()
+                ],
             styleMap: styleMap,
             format: OpenLayers.Format.KML, 
             projection: this.map.displayProjection,
@@ -148,6 +158,12 @@ var SYP = {
 
     onFeatureSelect: function(feature) {
         var map = feature.layer.map;
+        if (feature.attributes.count > 1) {
+            this.unselect(feature);
+            var lonlat = new OpenLayers.LonLat(feature.geometry.x, feature.geometry.y);
+            map.setCenter(lonlat, map.zoom + 1);
+            return;
+        }
         var permaControl = map.getControlsByClass("OpenLayers.Control.Permalink");
         if (permaControl[0]) {
             permaControl[0].div.style.display = "none";
@@ -162,13 +178,13 @@ var SYP = {
             popup.destroy();
         }
         var contentHTML;
-        if (feature.attributes.name) {
+        if (feature.cluster[0].attributes.name) {
             contentHTML = "<h2>" +
-                          feature.attributes.name + 
+                          feature.cluster[0].attributes.name + 
                           "</h2>" + 
-                          feature.attributes.description;
+                          feature.cluster[0].attributes.description;
         } else {
-            contentHTML = feature.attributes.description;
+            contentHTML = feature.cluster[0].attributes.description;
         }
         if (!contentHTML || !contentHTML.length) {
             this.map.events.register("movestart", this, this._unselect = function () { this.unselect(feature)});
@@ -178,7 +194,7 @@ var SYP = {
         var control = this;
         popup.hide = function () {
             OpenLayers.Element.hide(this.div);
-            control.unselect(feature);
+            control.unselectAll();
         };
         map.addPopup(popup);
         feature.popup = popup;
diff --git a/syp.cfg b/syp.cfg
index cb484e5cd1d62f9f92a1697c696143ee59aa6163..f342deabf7fb029644fe568e71755a5e1aff61e4 100644 (file)
--- a/syp.cfg
+++ b/syp.cfg
@@ -24,6 +24,7 @@ OpenLayers/Vector.js
 OpenLayers/Renderer/SVG.js
 OpenLayers/Renderer/Canvas.js
 OpenLayers/Renderer/VML.js
+OpenLayers/Strategy/Cluster.js
 OpenLayers/Tile/Image.js
 OpenLayers/Tile/Image.js
 OpenLayers/Tile/WFS.js