when selecting a cluster, zoom until features are detached
authorarno <arenevier@fdn.fr>
Tue, 6 Oct 2009 22:18:15 +0000 (00:18 +0200)
committerarno <arenevier@fdn.fr>
Tue, 6 Oct 2009 22:18:15 +0000 (00:18 +0200)
js/syp.js

index 9bccba64d4e1d6796c7b06049e85cc0fb974e1c8..0f7785491f15a681bc556a81d0e089e7e39376a3 100644 (file)
--- a/js/syp.js
+++ b/js/syp.js
@@ -246,11 +246,36 @@ var SYP = {
         }
     },
 
         }
     },
 
+    onZoomClusterEnd: function(arg) {
+        var map = arg.object;
+        var point = new OpenLayers.Geometry.Point(this.lonlat.lon, this.lonlat.lat);
+        var center = map.getCenter();
+        for (var i = this.layer.features.length; i-->0;) {
+            var feature = this.layer.features[i];
+            if (feature.geometry.equals(point) && 
+                (feature.attributes.count == this.count)) {
+                   var self = this;
+                   window.setTimeout(function() { map.setCenter(self.lonlat, map.zoom + 1)}, 500);
+                   return;
+            }
+        }
+        SYP.selectControl.activate();
+        map.events.unregister("zoomend", this, SYP.onZoomClusterEnd);
+    },
+
     onFeatureSelect: function(feature) {
         var map = feature.layer.map;
     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);
         if (feature.attributes.count > 1) {
             this.unselect(feature);
             var lonlat = new OpenLayers.LonLat(feature.geometry.x, feature.geometry.y);
+            var args = {
+                lonlat: lonlat,
+                layer: feature.layer,
+                count: feature.attributes.count
+            }
+            map.events.register("zoomend", args, SYP.onZoomClusterEnd);
+            SYP.selectControl.deactivate();
             map.setCenter(lonlat, map.zoom + 1);
             return;
         }
             map.setCenter(lonlat, map.zoom + 1);
             return;
         }