OpenLayers OpenLayers

Changeset 2254

Show
Ignore:
Timestamp:
02/21/07 08:47:43 (2 years ago)
Author:
oterral
Message:

MeasureArea and MeasureDistance have been added to the butonBar.html example

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/oterral/ButtonBar/vector/examples/Buttonbar.html

    r2253 r2254  
    8686   var dragpan=new OpenLayers.MouseListener.DragPan("dragpan","panning-hand-off.png", "panning-hand-on.png","radioButton",optionsTools); 
    8787   var measuredistance=new OpenLayers.MouseListener.MeasureDistance("measuredistance","MeasureEnable.png", "MeasureDisable.png","radioButton",optionsTools); 
     88    var measurearea=new OpenLayers.MouseListener.MeasureArea("measurearea","MeasureEnable.png", "MeasureDisable.png","radioButton",optionsTools); 
     89   
    8890   var zoomworld=new OpenLayers.MouseListener.Reset("zoomworld","ResetExtentDisable.png", "button",optionsTools); 
    8991   
     
    9597   var drawpointstring=new OpenLayers.MouseListener.EditingListener.DrawPoint("drawpoint","EditPointEnable.png", "EditPointDisable.png","radioButton",optionsTools); 
    9698    
    97    toolbar.addTools([measuredistance,drawlinearring,drawlinestring,drawpointstring]);  
     99   toolbar.addTools([measuredistance,measurearea,drawlinearring,drawlinestring,drawpointstring]);  
    98100    
    99101   /*Modify Geometry Tool*/  
     
    126128    <div id="map"></div> 
    127129    <div id="ButtonBar" style="position:relative;"></div> 
     130   
     131    <div id="Area" style="position:relative;display:block;"></div> 
    128132  </body> 
    129133</html> 
  • sandbox/oterral/ButtonBar/vector/lib/OpenLayers/MouseListener/MeasureArea.js

    r2157 r2254  
    2727     * @constructor 
    2828    ***/ 
    29     initialize: function(options) { 
     29    initialize: function(id , imageOn , imageOff , type , options) { 
    3030        OpenLayers.MouseListener.EditingListener.prototype.initialize.apply(this, arguments); 
    31         this.turnOn(); 
    32  
     31        //this.turnOn(); 
     32        this.id=id; 
     33        this.imageOn=imageOn; 
     34        this.imageOff=imageOff; 
     35        this.type=type; 
     36         
    3337        options = options || []; 
    3438        OpenLayers.Util.extend(this, options); 
     
    3943     */ 
    4044    turnOn: function() { 
    41         OpenLayers.MouseListener.EditingListener.prototype.turnOn.apply(this, arguments); 
    42         this.geometry = new OpenLayers.Geometry.LinearRing(); 
     45        this.map.addMouseListener(this); 
     46          this.geometry = new OpenLayers.Geometry.LinearRing(); 
    4347        this.tmpLineSting = new OpenLayers.Geometry.LineString(); 
    4448    }, 
     
    4852     */ 
    4953    turnOff: function() { 
    50         OpenLayers.MouseListener.EditingListener.prototype.turnOff.apply(this, arguments); 
    51         this.eraseTmpElements(); 
     54        this.eraseTmpElements(); 
    5255        this.geometry = null; 
     56        this.map.removeMouseListener(this); 
     57       
    5358    }, 
    5459 
     
    6368 
    6469    eraseTmpElements: function() { 
    65         for(var i = 0; i < this.geometry.path.length; i++) { 
    66             this.map.vectorLayer.renderer.eraseGeometry(this.geometry.path[i]); 
    67         } 
    68         this.map.vectorLayer.renderer.eraseGeometry(this.geometry); 
     70   
     71            this.map.vectorLayer.renderer.eraseGeometry(this.tmpLineSting); 
     72     
     73         
     74        this.map.vectorLayer.renderer.eraseGeometry(this.oldGeometry); 
    6975    }, 
    7076 
     
    115121                this.map.vectorLayer.renderer.drawGeometry(this.tmpLineSting, this.style); 
    116122 
    117                 if (this.element != null) { 
    118                     this.draw(); 
    119                 } 
    120123            } 
    121124        } 
    122125    }, 
    123  
     126 mouseUp: function(evt) { 
     127        OpenLayers.MouseListener.EditingListener.prototype.mouseUp.apply(this, arguments); 
     128         this.draw(); 
     129    }, 
    124130    keyDown: function(evt) { 
    125131 
     
    146152    draw: function() { 
    147153        var digits = parseInt(this.numdigits); 
    148  
     154        if(!this.div) 
     155        {   this.div=document.createElement('div'); 
     156            this.div.id="MeasureArea";} 
     157        this.div.innerHTML=""; 
     158        //configure main div 
     159        this.div.style.position = "relative"; 
     160        this.div.style.top = "30px"; 
     161        this.div.style.right = "0px"; 
     162        this.div.style.left = ""; 
     163        this.div.style.fontFamily = "sans-serif"; 
     164        this.div.style.fontWeight = "bold"; 
     165        this.div.style.marginTop = "3px"; 
     166        this.div.style.marginLeft = "3px"; 
     167        this.div.style.marginBottom = "3px"; 
     168        this.div.style.fontSize = "smaller";    
     169        this.div.style.color = "white";    
     170        this.div.style.backgroundColor = "blue"; 
    149171        var newHtml = this.prefix + 
    150172                      this.geometry.getLength().toFixed(digits) + 
    151173                      this.suffix; 
     174     
     175        if (newHtml != this.div.innerHTML) { 
    152176 
    153         if (newHtml != this.element.innerHTML) { 
    154             this.element.innerHTML = newHtml; 
     177            this.div.innerHTML = newHtml; 
    155178        } 
     179        document.lastChild.lastChild.appendChild(this.div); 
    156180    }, 
    157181 
  • sandbox/oterral/ButtonBar/vector/lib/OpenLayers/MouseListener/MeasureDistance.js

    r2248 r2254  
    1313 
    1414    /** @type DOMElement */ 
    15     element: null, 
     15    div: null, 
    1616 
    1717    /** @type String */ 
     
    1919 
    2020    /** @type String */ 
    21     suffix: ' m'
     21    suffix: null
    2222 
    2323    /** @type int */ 
    2424    numdigits: 2, 
    2525 
     26    map:null, 
    2627    /** 
    2728     * @constructor 
     
    3435        this.imageOff=imageOff; 
    3536        this.type=type; 
     37         
    3638        options = options || []; 
    3739        OpenLayers.Util.extend(this, options); 
     
    4345    turnOn: function() { 
    4446       // OpenLayers.MouseListener.EditingListener.prototype.turnOn.apply(this, arguments); 
    45        this.map.events.register( "mousedown", this, this.mouseDown); 
    46         this.map.events.register( "mousemove", this, this.mouseMove); 
    47          this.map.events.register( "mouseup", this, this.mouseUp); 
     47       this.map.addMouseListener(this); 
     48       this.suffix=this.map.units; 
    4849        this.geometry = new OpenLayers.Geometry.LineString(); 
    49         this.tmpSegment = new OpenLayers.Geometry.LineSegment(); 
     50        this.tmpSegment = new OpenLayers.Geometry.LineString(); 
    5051    }, 
    5152 
     
    5455     */ 
    5556    turnOff: function() { 
    56     this.map.events.unregister( "mousedown", this, this.mouseDown); 
    57         this.map.events.unregister( "mousemove", this, this.mouseMove)
    58          this.map.events.unregister( "mouseup", this, this.mouseUp); 
     57    this.eraseTmpElements(); 
     58        this.geometry = null
     59     this.map.removeMouseListener(this); 
    5960        //OpenLayers.MouseListener.EditingListener.prototype.turnOff.apply(this, arguments); 
    60         this.eraseTmpElements(); 
    61         this.geometry = null; 
     61         
    6262    }, 
    6363 
     
    6666     */ 
    6767    finalizeGeometry: function() { 
     68     
    6869        this.oldGeometry = this.geometry; 
    6970        this.geometry = new OpenLayers.Geometry.LineString(); 
     
    7273 
    7374    eraseTmpElements: function() { 
    74         for(var i = 0; i < this.geometry.path.length; i++) { 
     75        /*for(var i = 0; i < this.oldGeometry.path.length; i++) { 
    7576            this.map.vectorLayer.renderer.eraseGeometry(this.geometry.path[i]); 
    76         } 
    77         this.map.vectorLayer.renderer.eraseGeometry(this.geometry); 
     77            
     78        }*/ 
     79         this.map.vectorLayer.renderer.eraseGeometry(this.tmpSegment); 
     80     
     81       // this.map.vectorLayer.renderer.eraseGeometry(this.oldGeometry); 
     82        this.map.vectorLayer.renderer.eraseGeometry(this.oldGeometry); 
     83         
    7884    }, 
    7985 
     
    8288 
    8389        this.mouseDown(evt); 
    84 //        this.eraseTmpElements(); 
     90       // this.eraseTmpElements(); 
    8591        if(this.geometry.path.length > 2){ 
    8692            this.finalizeGeometry(); 
     
    112118 
    113119        } else { 
    114             if (this.geometry.path.length > 0) { 
     120            if (this.geometry.path.length > 0) {//alert(this.tmpSegment.path[1]); 
     121               this.tmpSegment.path[1] = this.geometry.path[this.geometry.path.length-1]; 
    115122                this.tmpSegment.path[0] = evt.point; 
    116                 this.tmpSegment.path[1] = this.geometry.path[this.geometry.path.length-1]; 
     123                //this.tmpLineSting.path[2] = this.geometry.path[this.geometry.path.length-1]; 
    117124                this.map.vectorLayer.renderer.drawGeometry(this.tmpSegment, this.style); 
    118125 
    119                 if (this.element != null) { 
    120                     this.draw(); 
    121                 } 
     126 
     127              
    122128            } 
    123129        } 
    124130    }, 
    125  
     131 mouseUp: function(evt) { 
     132        OpenLayers.MouseListener.EditingListener.prototype.mouseUp.apply(this, arguments); 
     133         this.draw(); 
     134    }, 
    126135    keyDown: function(evt) { 
    127136 
     
    148157    draw: function() { 
    149158        var digits = parseInt(this.numdigits); 
    150  
     159        if(!this.div) 
     160        {   this.div=document.createElement('div'); 
     161            this.div.id="MeasureDistance"; 
     162        } 
     163        this.div.innerHTML=""; 
     164        //configure main div 
     165        this.div.style.position = "relative"; 
     166        this.div.style.top = "30px"; 
     167        this.div.style.right = "0px"; 
     168        this.div.style.left = ""; 
     169        this.div.style.fontFamily = "sans-serif"; 
     170        this.div.style.fontWeight = "bold"; 
     171        this.div.style.marginTop = "3px"; 
     172        this.div.style.marginLeft = "3px"; 
     173        this.div.style.marginBottom = "3px"; 
     174        this.div.style.fontSize = "smaller";    
     175        this.div.style.color = "white";    
     176        this.div.style.backgroundColor = "blue"; 
    151177        var newHtml = this.prefix + 
    152178                      this.geometry.getLength().toFixed(digits) + 
    153179                      this.suffix; 
     180     
     181        if (newHtml != this.div.innerHTML) { 
    154182 
    155         if (newHtml != this.element.innerHTML) { 
    156             this.element.innerHTML = newHtml; 
     183            this.div.innerHTML = newHtml; 
    157184        } 
     185        document.lastChild.lastChild.appendChild(this.div); 
    158186    }, 
    159187