[OpenLayers-Commits] r12255 - in trunk/openlayers: lib/OpenLayers/Control tests/Control

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Aug 17 09:47:10 EDT 2011


Author: bartvde
Date: 2011-08-17 06:47:08 -0700 (Wed, 17 Aug 2011)
New Revision: 12255

Modified:
   trunk/openlayers/lib/OpenLayers/Control/Snapping.js
   trunk/openlayers/tests/Control/Snapping.html
Log:
filter on snapping target does not work for all filter types, r=ahocevar (closes #3468)

Modified: trunk/openlayers/lib/OpenLayers/Control/Snapping.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/Snapping.js	2011-08-17 02:29:09 UTC (rev 12254)
+++ trunk/openlayers/lib/OpenLayers/Control/Snapping.js	2011-08-17 13:47:08 UTC (rev 12255)
@@ -476,7 +476,7 @@
             feature = features[i];
             if(feature !== this.feature && !feature._sketch &&
                feature.state !== OpenLayers.State.DELETE &&
-               (!target.filter || target.filter.evaluate(feature.attributes))) {
+               (!target.filter || target.filter.evaluate(feature))) {
                 if(feature.atPoint(ll, maxTolerance, maxTolerance)) {
                     for(var j=0, stop=Math.min(result.rank+1, numTypes); j<stop; ++j) {
                         type = this.precedence[j];

Modified: trunk/openlayers/tests/Control/Snapping.html
===================================================================
--- trunk/openlayers/tests/Control/Snapping.html	2011-08-17 02:29:09 UTC (rev 12254)
+++ trunk/openlayers/tests/Control/Snapping.html	2011-08-17 13:47:08 UTC (rev 12255)
@@ -236,6 +236,56 @@
         map.destroy();
     
     }
+
+    function test_filter(t) {
+        t.plan(3);
+        var map = new OpenLayers.Map("map", {
+            resolutions: [1],
+            maxExtent: new OpenLayers.Bounds(0, 0, 100, 100)
+        });
+
+        var layer1 = new OpenLayers.Layer.Vector(null, {
+            isBaseLayer: true
+        });
+        var f1 = new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT(
+            "LINESTRING(0 0, 10 10, 20 20, 30 30)"
+        ), {foo: 'bar'});
+        f1.fid = "FID1";
+        var f2 = new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT(
+            "LINESTRING(11 10, 20 10, 30 10)"
+        ), {foo: 'bar'});
+        f2.fid = "FID2";
+        layer1.addFeatures([f1, f2]);
+        map.addLayers([layer1]);
+        map.zoomToMaxExtent();
+
+        var control = new OpenLayers.Control.Snapping({
+            layer: layer1,
+            targets: [layer1],
+            defaults: {tolerance: 4}
+        });
+        control.activate();
+
+        var result;
+        var loc = new OpenLayers.Geometry.Point(1, 1);
+
+        control.setTargets([{layer: layer1}]);
+        result = control.testTarget(control.targets[0], loc);
+        t.ok(result !== null, "target is eligible without a filter set");
+        var filter = new OpenLayers.Filter.Logical({
+            type: OpenLayers.Filter.Logical.NOT, 
+            filters: [
+                new OpenLayers.Filter.FeatureId({fids: ["FID1", "FID2"]})
+            ]
+        });
+        control.setTargets([{layer: layer1, filter: filter}]);
+        result = control.testTarget(control.targets[0], loc);
+        t.ok(result === null, "target is not eligible with a filter set which excludes the target's features");
+        filter = new OpenLayers.Filter.Comparison({type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO, value: 'bar', property: 'foo'});
+        control.setTargets([{layer: layer1, filter: filter}]);
+        result = control.testTarget(control.targets[0], loc);
+        t.ok(result === null, "target is not eligible with a filter set which excludes the target's features using a comparison filter");
+    }
     
     function test_snapping(t) {
         



More information about the Commits mailing list