OpenLayers OpenLayers

Changeset 7961

Show
Ignore:
Timestamp:
09/05/08 07:32:17 (3 months ago)
Author:
elemoine
Message:

apply patch attached to #1698 (sketch handler updates)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/camptocamp/unhcr/lib/OpenLayers/Handler/Path.js

    r7875 r7961  
    7474        this.point = new OpenLayers.Feature.Vector( 
    7575                                        new OpenLayers.Geometry.Point()); 
     76        this.layer.addFeatures([this.line, this.point], {silent: true}); 
    7677    }, 
    7778         
     
    8283    destroyFeature: function() { 
    8384        OpenLayers.Handler.Point.prototype.destroyFeature.apply(this); 
    84         if(this.line) { 
    85             this.line.destroy(); 
    86         } 
    8785        this.line = null; 
     86    }, 
     87 
     88    /** 
     89     * Method: destroyPoint 
     90     * Destroy the temporary point. 
     91     */ 
     92    destroyPoint: function() { 
     93        if(this.point) { 
     94            this.layer.destroyFeatures([this.point]); 
     95        } 
    8896    }, 
    8997     
     
    96104        this.line.geometry.addComponent(this.point.geometry.clone(), 
    97105                                        this.line.geometry.components.length); 
    98         this.callback("point", [this.point.geometry]); 
     106        this.callback("point", [this.point.geometry, this.getGeometry()]); 
    99107    }, 
    100108     
     
    132140 
    133141    /** 
    134      * Method: geometryClone 
    135      * Return a clone of the relevant geometry. 
     142     * Method: getGeometry 
     143     * Return the sketch geometry.  If <multi> is true, this will return 
     144     *     a multi-part geometry. 
    136145     * 
    137146     * Returns: 
    138147     * {<OpenLayers.Geometry.LineString>} 
    139148     */ 
    140     geometryClone: function() { 
    141         return this.line.geometry.clone(); 
     149    getGeometry: function() { 
     150        var geometry = this.line.geometry; 
     151        if(this.multi) { 
     152            geometry = new OpenLayers.Geometry.MultiLineString([geometry]); 
     153        } 
     154        return geometry; 
    142155    }, 
    143156 
     
    159172        } 
    160173        if(this.lastDown == null) { 
     174            if(this.persist) { 
     175                this.destroyFeature(); 
     176            } 
    161177            this.createFeature(); 
    162178        } 
     
    166182        this.point.geometry.x = lonlat.lon; 
    167183        this.point.geometry.y = lonlat.lat; 
     184        this.point.geometry.clearBounds(); 
    168185        if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) { 
    169186            this.addPoint(); 
     
    216233        if(this.drawing) { 
    217234            if(this.freehandMode(evt)) { 
     235                if(this.persist) { 
     236                    this.destroyPoint(); 
     237                } 
    218238                this.finalize(); 
    219239            } else { 
     
    243263            var index = this.line.geometry.components.length - 1; 
    244264            this.line.geometry.removeComponent(this.line.geometry.components[index]); 
     265            if(this.persist) { 
     266                this.destroyPoint(); 
     267            } 
    245268            this.finalize(); 
    246269        } 
  • sandbox/camptocamp/unhcr/lib/OpenLayers/Handler/Point.js

    r7785 r7961  
    3434     
    3535    /** 
     36     * Property: multi 
     37     * {Boolean} Cast features to multi-part geometries before passing to the 
     38     *     layer.  Default is false. 
     39     */ 
     40    multi: false, 
     41     
     42    /** 
    3643     * Property: drawing  
    3744     * {Boolean} A point is being drawn 
     
    5663     */ 
    5764    lastUp: null, 
     65 
     66    /** 
     67     * APIProperty: persist 
     68     * {Boolean} Leave the feature rendered until destroyFeature is called. 
     69     *     Default is false.  If set to true, the feature remains rendered until 
     70     *     destroyFeature is called, typically by deactivating the handler or 
     71     *     starting another drawing. 
     72     */ 
     73    persist: false, 
     74 
     75    /** 
     76     * Property: layerOptions 
     77     * {Object} Any optional properties to be set on the sketch layer. 
     78     */ 
     79    layerOptions: null, 
    5880 
    5981    /** 
     
    90112        // create temporary vector layer for rendering geometry sketch 
    91113        // TBD: this could be moved to initialize/destroy - setting visibility here 
    92         var options =
     114        var options = OpenLayers.Util.extend(
    93115            displayInLayerSwitcher: false, 
    94116            // indicate that the temp vector layer will never be out of range 
     
    97119            // correctly 
    98120            calculateInRange: function() { return true; } 
    99         }
     121        }, this.layerOptions)
    100122        this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); 
    101123        this.map.addLayer(this.layer); 
     
    109131    createFeature: function() { 
    110132        this.point = new OpenLayers.Feature.Vector( 
    111                                               new OpenLayers.Geometry.Point()); 
     133            new OpenLayers.Geometry.Point() 
     134        ); 
     135        this.layer.addFeatures([this.point], {silent: true}); 
    112136    }, 
    113137 
     
    124148            this.cancel(); 
    125149        } 
     150        this.destroyFeature(); 
    126151        // If a layer's map property is set to null, it means that that layer 
    127152        // isn't added to the map. Since we ourself added the layer to the map 
     
    141166     */ 
    142167    destroyFeature: function() { 
    143         if(this.point) { 
    144             this.point.destroy(); 
     168        if(this.layer) { 
     169            this.layer.destroyFeatures(); 
    145170        } 
    146171        this.point = null; 
     
    150175     * Method: finalize 
    151176     * Finish the geometry and call the "done" callback. 
    152      */ 
    153     finalize: function() { 
    154         this.layer.renderer.clear(); 
     177     * 
     178     * Parameters: 
     179     * cancel - {Boolean} Call cancel instead of done callback.  Default is 
     180     *     false. 
     181     */ 
     182    finalize: function(cancel) { 
     183        var key = cancel ? "cancel" : "done"; 
    155184        this.drawing = false; 
    156185        this.mouseDown = false; 
    157186        this.lastDown = null; 
    158187        this.lastUp = null; 
    159         this.callback("done", [this.geometryClone()]); 
    160         this.destroyFeature(); 
     188        this.callback(key, [this.geometryClone()]); 
     189        if(cancel || !this.persist) { 
     190            this.destroyFeature(); 
     191        } 
    161192    }, 
    162193 
     
    166197     */ 
    167198    cancel: function() { 
    168         this.layer.renderer.clear(); 
    169         this.drawing = false; 
    170         this.mouseDown = false; 
    171         this.lastDown = null; 
    172         this.lastUp = null; 
    173         this.callback("cancel", [this.geometryClone()]); 
    174         this.destroyFeature(); 
     199        this.finalize(true); 
    175200    }, 
    176201 
     
    216241     
    217242    /** 
     243     * Method: getGeometry 
     244     * Return the sketch geometry.  If <multi> is true, this will return 
     245     *     a multi-part geometry. 
     246     * 
     247     * Returns: 
     248     * {<OpenLayers.Geometry.Point>} 
     249     */ 
     250    getGeometry: function() { 
     251        var geometry = this.point.geometry; 
     252        if(this.multi) { 
     253            geometry = new OpenLayers.Geometry.MultiPoint([geometry]); 
     254        } 
     255        return geometry; 
     256    }, 
     257 
     258    /** 
    218259     * Method: geometryClone 
    219260     * Return a clone of the relevant geometry. 
    220261     * 
    221262     * Returns: 
    222      * {<OpenLayers.Geometry.Point>} 
     263     * {<OpenLayers.Geometry>} 
    223264     */ 
    224265    geometryClone: function() { 
    225         return this.point.geometry.clone(); 
     266        return this.getGeometry().clone(); 
    226267    }, 
    227268   
     
    247288        } 
    248289        if(this.lastDown == null) { 
     290            if(this.persist) { 
     291                this.destroyFeature(); 
     292            } 
    249293            this.createFeature(); 
    250294        } 
     
    254298        this.point.geometry.x = lonlat.lon; 
    255299        this.point.geometry.y = lonlat.lat; 
     300        this.point.geometry.clearBounds(); 
    256301        this.drawFeature(); 
    257302        return false; 
  • sandbox/camptocamp/unhcr/lib/OpenLayers/Handler/Polygon.js

    r7785 r7961  
    6060        this.point = new OpenLayers.Feature.Vector( 
    6161                                        new OpenLayers.Geometry.Point()); 
     62        this.layer.addFeatures([this.polygon, this.point], {silent: true}); 
    6263    }, 
    6364 
     
    6869    destroyFeature: function() { 
    6970        OpenLayers.Handler.Path.prototype.destroyFeature.apply(this); 
    70         if(this.polygon) { 
    71             this.polygon.destroy(); 
    72         } 
    7371        this.polygon = null; 
    7472    }, 
     
    9492        this.layer.drawFeature(this.point, this.style); 
    9593    }, 
    96  
     94     
    9795    /** 
    98      * Method: geometryClone 
    99      * Return a clone of the relevant geometry. 
     96     * Method: getGeometry 
     97     * Return the sketch geometry.  If <multi> is true, this will return 
     98     *     a multi-part geometry. 
    10099     * 
    101100     * Returns: 
    102101     * {<OpenLayers.Geometry.Polygon>} 
    103102     */ 
    104     geometryClone: function() { 
    105         return this.polygon.geometry.clone(); 
     103    getGeometry: function() { 
     104        var geometry = this.polygon.geometry; 
     105        if(this.multi) { 
     106            geometry = new OpenLayers.Geometry.MultiPolygon([geometry]); 
     107        } 
     108        return geometry; 
    106109    }, 
    107110 
     
    119122            var index = this.line.geometry.components.length - 2; 
    120123            this.line.geometry.removeComponent(this.line.geometry.components[index]); 
     124            if(this.persist) { 
     125                this.destroyPoint(); 
     126            } 
    121127            this.finalize(); 
    122128        }