Changeset 5316
- Timestamp:
- 12/01/07 06:26:41 (1 year ago)
- Files:
-
- sandbox/ahocevar/styles/apidoc_config/Menu.txt (modified) (5 diffs)
- sandbox/ahocevar/styles/doc_config/Menu.txt (modified) (5 diffs)
- sandbox/ahocevar/styles/examples/modify-feature.html (modified) (3 diffs)
- sandbox/ahocevar/styles/examples/smoothDragging.html (modified) (1 diff)
- sandbox/ahocevar/styles/lib/OpenLayers/Control/ModifyFeature.js (modified) (7 diffs)
- sandbox/ahocevar/styles/lib/OpenLayers/Layer/Boxes.js (modified) (1 diff)
- sandbox/ahocevar/styles/lib/OpenLayers/Layer/Text.js (modified) (5 diffs)
- sandbox/ahocevar/styles/lib/OpenLayers/Layer/Vector.js (modified) (1 diff)
- sandbox/ahocevar/styles/lib/OpenLayers/Renderer/VML.js (modified) (1 diff)
- sandbox/ahocevar/styles/lib/OpenLayers/Tile/Image.js (modified) (5 diffs)
- sandbox/ahocevar/styles/lib/OpenLayers/Util.js (modified) (4 diffs)
- sandbox/ahocevar/styles/tests/Control/test_ModifyFeature.html (modified) (6 diffs)
- sandbox/ahocevar/styles/tests/Layer/test_Vector.html (modified) (2 diffs)
- sandbox/ahocevar/styles/tests/manual (copied) (copied from trunk/openlayers/tests/manual)
- sandbox/ahocevar/styles/tests/manual/google-panning.html (copied) (copied from trunk/openlayers/tests/manual/google-panning.html)
- sandbox/ahocevar/styles/tests/test_Util.html (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/ahocevar/styles/apidoc_config/Menu.txt
r4223 r5316 51 51 Group: Control { 52 52 53 File: Control ( no auto-title,OpenLayers/Control.js)53 File: Control (OpenLayers/Control.js) 54 54 File: ArgParser (no auto-title, OpenLayers/Control/ArgParser.js) 55 File: ZoomToMaxExtent (no auto-title, OpenLayers/Control/ZoomToMaxExtent.js) 56 File: OverviewMap (no auto-title, OpenLayers/Control/OverviewMap.js) 55 File: Attribution (no auto-title, OpenLayers/Control/Attribution.js) 57 56 File: DragFeature (no auto-title, OpenLayers/Control/DragFeature.js) 58 57 File: DragPan (no auto-title, OpenLayers/Control/DragPan.js) … … 61 60 File: KeyboardDefaults (no auto-title, OpenLayers/Control/KeyboardDefaults.js) 62 61 File: LayerSwitcher (no auto-title, OpenLayers/Control/LayerSwitcher.js) 62 File: ModifyFeature (no auto-title, OpenLayers/Control/ModifyFeature.js) 63 63 File: MouseDefaults (no auto-title, OpenLayers/Control/MouseDefaults.js) 64 64 File: MousePosition (no auto-title, OpenLayers/Control/MousePosition.js) … … 66 66 File: Navigation (no auto-title, OpenLayers/Control/Navigation.js) 67 67 File: NavToolbar (no auto-title, OpenLayers/Control/NavToolbar.js) 68 File: OverviewMap (no auto-title, OpenLayers/Control/OverviewMap.js) 68 69 File: Panel (no auto-title, OpenLayers/Control/Panel.js) 70 File: PanZoom (no auto-title, OpenLayers/Control/PanZoom.js) 69 71 File: PanZoomBar (no auto-title, OpenLayers/Control/PanZoomBar.js) 70 72 File: Permalink (no auto-title, OpenLayers/Control/Permalink.js) … … 72 74 File: SelectFeature (no auto-title, OpenLayers/Control/SelectFeature.js) 73 75 File: ZoomBox (no auto-title, OpenLayers/Control/ZoomBox.js) 74 File: PanZoom (OpenLayers/Control/PanZoom.js)76 File: ZoomToMaxExtent (no auto-title, OpenLayers/Control/ZoomToMaxExtent.js) 75 77 } # Group: Control 76 78 … … 79 81 Group: Feature { 80 82 81 File: Feature (no auto-title, OpenLayers/Feature.js) 83 File: Feature (OpenLayers/Feature.js) 84 File: Vector (no auto-title, OpenLayers/Feature/Vector.js) 82 85 File: WFS (no auto-title, OpenLayers/Feature/WFS.js) 83 File: Vector (no auto-title, OpenLayers/Feature/Vector.js)84 86 } # Group: Feature 85 87 sandbox/ahocevar/styles/doc_config/Menu.txt
r4223 r5316 53 53 File: Control (OpenLayers/Control.js) 54 54 File: ArgParser (no auto-title, OpenLayers/Control/ArgParser.js) 55 File: ZoomToMaxExtent (no auto-title, OpenLayers/Control/ZoomToMaxExtent.js) 56 File: OverviewMap (no auto-title, OpenLayers/Control/OverviewMap.js) 55 File: Attribution (no auto-title, OpenLayers/Control/Attribution.js) 57 56 File: DragFeature (no auto-title, OpenLayers/Control/DragFeature.js) 58 57 File: DragPan (no auto-title, OpenLayers/Control/DragPan.js) … … 61 60 File: KeyboardDefaults (no auto-title, OpenLayers/Control/KeyboardDefaults.js) 62 61 File: LayerSwitcher (no auto-title, OpenLayers/Control/LayerSwitcher.js) 62 File: ModifyFeature (no auto-title, OpenLayers/Control/ModifyFeature.js) 63 63 File: MouseDefaults (no auto-title, OpenLayers/Control/MouseDefaults.js) 64 64 File: MousePosition (no auto-title, OpenLayers/Control/MousePosition.js) … … 66 66 File: Navigation (no auto-title, OpenLayers/Control/Navigation.js) 67 67 File: NavToolbar (no auto-title, OpenLayers/Control/NavToolbar.js) 68 File: OverviewMap (no auto-title, OpenLayers/Control/OverviewMap.js) 68 69 File: Panel (no auto-title, OpenLayers/Control/Panel.js) 70 File: PanZoom (no auto-title, OpenLayers/Control/PanZoom.js) 69 71 File: PanZoomBar (no auto-title, OpenLayers/Control/PanZoomBar.js) 70 72 File: Permalink (no auto-title, OpenLayers/Control/Permalink.js) … … 72 74 File: SelectFeature (no auto-title, OpenLayers/Control/SelectFeature.js) 73 75 File: ZoomBox (no auto-title, OpenLayers/Control/ZoomBox.js) 74 File: PanZoom (no auto-title, OpenLayers/Control/PanZoom.js)76 File: ZoomToMaxExtent (no auto-title, OpenLayers/Control/ZoomToMaxExtent.js) 75 77 } # Group: Control 76 78 … … 80 82 81 83 File: Feature (OpenLayers/Feature.js) 84 File: Vector (no auto-title, OpenLayers/Feature/Vector.js) 82 85 File: WFS (no auto-title, OpenLayers/Feature/WFS.js) 83 File: Vector (no auto-title, OpenLayers/Feature/Vector.js)84 86 } # Group: Feature 85 87 sandbox/ahocevar/styles/examples/modify-feature.html
r4272 r5316 54 54 polygon: new OpenLayers.Control.DrawFeature(vectors, 55 55 OpenLayers.Handler.Polygon), 56 regular: new OpenLayers.Control.DrawFeature(vectors, 57 OpenLayers.Handler.RegularPolygon, 58 {handlerOptions: {sides: 5}}), 56 59 modify: new OpenLayers.Control.ModifyFeature(vectors, 57 60 modifyOptions) … … 66 69 } 67 70 71 function update() { 72 var rotate = document.getElementById("rotate").checked; 73 controls.modify.rotate = rotate; 74 var resize = document.getElementById("resize").checked; 75 controls.modify.resize = resize; 76 var drag = document.getElementById("drag").checked; 77 controls.modify.drag = drag; 78 var sides = parseInt(document.getElementById("sides").value); 79 sides = Math.max(3, isNaN(sides) ? 0 : sides); 80 controls.regular.handler.sides = sides; 81 var irregular = document.getElementById("irregular").checked; 82 controls.regular.handler.irregular = irregular; 83 } 68 84 69 85 function toggleControl(element) { … … 103 119 </li> 104 120 <li> 121 <input type="radio" name="type" value="regular" id="regularToggle" onclick="toggleControl(this);" /> 122 <label for="regularToggle">draw regular polygon</label> 123 <label for="sides"> - sides</label> 124 <input id="sides" type="text" size="2" maxlength="2" 125 name="sides" value="5" onchange="update()" /> 126 <ul> 127 <li> 128 <input id="irregular" type="checkbox" 129 name="irregular" onchange="update()" /> 130 <label for="irregular">irregular</label> 131 </li> 132 </ul> 133 </li> 134 <li> 105 135 <input type="radio" name="type" value="modify" id="modifyToggle" 106 136 onclick="toggleControl(this);" /> 107 137 <label for="modifyToggle">modify feature</label> 138 <ul> 139 <li> 140 <input id="rotate" type="checkbox" 141 name="rotate" onchange="update()" /> 142 <label for="rotate">allow rotation</label> 143 </li> 144 <li> 145 <input id="resize" type="checkbox" 146 name="resize" onchange="update()" /> 147 <label for="resize">allow resizing</label> 148 </li> 149 <li> 150 <input id="drag" type="checkbox" 151 name="drag" onchange="update()" /> 152 <label for="drag">allow dragging</label> 153 </li> 154 </ul> 108 155 </li> 109 156 </ul> sandbox/ahocevar/styles/examples/smoothDragging.html
r5230 r5316 9 9 </style> 10 10 11 <script src='http://maps.google.com/maps?file=api&v=2.82&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuh QtCjFYhdtNUZyqZQW2mFbq_dOIHBSGvjZ-C7_tXAXYdB-ehlOacmC_xA'></script>11 <script src='http://maps.google.com/maps?file=api&v=2.82&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script> 12 12 <script src='http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js'></script> 13 13 <script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script> sandbox/ahocevar/styles/lib/OpenLayers/Control/ModifyFeature.js
r5099 r5316 87 87 */ 88 88 virtualStyle: null, 89 89 90 /** 91 * APIProperty: rotate 92 * {Boolean} Allow rotation of feature instead of vertex modification. 93 */ 94 rotate: false, 95 96 /** 97 * APIProperty: resize 98 * {Boolean} Allow resizing of feature instead of vertex modification. 99 */ 100 resize: false, 101 102 /** 103 * Property: radiusHandle 104 * {<OpenLayers.Feature.Vector>} A handle for rotating/resizing a feature. 105 */ 106 radiusHandle: null, 107 108 /** 109 * APIProperty: drag 110 * {Boolean} Allow dragging of feature with a drag handle. 111 */ 112 drag: false, 113 114 /** 115 * Property: dragHandle 116 * {<OpenLayers.Feature.Vector>} A handle for dragging a feature. 117 */ 118 dragHandle: null, 119 90 120 /** 91 121 * APIProperty: onModificationStart … … 251 281 unselectFeature: function(feature) { 252 282 this.layer.removeFeatures(this.vertices); 253 this.layer.removeFeatures(this.virtualVertices);254 283 this.vertices = []; 284 this.layer.destroyFeatures(this.virtualVertices); 255 285 this.virtualVertices = []; 286 if(this.dragHandle) { 287 this.layer.destroyFeatures([this.dragHandle]); 288 delete this.dragHandle; 289 } 290 if(this.radiusHandle) { 291 this.layer.destroyFeatures([this.radiusHandle]); 292 delete this.radiusHandle; 293 } 256 294 this.feature = null; 257 295 this.dragControl.deactivate(); … … 275 313 dragStart: function(feature, pixel) { 276 314 // only change behavior if the feature is not in the vertices array 277 if(feature != this.feature && 278 OpenLayers.Util.indexOf(this.vertices, feature) == -1 && 279 OpenLayers.Util.indexOf(this.virtualVertices, feature) == -1) { 315 if(feature != this.feature && !feature.geometry.parent && 316 feature != this.dragHandle && feature != this.radiusHandle) { 280 317 if(this.feature) { 281 318 // unselect the currently selected feature … … 316 353 */ 317 354 dragVertex: function(vertex) { 355 /** 356 * Five cases: 357 * 1) dragging a simple point 358 * 2) dragging a virtual vertex 359 * 3) dragging a drag handle 360 * 4) dragging a radius handle 361 * 5) dragging a real vertex 362 */ 318 363 if(this.feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { 364 // dragging a simple point 319 365 if(this.feature != vertex) { 320 366 this.feature = vertex; 321 367 } 322 368 } else { 323 if(OpenLayers.Util.indexOf(this.virtualVertices, vertex) != -1) { 369 if(vertex._index) { 370 // dragging a virtual vertex 324 371 vertex.geometry.parent.addComponent(vertex.geometry, 325 372 vertex._index); 326 373 delete vertex._index; 327 374 OpenLayers.Util.removeItem(this.virtualVertices, vertex); 328 this.layer.removeFeatures(vertex); 329 } 330 } 331 this.layer.drawFeature(this.feature, this.selectControl.selectStyle); 332 this.layer.removeFeatures(this.virtualVertices); 375 } else if(vertex == this.dragHandle) { 376 // dragging a drag handle 377 this.layer.removeFeatures(this.vertices); 378 this.vertices = []; 379 if(this.radiusHandle) { 380 this.layer.destroyFeatures([this.radiusHandle]); 381 this.radiusHandle = null; 382 } 383 } 384 // dragging a radius handle - no special treatment 385 // dragging a real vertex - no special treatment 386 this.layer.destroyFeatures(this.virtualVertices); 387 this.virtualVertices = []; 388 this.layer.drawFeature(this.feature, this.selectControl.selectStyle); 389 } 333 390 // keep the vertex on top so it gets the mouseout after dragging 334 391 // this should be removed in favor of an option to draw under or … … 361 418 this.virtualVertices = []; 362 419 } 420 if(this.dragHandle) { 421 this.layer.destroyFeatures([this.dragHandle]); 422 this.dragHandle = null; 423 } 424 if(this.radiusHandle) { 425 this.layer.destroyFeatures([this.radiusHandle]); 426 this.radiusHandle = null; 427 } 363 428 if(this.feature && 364 429 this.feature.geometry.CLASS_NAME != "OpenLayers.Geometry.Point") { 365 this.collectVertices(this.feature.geometry); 366 this.layer.addFeatures(this.vertices); 367 this.layer.addFeatures(this.virtualVertices); 430 if(this.drag) { 431 this.collectDragHandle(); 432 } 433 if(this.rotate || this.resize) { 434 this.collectRadiusHandle(); 435 } else { 436 this.collectVertices(); 437 } 368 438 } 369 439 }, … … 386 456 if(vertex && 387 457 OpenLayers.Util.indexOf(this.vertices, vertex) != -1 && 388 !this.dragControl.dragHandler.dragging) { 458 !this.dragControl.dragHandler.dragging && 459 vertex.geometry.parent) { 389 460 // remove the vertex 390 461 vertex.geometry.parent.removeComponent(vertex.geometry); … … 443 514 } 444 515 } 445 } 446 collectComponentVertices(this.feature.geometry); 516 } 517 collectComponentVertices.call(this, this.feature.geometry); 518 this.layer.addFeatures(this.vertices); 519 this.layer.addFeatures(this.virtualVertices); 520 }, 521 522 /** 523 * Method: collectDragHandle 524 * Collect the drag handle for the selected geometry. 525 */ 526 collectDragHandle: function() { 527 var geometry = this.feature.geometry; 528 var center = geometry.getBounds().getCenterLonLat(); 529 var originGeometry = new OpenLayers.Geometry.Point( 530 center.lon, center.lat 531 ); 532 var origin = new OpenLayers.Feature.Vector(originGeometry); 533 originGeometry.move = function(x, y) { 534 OpenLayers.Geometry.Point.prototype.move.call(this, x, y); 535 geometry.move(x, y); 536 } 537 this.dragHandle = origin; 538 this.layer.addFeatures([this.dragHandle]); 539 }, 540 541 /** 542 * Method: collectRadiusHandle 543 * Collect the radius handle for the selected geometry. 544 */ 545 collectRadiusHandle: function() { 546 var geometry = this.feature.geometry; 547 var bounds = geometry.getBounds(); 548 var center = bounds.getCenterLonLat(); 549 var originGeometry = new OpenLayers.Geometry.Point( 550 center.lon, center.lat 551 ); 552 var radiusGeometry = new OpenLayers.Geometry.Point( 553 bounds.right, bounds.bottom 554 ); 555 var radius = new OpenLayers.Feature.Vector(radiusGeometry); 556 var resize = this.resize; 557 var rotate = this.rotate; 558 radiusGeometry.move = function(x, y) { 559 OpenLayers.Geometry.Point.prototype.move.call(this, x, y); 560 var dx1 = this.x - originGeometry.x; 561 var dy1 = this.y - originGeometry.y; 562 var dx0 = dx1 - x; 563 var dy0 = dy1 - y; 564 if(rotate) { 565 var a0 = Math.atan2(dy0, dx0); 566 var a1 = Math.atan2(dy1, dx1); 567 var angle = a1 - a0; 568 angle *= 180 / Math.PI; 569 geometry.rotate(angle, originGeometry); 570 } 571 if(resize) { 572 var l0 = Math.sqrt((dx0 * dx0) + (dy0 * dy0)); 573 var l1 = Math.sqrt((dx1 * dx1) + (dy1 * dy1)); 574 geometry.resize(l1 / l0, originGeometry); 575 } 576 } 577 this.radiusHandle = radius; 578 this.layer.addFeatures([this.radiusHandle]); 447 579 }, 448 580 sandbox/ahocevar/styles/lib/OpenLayers/Layer/Boxes.js
r4985 r5316 9 9 * 10 10 * Class: OpenLayers.Layer.Boxes 11 * Draw divs as 'bo es' on the layer.11 * Draw divs as 'boxes' on the layer. 12 12 * 13 13 * Inherits from: sandbox/ahocevar/styles/lib/OpenLayers/Layer/Text.js
r5028 r5316 9 9 * 10 10 * Class: OpenLayers.Layer.Text 11 * Tab seperated values file parsing code which creates a markers layer. 12 * 13 * Inherits from; 11 * This layer creates markers given data in a text file. The <location> 12 * property of the layer (specified as a property of the options argument 13 * in the <OpenLayers.Layer.Text> constructor) points to a tab delimited 14 * file with data used to create markers. 15 * 16 * The first row of the data file should be a header line with the column names 17 * of the data. Each column should be delimited by a tab space. The 18 * possible columns are: 19 * - *point* lat,lon of the point where a marker is to be placed 20 * - *lat* Latitude of the point where a marker is to be placed 21 * - *lon* Longitude of the point where a marker is to be placed 22 * - *iconURL* URL of marker icon to use. 23 * - *iconSize* Size of Icon to use. 24 * - *iconOffset* Where the top-left corner of the icon is to be placed 25 * relative to the latitude and longitude of the point. 26 * - *title* The text of the 'title' is placed inside an 'h2' marker 27 * inside a popup, which opens when the marker is clicked. 28 * - *description* The text of the 'description' is placed below the h2 29 * in the popup. this can be plain text or HTML. 30 * 31 * Example text file: 32 * (code) 33 * lat lon title description iconSize iconOffset icon 34 * 10 20 title description 21,25 -10,-25 http://www.openlayers.org/dev/img/marker.png 35 * (end) 36 * 37 * Inherits from: 14 38 * - <OpenLayers.Layer.Markers> 15 39 */ … … 18 42 /** 19 43 * APIProperty: location 20 * {String} store url of text file - this should be specified in the21 * "options" hashtable. Can not be changed once passed in.44 * {String} URL of text file. Must be specified in the "options" argument 45 * of the constructor. Can not be changed once passed in. 22 46 */ 23 47 location:null, … … 36 60 37 61 /** 38 * Constructor: OpenLayers.Layer.Text39 * Create a text layer.40 *41 * Parameters:42 * name - {String}43 * options - {Object} Hashtable of extra options to tag onto44 * the layer. Must include "location"property.45 */62 * Constructor: OpenLayers.Layer.Text 63 * Create a text layer. 64 * 65 * Parameters: 66 * name - {String} 67 * options - {Object} Object with properties to be set on the layer. 68 * Must include <location> property. 69 */ 46 70 initialize: function(name, options) { 47 71 OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments); … … 59 83 }, 60 84 61 /**85 /** 62 86 * APIMethod: destroy 63 87 */ … … 199 223 CLASS_NAME: "OpenLayers.Layer.Text" 200 224 }); 201 202 sandbox/ahocevar/styles/lib/OpenLayers/Layer/Vector.js
r5244 r5316 308 308 /** 309 309 * APIMethod: destroyFeatures 310 * Destroy all features on the layer and empty the selected features array. 311 */ 312 destroyFeatures: function () { 313 this.selectedFeatures = []; 314 for (var i = this.features.length - 1; i >= 0; i--) { 315 this.features[i].destroy(); 310 * Erase and estroy features on the layer. 311 * 312 * Parameters: 313 * features - {Array(<OpenLayers.Feature.Vector>)} An optional array of 314 * features to destroy. If not supplied, all features on the layer 315 * will be destroyed. 316 */ 317 destroyFeatures: function(features) { 318 var all = (features == undefined); 319 if(all) { 320 features = this.features; 321 this.selectedFeatures = []; 322 } 323 this.eraseFeatures(features); 324 var feature; 325 for(var i=features.length-1; i>=0; i--) { 326 feature = features[i]; 327 if(!all) { 328 OpenLayers.Util.removeItem(this.selectedFeatures, feature); 329 } 330 feature.destroy(); 316 331 } 317 332 }, sandbox/ahocevar/styles/lib/OpenLayers/Renderer/VML.js
r5312 r5316 141 141 * 142 142 * Parameters: 143 * node - {DOMElement} 143 * node - {DOMElement} An VML element to decorate 144 144 * style - {Object} 145 * options - {Object} 146 * isFilled - {Boolean}147 * isStroked -{Boolean}145 * options - {Object} Currently supported options include 146 * 'isFilled' {Boolean} and 147 * 'isStroked' {Boolean} 148 148 * geometry - {<OpenLayers.Geometry>} 149 149 */ sandbox/ahocevar/styles/lib/OpenLayers/Tile/Image.js
r5157 r5316 37 37 frame: null, 38 38 39 40 /** 41 * Property: layerAlphaHack 42 * {Boolean} True if the png alpha hack needs to be applied on the layer's div. 43 */ 44 layerAlphaHack: null, 45 39 46 /** TBD 3.0 - reorder the parameters to the init function to remove 40 47 * URL. the getUrl() function on the layer gets called on … … 59 66 this.frame.style.overflow = 'hidden'; 60 67 this.frame.style.position = 'absolute'; 68 69 this.layerAlphaHack = this.layer.alpha && OpenLayers.Util.alphaHack(); 61 70 }, 62 71 … … 116 125 117 126 var imageSize = this.layer.getImageSize(); 118 if (this.layer .alpha) {127 if (this.layerAlphaHack) { 119 128 OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, 120 129 null, null, imageSize, this.url); … … 147 156 var size = this.layer.getImageSize(); 148 157 149 if (this.layer .alpha) {158 if (this.layerAlphaHack) { 150 159 this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, 151 160 offset, … … 231 240 // from the map, in which case this check is not needed. 232 241 if (this.layer) { 233 var loaded = this.layer .alpha? this.imgDiv.firstChild.src : this.imgDiv.src;242 var loaded = this.layerAlphaHack ? this.imgDiv.firstChild.src : this.imgDiv.src; 234 243 if (!OpenLayers.Util.isEquivalentUrl(loaded, this.url)) { 235 244 this.imgDiv.style.display = "none"; sandbox/ahocevar/styles/lib/OpenLayers/Util.js
r5162 r5316 39 39 * APIFunction: extend 40 40 * Copy all properties of a source object to a destination object. Modifies 41 * the passed in destination object. 41 * the passed in destination object. Any properties on the source object 42 * that are set to undefined will not be (re)set on the destination object. 42 43 * 43 44 * Parameters: … … 51 52 if(destination && source) { 52 53 for(var property in source) { 53 destination[property] = source[property]; 54 value = source[property]; 55 if(value !== undefined) { 56 destination[property] = value; 57 } 54 58 } 55 59 /** … … 370 374 371 375 try { 372 filter = document.body.filters;376 filter = !!(document.body.filters); 373 377 } catch (e) { 374 378 } … … 490 494 /** 491 495 * Function: applyDefaults 492 * Takes a hashtable and copies any keys that don't exist from493 * another hashtable, by analogy with OpenLayers.Util.extend() from496 * Takes an object and copies any properties that don't exist from 497 * another properties, by analogy with OpenLayers.Util.extend() from 494 498 * Prototype.js. 495 499 * 496 500 * Parameters: 497 * to - {Object} 498 * from - {Object} 501 * to - {Object} The destination object. 502 * from - {Object} The source object. Any properties of this object that 503 * are undefined in the to object will be set on the to object. 504 * 505 * Returns: 506 * {Object} A reference to the to object. Note that the to argument is modified 507 * in place and returned by this function. 499 508 */ 500 509 OpenLayers.Util.applyDefaults = function (to, from) { 501 510 for (var key in from) { 502 if (to[key] == null) { 511 if (to[key] === undefined || 512 (from.hasOwnProperty 513 && from.hasOwnProperty(key) && !to.hasOwnProperty(key))) { 503 514 to[key] = from[key]; 504 515 } 505 516 } 517 /** 518 * IE doesn't include the toString property when iterating over an object's 519 * properties with the for(property in object) syntax. Explicitly check if 520 * the source has its own toString property. 521 */ 522 if(from.hasOwnProperty 523 && from.hasOwnProperty('toString') && !to.hasOwnProperty('toString')) { 524 to.toString = from.toString; 525 } 526 506 527 return to; 507 528 }; sandbox/ahocevar/styles/tests/Control/test_ModifyFeature.html
r5099 r5316 191 191 control.onModificationEnd = function (feature) { t.eq(feature.id, fakeFeature.id, "onModificationEnd got feature.") } 192 192 layer.removeFeatures = function(verts) { 193 t.ok(verts == 'a' || verts == 'b', "Verts removed correctly") 193 t.ok(verts == 'a', "Normal verts removed correctly"); 194 } 195 layer.destroyFeatures = function(verts) { 196 t.ok(verts == 'b', "Virtual verts destroyed correctly"); 194 197 } 195 198 control.unselectFeature(fakeFeature); … … 215 218 216 219 control.collectVertices = function() { 220 t.ok(true, "collectVertices called"); 217 221 this.vertices = 'a'; 218 222 this.virtualVertices = 'd'; 219 t.ok(true, "collectVertices called"); 223 layer.addFeatures(this.vertices); 224 layer.addFeatures(this.virtualVertices); 220 225 } 221 226 … … 243 248 244 249 function test_ModifyFeature_resetVertices(t) { 245 t.plan( 9);250 t.plan(15); 246 251 var layer = new OpenLayers.Layer.Vector(); 247 252 var control = new OpenLayers.Control.ModifyFeature(layer); … … 254 259 t.eq(control.vertices.length, 0, "Correct vertices length"); 255 260 t.eq(control.virtualVertices.length, 0, "Correct virtual vertices length."); 256 261 257 262 var multiPoint = new OpenLayers.Geometry.MultiPoint([point, point2]); 258 263 control.feature = new OpenLayers.Feature.Vector(multiPoint); … … 274 279 t.eq(control.virtualVertices.length, 3, "Correct virtual vertices length (polygon)."); 275 280 281 control.drag = true; 282 control.resetVertices(); 283 t.ok(control.dragHandle != null, "Drag handle is set"); 284 t.eq(control.vertices.length, 4, "Correct vertices length with polygon (drag)"); 285 286 control.rotate = true; 287 control.resetVertices(); 288 t.ok(control.radiusHandle != null, "Radius handle is set"); 289 t.eq(control.vertices.length, 0, "Correct vertices length with polygon (rotate)"); 290 291 control.rotate = false; 292 control.resize = true; 293 t.ok(control.radiusHandle != null, "Radius handle is set"); 294 t.eq(control.vertices.length, 0, "Correct vertices length with polygon (resize)"); 276 295 } 277 296 … … 290 309 'id': 'fakeFeature' 291 310 }; 292 control.collectVertices = function(geom) { 293 t.eq(geom.id, 'myGeom', "collect geom called"); 311 layer.addFeatures = function (verts) { 312 t.ok(verts == 'virtual' || verts == 'normal', verts + " verts correct"); 313 } 314 layer.removeFeatures = function (verts) { 315 t.ok(verts == 'previous virtual' || verts == 'previous normal', verts + " verts correct"); 316 } 317 control.onModification = function(feat) { 318 t.eq(feat.id, fakeFeature.id, "onModification gets correct feat"); 319 } 320 control.collectVertices = function() { 321 t.ok(true, "collectVertices called"); 294 322 this.vertices = 'normal'; 295 323 this.virtualVertices = 'virtual'; 296 } 297 layer.addFeatures = function (verts) { 298 t.ok(verts == 'virtual' || verts == 'normal', verts + " verts correct"); 299 } 300 layer.removeFeatures = function (verts) { 301 t.ok(verts == 'previous virtual' || verts == 'previous normal', verts + " verts correct"); 302 } 303 control.onModification = function(feat) { 304 t.eq(feat.id, fakeFeature.id, "onModification gets correct feat"); 324 layer.addFeatures(this.vertices); 325 layer.addFeatures(this.virtualVertices); 305 326 } 306 327 control.feature = fakeFeature; sandbox/ahocevar/styles/tests/Layer/test_Vector.html
r4356 r5316 131 131 132 132 function test_Layer_Vector_destroyFeatures (t) { 133 t.plan( 3);133 t.plan(5); 134 134 layer = new OpenLayers.Layer.Vector(name); 135 135 var map = new OpenLayers.Map('map'); … … 146 146 t.eq(layer.features.length, 0, "destroyFeatures triggers removal"); 147 147 t.eq(layer.selectedFeatures, [], "Destroy features removes selected features"); 148 features = []; 149 for (var i = 0; i < 5; i++) { 150 features.push(new OpenLayers.Feature.Vector( 151 new OpenLayers.Geometry.Point(0,0))); 152 } 153 layer.addFeatures(features); 154 layer.selectedFeatures.push(features[0]); 155 layer.selectedFeatures.push(features[1]); 156 layer.destroyFeatures([features[0], features[1]]); 157 t.eq(layer.features.length, 3, "destroyFeatures removes appropriate features"); 158 t.eq(layer.selectedFeatures, [], "destroyFeatures removes appropriate selected features"); 148 159 } 149 160 sandbox/ahocevar/styles/tests/test_Util.html
r5162 r5316 142 142 } 143 143 144 function test_ 06_Util_applyDefaults(t) {145 146 t.plan( 8);144 function test_Util_applyDefaults(t) { 145 146 t.plan(10); 147 147 148 148 var to = { 149 149 'a': "abra", 150 'b': "blorg" 150 'b': "blorg", 151 'n': null 151 152 }; 152 153 153 154 var from = { 154 155 'b': "zoink", 155 'c': "press" 156 'c': "press", 157 'toString': function() {return 'works'}, 158 'n': "broken" 156 159 }; 157 160 … … 168 171 t.eq( ret["b"], "blorg", "key present in ret and from, maintained in ret"); 169 172 t.eq( ret["c"], "press", "key present in from and not ret successfully copied to ret"); 173 t.eq(to.toString(), "works", "correctly applies custom toString"); 174 t.eq(to.n, null, "correctly preserves null"); 170 175 } 171 176 … … 587 592 588 593 function tests_Util_extend(t) { 589 t.plan( 5);594 t.plan(6); 590 595 591 596 var source = { … … 599 604 toString: function() { 600 605 return "source"; 601 } 602 }; 603 var destination = OpenLayers.Util.extend({}, source); 606 }, 607 nada: undefined 608 }; 609 var destination = OpenLayers.Util.extend({nada: "untouched"}, source); 604 610 t.eq(destination.num, source.num, 605 611 "extend properly sets primitive property on destination"); … … 610 616 t.eq(destination.toString(), "source", 611 617 "extend properly sets custom toString method"); 618 t.eq(destination.nada, "untouched", 619 "undefined source properties don't clobber existing properties"); 612 620 t.eq(window.property, undefined, "Property variable not clobbered."); 613 621 }
