OpenLayers OpenLayers

Changeset 5316

Show
Ignore:
Timestamp:
12/01/07 06:26:41 (1 year ago)
Author:
ahocevar
Message:

merging from r5246 to HEAD

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/ahocevar/styles/apidoc_config/Menu.txt

    r4223 r5316  
    5151   Group: Control  { 
    5252 
    53       File: Control  (no auto-title, OpenLayers/Control.js) 
     53      File: Control  (OpenLayers/Control.js) 
    5454      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) 
    5756      File: DragFeature  (no auto-title, OpenLayers/Control/DragFeature.js) 
    5857      File: DragPan  (no auto-title, OpenLayers/Control/DragPan.js) 
     
    6160      File: KeyboardDefaults  (no auto-title, OpenLayers/Control/KeyboardDefaults.js) 
    6261      File: LayerSwitcher  (no auto-title, OpenLayers/Control/LayerSwitcher.js) 
     62      File: ModifyFeature  (no auto-title, OpenLayers/Control/ModifyFeature.js) 
    6363      File: MouseDefaults  (no auto-title, OpenLayers/Control/MouseDefaults.js) 
    6464      File: MousePosition  (no auto-title, OpenLayers/Control/MousePosition.js) 
     
    6666      File: Navigation  (no auto-title, OpenLayers/Control/Navigation.js) 
    6767      File: NavToolbar  (no auto-title, OpenLayers/Control/NavToolbar.js) 
     68      File: OverviewMap  (no auto-title, OpenLayers/Control/OverviewMap.js) 
    6869      File: Panel  (no auto-title, OpenLayers/Control/Panel.js) 
     70      File: PanZoom  (no auto-title, OpenLayers/Control/PanZoom.js) 
    6971      File: PanZoomBar  (no auto-title, OpenLayers/Control/PanZoomBar.js) 
    7072      File: Permalink  (no auto-title, OpenLayers/Control/Permalink.js) 
     
    7274      File: SelectFeature  (no auto-title, OpenLayers/Control/SelectFeature.js) 
    7375      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) 
    7577      }  # Group: Control 
    7678 
     
    7981   Group: Feature  { 
    8082 
    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) 
    8285      File: WFS  (no auto-title, OpenLayers/Feature/WFS.js) 
    83       File: Vector  (no auto-title, OpenLayers/Feature/Vector.js) 
    8486      }  # Group: Feature 
    8587 
  • sandbox/ahocevar/styles/doc_config/Menu.txt

    r4223 r5316  
    5353      File: Control  (OpenLayers/Control.js) 
    5454      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) 
    5756      File: DragFeature  (no auto-title, OpenLayers/Control/DragFeature.js) 
    5857      File: DragPan  (no auto-title, OpenLayers/Control/DragPan.js) 
     
    6160      File: KeyboardDefaults  (no auto-title, OpenLayers/Control/KeyboardDefaults.js) 
    6261      File: LayerSwitcher  (no auto-title, OpenLayers/Control/LayerSwitcher.js) 
     62      File: ModifyFeature  (no auto-title, OpenLayers/Control/ModifyFeature.js) 
    6363      File: MouseDefaults  (no auto-title, OpenLayers/Control/MouseDefaults.js) 
    6464      File: MousePosition  (no auto-title, OpenLayers/Control/MousePosition.js) 
     
    6666      File: Navigation  (no auto-title, OpenLayers/Control/Navigation.js) 
    6767      File: NavToolbar  (no auto-title, OpenLayers/Control/NavToolbar.js) 
     68      File: OverviewMap  (no auto-title, OpenLayers/Control/OverviewMap.js) 
    6869      File: Panel  (no auto-title, OpenLayers/Control/Panel.js) 
     70      File: PanZoom  (no auto-title, OpenLayers/Control/PanZoom.js) 
    6971      File: PanZoomBar  (no auto-title, OpenLayers/Control/PanZoomBar.js) 
    7072      File: Permalink  (no auto-title, OpenLayers/Control/Permalink.js) 
     
    7274      File: SelectFeature  (no auto-title, OpenLayers/Control/SelectFeature.js) 
    7375      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) 
    7577      }  # Group: Control 
    7678 
     
    8082 
    8183      File: Feature  (OpenLayers/Feature.js) 
     84      File: Vector  (no auto-title, OpenLayers/Feature/Vector.js) 
    8285      File: WFS  (no auto-title, OpenLayers/Feature/WFS.js) 
    83       File: Vector  (no auto-title, OpenLayers/Feature/Vector.js) 
    8486      }  # Group: Feature 
    8587 
  • sandbox/ahocevar/styles/examples/modify-feature.html

    r4272 r5316  
    5454                polygon: new OpenLayers.Control.DrawFeature(vectors, 
    5555                            OpenLayers.Handler.Polygon), 
     56                regular: new OpenLayers.Control.DrawFeature(vectors, 
     57                            OpenLayers.Handler.RegularPolygon, 
     58                            {handlerOptions: {sides: 5}}), 
    5659                modify: new OpenLayers.Control.ModifyFeature(vectors, 
    5760                                                             modifyOptions) 
     
    6669        } 
    6770         
     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        } 
    6884 
    6985        function toggleControl(element) { 
     
    103119            </li> 
    104120            <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> 
    105135                <input type="radio" name="type" value="modify" id="modifyToggle" 
    106136                       onclick="toggleControl(this);" /> 
    107137                <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> 
    108155            </li> 
    109156        </ul> 
  • sandbox/ahocevar/styles/examples/smoothDragging.html

    r5230 r5316  
    99    </style> 
    1010 
    11     <script src='http://maps.google.com/maps?file=api&amp;v=2.82&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhQtCjFYhdtNUZyqZQW2mFbq_dOIHBSGvjZ-C7_tXAXYdB-ehlOacmC_xA'></script> 
     11    <script src='http://maps.google.com/maps?file=api&amp;v=2.82&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script> 
    1212    <script src='http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js'></script> 
    1313    <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  
    8787     */ 
    8888    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 
    90120    /** 
    91121     * APIProperty: onModificationStart  
     
    251281    unselectFeature: function(feature) { 
    252282        this.layer.removeFeatures(this.vertices); 
    253         this.layer.removeFeatures(this.virtualVertices); 
    254283        this.vertices = []; 
     284        this.layer.destroyFeatures(this.virtualVertices); 
    255285        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        } 
    256294        this.feature = null; 
    257295        this.dragControl.deactivate(); 
     
    275313    dragStart: function(feature, pixel) { 
    276314        // 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) { 
    280317            if(this.feature) { 
    281318                // unselect the currently selected feature 
     
    316353     */ 
    317354    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         */ 
    318363        if(this.feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { 
     364            // dragging a simple point 
    319365            if(this.feature != vertex) { 
    320366                this.feature = vertex; 
    321367            } 
    322368        } else { 
    323             if(OpenLayers.Util.indexOf(this.virtualVertices, vertex) != -1) { 
     369            if(vertex._index) { 
     370                // dragging a virtual vertex 
    324371                vertex.geometry.parent.addComponent(vertex.geometry, 
    325372                                                    vertex._index); 
    326373                delete vertex._index; 
    327374                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        } 
    333390        // keep the vertex on top so it gets the mouseout after dragging 
    334391        // this should be removed in favor of an option to draw under or 
     
    361418            this.virtualVertices = []; 
    362419        } 
     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        } 
    363428        if(this.feature && 
    364429           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            } 
    368438        } 
    369439    }, 
     
    386456            if(vertex && 
    387457               OpenLayers.Util.indexOf(this.vertices, vertex) != -1 && 
    388                !this.dragControl.dragHandler.dragging) { 
     458               !this.dragControl.dragHandler.dragging && 
     459               vertex.geometry.parent) { 
    389460                // remove the vertex 
    390461                vertex.geometry.parent.removeComponent(vertex.geometry); 
     
    443514                } 
    444515            } 
    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]); 
    447579    }, 
    448580 
  • sandbox/ahocevar/styles/lib/OpenLayers/Layer/Boxes.js

    r4985 r5316  
    99 * 
    1010 * Class: OpenLayers.Layer.Boxes 
    11  * Draw divs as 'boes' on the layer.  
     11 * Draw divs as 'boxes' on the layer.  
    1212 * 
    1313 * Inherits from: 
  • sandbox/ahocevar/styles/lib/OpenLayers/Layer/Text.js

    r5028 r5316  
    99 * 
    1010 * 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: 
    1438 *  - <OpenLayers.Layer.Markers> 
    1539 */ 
     
    1842    /** 
    1943     * APIProperty: location  
    20      * {String} store url of text file - this should be specified in the  
    21      *   "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.  
    2246     */ 
    2347    location:null, 
     
    3660 
    3761    /** 
    38     * Constructor: OpenLayers.Layer.Text 
    39     * Create a text layer. 
    40     *  
    41     * Parameters: 
    42     * name - {String}  
    43     * options - {Object} Hashtable of extra options to tag onto 
    44     *                    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    */ 
    4670    initialize: function(name, options) { 
    4771        OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments); 
     
    5983    }, 
    6084 
    61    /** 
     85    /** 
    6286     * APIMethod: destroy  
    6387     */ 
     
    199223    CLASS_NAME: "OpenLayers.Layer.Text" 
    200224}); 
    201       
    202      
  • sandbox/ahocevar/styles/lib/OpenLayers/Layer/Vector.js

    r5244 r5316  
    308308    /** 
    309309     * 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(); 
    316331        } 
    317332    }, 
  • sandbox/ahocevar/styles/lib/OpenLayers/Renderer/VML.js

    r5312 r5316  
    141141     * 
    142142     * Parameters: 
    143      * node - {DOMElement}  
     143     * node - {DOMElement} An VML element to decorate 
    144144     * 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} 
    148148     * geometry - {<OpenLayers.Geometry>} 
    149149     */ 
  • sandbox/ahocevar/styles/lib/OpenLayers/Tile/Image.js

    r5157 r5316  
    3737    frame: null,  
    3838 
     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 
    3946    /** TBD 3.0 - reorder the parameters to the init function to remove  
    4047     *             URL. the getUrl() function on the layer gets called on  
     
    5966        this.frame.style.overflow = 'hidden';  
    6067        this.frame.style.position = 'absolute';  
     68 
     69        this.layerAlphaHack = this.layer.alpha && OpenLayers.Util.alphaHack(); 
    6170    }, 
    6271 
     
    116125 
    117126        var imageSize = this.layer.getImageSize();  
    118         if (this.layer.alpha) { 
     127        if (this.layerAlphaHack) { 
    119128            OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, 
    120129                    null, null, imageSize, this.url); 
     
    147156        var size = this.layer.getImageSize();  
    148157      
    149         if (this.layer.alpha) { 
     158        if (this.layerAlphaHack) { 
    150159            this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, 
    151160                                                           offset, 
     
    231240        // from the map, in which case this check is not needed.   
    232241        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; 
    234243            if (!OpenLayers.Util.isEquivalentUrl(loaded, this.url)) { 
    235244                this.imgDiv.style.display = "none"; 
  • sandbox/ahocevar/styles/lib/OpenLayers/Util.js

    r5162 r5316  
    3939 * APIFunction: extend 
    4040 * 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. 
    4243 * 
    4344 * Parameters: 
     
    5152    if(destination && source) { 
    5253        for(var property in source) { 
    53             destination[property] = source[property]; 
     54            value = source[property]; 
     55            if(value !== undefined) { 
     56                destination[property] = value; 
     57            } 
    5458        } 
    5559        /** 
     
    370374     
    371375    try {  
    372         filter = document.body.filters
     376        filter = !!(document.body.filters)
    373377    } catch (e) { 
    374378    }     
     
    490494/**  
    491495 * Function: applyDefaults 
    492  * Takes a hashtable and copies any keys that don't exist from 
    493  *     another hashtable, by analogy with OpenLayers.Util.extend() from 
     496 * Takes an object and copies any properties that don't exist from 
     497 *     another properties, by analogy with OpenLayers.Util.extend() from 
    494498 *     Prototype.js. 
    495499 *  
    496500 * 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. 
    499508 */ 
    500509OpenLayers.Util.applyDefaults = function (to, from) { 
    501510    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))) { 
    503514            to[key] = from[key]; 
    504515        } 
    505516    } 
     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     
    506527    return to; 
    507528}; 
  • sandbox/ahocevar/styles/tests/Control/test_ModifyFeature.html

    r5099 r5316  
    191191        control.onModificationEnd = function (feature) { t.eq(feature.id, fakeFeature.id, "onModificationEnd got feature.") } 
    192192        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"); 
    194197        } 
    195198        control.unselectFeature(fakeFeature); 
     
    215218         
    216219        control.collectVertices = function() {  
     220          t.ok(true, "collectVertices called");  
    217221          this.vertices = 'a'; 
    218222          this.virtualVertices = 'd'; 
    219           t.ok(true, "collectVertices called");  
     223          layer.addFeatures(this.vertices); 
     224          layer.addFeatures(this.virtualVertices); 
    220225        } 
    221226         
     
    243248 
    244249    function test_ModifyFeature_resetVertices(t) { 
    245         t.plan(9); 
     250        t.plan(15); 
    246251        var layer = new OpenLayers.Layer.Vector(); 
    247252        var control = new OpenLayers.Control.ModifyFeature(layer); 
     
    254259        t.eq(control.vertices.length, 0, "Correct vertices length"); 
    255260        t.eq(control.virtualVertices.length, 0, "Correct virtual vertices length."); 
    256          
     261 
    257262        var multiPoint = new OpenLayers.Geometry.MultiPoint([point, point2]); 
    258263        control.feature = new OpenLayers.Feature.Vector(multiPoint); 
     
    274279        t.eq(control.virtualVertices.length, 3, "Correct virtual vertices length (polygon)."); 
    275280 
     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)"); 
    276295    }     
    277296         
     
    290309         'id': 'fakeFeature' 
    291310        }; 
    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"); 
    294322            this.vertices = 'normal'; 
    295323            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); 
    305326        } 
    306327        control.feature = fakeFeature; 
  • sandbox/ahocevar/styles/tests/Layer/test_Vector.html

    r4356 r5316  
    131131 
    132132    function test_Layer_Vector_destroyFeatures (t) { 
    133         t.plan(3);  
     133        t.plan(5);  
    134134        layer = new OpenLayers.Layer.Vector(name); 
    135135        var map = new OpenLayers.Map('map'); 
     
    146146        t.eq(layer.features.length, 0, "destroyFeatures triggers removal"); 
    147147        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"); 
    148159    } 
    149160 
  • sandbox/ahocevar/styles/tests/test_Util.html

    r5162 r5316  
    142142    } 
    143143 
    144     function test_06_Util_applyDefaults(t) { 
    145      
    146         t.plan(8); 
     144    function test_Util_applyDefaults(t) { 
     145     
     146        t.plan(10); 
    147147         
    148148        var to = {  
    149149            'a': "abra", 
    150             'b': "blorg" 
     150            'b': "blorg", 
     151            'n': null 
    151152        }; 
    152153 
    153154        var from = {  
    154155            'b': "zoink", 
    155             'c': "press" 
     156            'c': "press", 
     157            'toString': function() {return 'works'}, 
     158            'n': "broken" 
    156159        }; 
    157160 
     
    168171        t.eq( ret["b"], "blorg", "key present in ret and from, maintained in ret"); 
    169172        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"); 
    170175    } 
    171176 
     
    587592 
    588593    function tests_Util_extend(t) { 
    589         t.plan(5); 
     594        t.plan(6); 
    590595 
    591596        var source = { 
     
    599604            toString: function() { 
    600605                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); 
    604610        t.eq(destination.num, source.num, 
    605611             "extend properly sets primitive property on destination"); 
     
    610616        t.eq(destination.toString(), "source", 
    611617             "extend properly sets custom toString method"); 
     618        t.eq(destination.nada, "untouched", 
     619             "undefined source properties don't clobber existing properties"); 
    612620        t.eq(window.property, undefined, "Property variable not clobbered."); 
    613621    }