Ticket #1071: patch-1071-r7546-A0.diff
| File patch-1071-r7546-A0.diff, 13.3 kB (added by pgiraud, 1 month ago) |
|---|
-
theme/default/style.css
old new 215 215 background-position: 0px 1px; 216 216 } 217 217 218 .olHandlerBoxZoomBox {218 .olHandlerBoxZoomBox, .olHandlerBoxFeatureSelect { 219 219 border: 2px solid red; 220 220 position: absolute; 221 221 background-color: white; -
tests/BaseTypes/Bounds.html
old new 196 196 197 197 } 198 198 199 200 function test_Bounds_intersects(t){ 201 t.plan(2); 202 203 var bounds = new OpenLayers.Bounds(-20, -10, 20, 10); 204 205 // intersects 206 var geometry = new OpenLayers.Geometry.Point(0, 0); 207 t.ok( bounds.intersects(geometry), "(" + bounds.toBBOX() + ") correctly intersects (" + geometry + ")"); 208 209 // no intersect 210 geometry = new OpenLayers.Geometry.Point(-50, 0); 211 t.ok( !bounds.intersects(geometry), "(" + bounds.toBBOX() + ") doesn't intersect (" + geometry + ")"); 212 } 213 199 214 function test_Bounds_containsBounds(t) { 200 215 t.plan( 35 ); 201 216 containerBounds = new OpenLayers.Bounds(10,10,40,40); -
tests/Control/SelectFeature.html
old new 18 18 } 19 19 20 20 function test_Control_SelectFeature_destroy(t) { 21 t.plan( 1);21 t.plan(2); 22 22 var map = new OpenLayers.Map("map"); 23 23 var layer = new OpenLayers.Layer.Vector(); 24 24 map.addLayer(layer); 25 var control = new OpenLayers.Control.SelectFeature(layer );26 control. handler.destroy= function() {25 var control = new OpenLayers.Control.SelectFeature(layer, {box: true}); 26 control.featureHandler.deactivate = function() { 27 27 t.ok(true, 28 "control.de stroy calls destroyon feature handler");28 "control.deactivate calls deactivate on feature handler"); 29 29 } 30 control.boxHandler.deactivate = function() { 31 t.ok(true, 32 "control.deactivate calls deactivate on box handler"); 33 } 30 34 // should nullify the layer property here 31 35 control.destroy(); 32 36 … … 61 65 }; 62 66 // mock up active control 63 67 var control = new OpenLayers.Control.SelectFeature(layer); 64 control. handler = {68 control.featureHandler = { 65 69 evt: {} 66 70 }; 67 71 // mock up features … … 110 114 111 115 } 112 116 117 function test_Control_SelectFeature_box(t) { 118 t.plan(3); 119 var map = new OpenLayers.Map("map"); 120 var layer = new OpenLayers.Layer.Vector(); 121 map.addLayer(layer); 122 var control = new OpenLayers.Control.SelectFeature(layer, {'multiple': true, box: true }); 123 var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0)); 124 var feature2 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,1)); 125 var feature3 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(-2,-2)); 126 layer.addFeatures([feature,feature2,feature3]); 127 control.setMap(map); 128 map.getLonLatFromPixel = function(arg) { 129 return new OpenLayers.LonLat(arg.x, arg.y); 130 } 131 control.selectBox(new OpenLayers.Bounds(-1, -1, 2, 2)); 132 t.eq(layer.selectedFeatures.length, 2, "box around all features selects all features."); 133 134 control.selectBox(new OpenLayers.Bounds(-3, -3, -1, -1)); 135 t.eq(layer.selectedFeatures.length, 3, "box around other features doesn't turn off already selected features."); 136 137 control.multipleSelect = function() { 138 return false; 139 }; 140 control.selectBox(new OpenLayers.Bounds(-3, -3, -1, -1)); 141 t.eq(layer.selectedFeatures.length, 1, "box around other features correctly turns off already selected features.") 142 143 } 144 113 145 function test_Control_SelectFeature_activate(t) { 114 t.plan( 2);146 t.plan(4); 115 147 var map = new OpenLayers.Map("map"); 116 148 var layer = new OpenLayers.Layer.Vector(); 117 149 map.addLayer(layer); 118 var control = new OpenLayers.Control.SelectFeature(layer );150 var control = new OpenLayers.Control.SelectFeature(layer, {box: true}); 119 151 map.addControl(control); 120 t.ok(!control. handler.active,152 t.ok(!control.featureHandler.active, 121 153 "feature handler is not active prior to activating control"); 154 t.ok(!control.boxHandler.active, 155 "box handler is not active prior to activating control"); 122 156 control.activate(); 123 t.ok(control. handler.active,157 t.ok(control.featureHandler.active, 124 158 "feature handler is active after activating control"); 159 t.ok(control.boxHandler.active, 160 "box handler is active after activating control"); 125 161 } 126 162 127 163 function test_Control_SelectFeature_deactivate(t) { 128 t.plan( 1);164 t.plan(2); 129 165 var map = new OpenLayers.Map("map"); 130 166 var layer = new OpenLayers.Layer.Vector(); 131 167 map.addLayer(layer); 132 var control = new OpenLayers.Control.SelectFeature(layer );168 var control = new OpenLayers.Control.SelectFeature(layer, {box: true}); 133 169 map.addControl(control); 134 170 135 171 control.activate(); 136 control. handler.deactivate = function() {172 control.featureHandler.deactivate = function() { 137 173 t.ok(true, 138 174 "control.deactivate calls deactivate on feature handler"); 139 175 } 176 control.boxHandler.deactivate = function() { 177 t.ok(true, 178 "control.deactivate calls deactivate on box handler"); 179 } 140 180 control.deactivate(); 141 181 } 142 182 -
lib/OpenLayers/BaseTypes/Bounds.js
old new 381 381 }, 382 382 383 383 /** 384 * APIMethod: intersects 385 * Converts the current bounds into a LinearRing to check for 386 * intersection with the given geometry 387 * 388 * Parameters: 389 * geometry - {<OpenLayers.Geometry>} 390 * 391 * Returns: 392 * {Boolean} The passed-in geometry object intersects this bounds. 393 */ 394 intersects: function(geometry) { 395 return this.toGeometry().intersects(geometry); 396 }, 397 398 /** 384 399 * APIMethod: containsBounds 385 400 * 386 401 * bounds - {<OpenLayers.Bounds>} -
lib/OpenLayers/Control/SelectFeature.js
old new 60 60 hover: false, 61 61 62 62 /** 63 * APIProperty: box 64 * {Boolean} Allow feature selection by drawing a box. 65 */ 66 box: false, 67 68 /** 63 69 * APIProperty: onSelect 64 70 * {Function} Optional function to be called when a feature is selected. 65 71 * The function should expect to be called with a feature. … … 88 94 89 95 /** 90 96 * APIProperty: callbacks 91 * {Object} The functions that are sent to the handler for callback97 * {Object} The functions that are sent to the featureHandler for callback 92 98 */ 93 99 callbacks: null, 94 100 … … 106 112 renderIntent: "select", 107 113 108 114 /** 109 * Property: handler115 * Property: featureHandler 110 116 * {<OpenLayers.Handler.Feature>} 111 117 */ 112 handler: null,118 featureHandler: null, 113 119 114 120 /** 115 121 * Constructor: <OpenLayers.Control.SelectFeature> … … 127 133 over: this.overFeature, 128 134 out: this.outFeature 129 135 }, this.callbacks); 130 var handlerOptions = { geometryTypes: this.geometryTypes};131 this. handler = new OpenLayers.Handler.Feature(this, layer,136 var featureHandlerOptions = { geometryTypes: this.geometryTypes}; 137 this.featureHandler = new OpenLayers.Handler.Feature(this, layer, 132 138 this.callbacks, 133 handlerOptions); 139 featureHandlerOptions); 140 141 if (this.box) { 142 this.boxHandler = new OpenLayers.Handler.Box( this, 143 {done: this.selectBox}, 144 { 145 //keyMask: // we don't want to set any keyMask for box 146 boxDivClassName: "olHandlerBoxFeatureSelect" 147 } 148 ); 149 } 134 150 }, 135 151 136 152 /** … … 188 204 * {Boolean} Allow for multiple selected features. 189 205 */ 190 206 multipleSelect: function() { 191 return this.multiple || this. handler.evt[this.multipleKey];207 return this.multiple || this.featureHandler.evt[this.multipleKey]; 192 208 }, 193 209 194 210 /** … … 200 216 * {Boolean} Toggle the selected state of a feature. 201 217 */ 202 218 toggleSelect: function() { 203 return this.toggle || this. handler.evt[this.toggleKey];219 return this.toggle || this.featureHandler.evt[this.toggleKey]; 204 220 }, 205 221 206 222 /** … … 279 295 this.layer.events.triggerEvent("featureunselected", {feature: feature}); 280 296 this.onUnselect(feature); 281 297 }, 298 299 /** 300 * Method: activate 301 */ 302 activate: function() { 303 this.featureHandler.activate(); 304 if (this.boxHandler) { 305 this.boxHandler.activate(); 306 } 307 return OpenLayers.Control.prototype.activate.apply(this,arguments); 308 }, 309 310 /** 311 * Method: deactivate 312 */ 313 deactivate: function() { 314 if (this.boxHandler) { 315 this.boxHandler.deactivate(); 316 } 317 this.featureHandler.deactivate(); 318 return OpenLayers.Control.prototype.deactivate.apply(this,arguments); 319 }, 282 320 321 /** 322 * Method: destroy 323 */ 324 destroy: function() { 325 this.featureHandler.destroy(); 326 if (this.boxHandler) { 327 this.boxHandler.destroy(); 328 } 329 return OpenLayers.Control.prototype.destroy.apply(this,arguments); 330 }, 331 332 /** 333 * Method: selectBox 334 * Callback from the boxHandler set up when multiple feature selection is on. 335 * depending on the inclusiveBox setting, will either select all features which 336 * intersect the given bounds, or toggle the feature selection status. 337 * If passed a bounds (shift-click) has no effect. 338 * 339 * Parameters: 340 * feature - {<OpenLayers.Bounds> || <OpenLayers.LonLat> } 341 */ 342 selectBox: function (position) { 343 if (position instanceof OpenLayers.Bounds) { 344 var minXY = this.map.getLonLatFromPixel( 345 new OpenLayers.Pixel(position.left, position.bottom)); 346 var maxXY = this.map.getLonLatFromPixel( 347 new OpenLayers.Pixel(position.right, position.top)); 348 var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, 349 maxXY.lon, maxXY.lat); 350 351 // if multiple is false, first deselect currently selected features 352 if (!this.multipleSelect()) { 353 this.unselectAll(); 354 } 355 356 // because we're using a box, we consider we want multiple selection 357 var prevMultiple = this.multiple; 358 this.multiple = true; 359 for(var i = 0; i < this.layer.features.length; i++) { 360 var feature = this.layer.features[i]; 361 if (bounds.intersects(feature.geometry)) { 362 if (OpenLayers.Util.indexOf(this.layer.selectedFeatures, feature) == -1) { 363 this.select(feature); 364 } 365 } 366 } 367 this.multiple = prevMultiple; 368 } 369 }, 370 283 371 /** 284 372 * Method: setMap 285 373 * Set the map property for the control. … … 288 376 * map - {<OpenLayers.Map>} 289 377 */ 290 378 setMap: function(map) { 291 this.handler.setMap(map); 379 this.featureHandler.setMap(map); 380 if (this.box) { 381 this.boxHandler.setMap(map); 382 } 292 383 OpenLayers.Control.prototype.setMap.apply(this, arguments); 293 384 }, 294 385 -
examples/select-feature.html
old new 41 41 clickout: false, toggle: false, 42 42 multiple: false, hover: false, 43 43 toggleKey: "ctrlKey", // ctrl key removes from selection 44 multipleKey: "shiftKey" // shift key adds to selection 44 multipleKey: "shiftKey", // shift key adds to selection 45 box: true 45 46 } 46 47 ) 47 48 };
