OpenLayers OpenLayers

Changeset 7541

Show
Ignore:
Timestamp:
07/18/08 01:28:25 (1 month ago)
Author:
tschaub
Message:

Adding basic measure control.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/topp/trimet/lib/OpenLayers.js

    r7496 r7541  
    151151            "OpenLayers/Control/Navigation.js", 
    152152            "OpenLayers/Control/MouseDefaults.js", 
     153            "OpenLayers/Control/Measure.js", 
    153154            "OpenLayers/Control/MousePosition.js", 
    154155            "OpenLayers/Control/OverviewMap.js", 
  • sandbox/topp/trimet/lib/OpenLayers/Handler/Path.js

    r7496 r7541  
    7474        this.point = new OpenLayers.Feature.Vector( 
    7575                                        new OpenLayers.Geometry.Point()); 
     76        this.layer.addFeatures([this.line, this.point]); 
    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     
     
    163171        } 
    164172        if(this.lastDown == null) { 
     173            if(this.persist) { 
     174                this.destroyFeature(); 
     175            } 
    165176            this.createFeature(); 
    166177        } 
     
    219230        if(this.drawing) { 
    220231            if(this.freehandMode(evt)) { 
     232                if(this.persist) { 
     233                    this.destroyPoint(); 
     234                } 
    221235                this.finalize(); 
    222236            } else { 
     
    246260            var index = this.line.geometry.components.length - 1; 
    247261            this.line.geometry.removeComponent(this.line.geometry.components[index]); 
     262            if(this.persist) { 
     263                this.destroyPoint(); 
     264            } 
    248265            this.finalize(); 
    249266        } 
  • sandbox/topp/trimet/lib/OpenLayers/Handler/Point.js

    r7496 r7541  
    6363     */ 
    6464    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, 
    6574 
    6675    /** 
     
    116125    createFeature: function() { 
    117126        this.point = new OpenLayers.Feature.Vector( 
    118                                               new OpenLayers.Geometry.Point()); 
     127            new OpenLayers.Geometry.Point() 
     128        ); 
     129        this.layer.addFeatures([this.point]); 
    119130    }, 
    120131 
     
    131142            this.cancel(); 
    132143        } 
     144        this.destroyFeature(); 
    133145        // If a layer's map property is set to null, it means that that layer 
    134146        // isn't added to the map. Since we ourself added the layer to the map 
     
    148160     */ 
    149161    destroyFeature: function() { 
    150         if(this.point) { 
    151             this.point.destroy(); 
    152         } 
     162        this.layer.destroyFeatures(); 
    153163        this.point = null; 
    154164    }, 
     
    164174    finalize: function(cancel) { 
    165175        var key = cancel ? "cancel" : "done"; 
    166         this.layer.renderer.clear(); 
    167176        this.drawing = false; 
    168177        this.mouseDown = false; 
     
    170179        this.lastUp = null; 
    171180        this.callback(key, [this.geometryClone()]); 
    172         this.destroyFeature(); 
     181        if(cancel || !this.persist) { 
     182            this.destroyFeature(); 
     183        } 
    173184    }, 
    174185 
     
    257268        } 
    258269        if(this.lastDown == null) { 
     270            if(this.persist) { 
     271                this.destroyFeature(); 
     272            } 
    259273            this.createFeature(); 
    260274        } 
  • sandbox/topp/trimet/lib/OpenLayers/Handler/Polygon.js

    r7496 r7541  
    6060        this.point = new OpenLayers.Feature.Vector( 
    6161                                        new OpenLayers.Geometry.Point()); 
     62        this.layer.addFeatures([this.polygon, this.point]); 
    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    }, 
     
    123121            var index = this.line.geometry.components.length - 2; 
    124122            this.line.geometry.removeComponent(this.line.geometry.components[index]); 
     123            if(this.persist) { 
     124                this.destroyPoint(); 
     125            } 
    125126            this.finalize(); 
    126127        }