OpenLayers OpenLayers

Changeset 555

Show
Ignore:
Timestamp:
06/07/06 23:38:02 (3 years ago)
Author:
crschmidt
Message:

Add support for distance measuring. Do more catching errors and the like. Move icons to be vertical, below panzoombar -- this is not yet configurable, but needs to be.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Control/MouseToolbar.js

    r552 r555  
    1717            this.direction = direction;  
    1818        } 
     19        this.measureDivs = []; 
    1920    }, 
    2021     
     
    2829        this.map.events.register( "mouseout", this, this.defaultMouseOut ); 
    2930        var sz = new OpenLayers.Size(28,28); 
    30         var centered = new OpenLayers.Pixel(100, 20); 
     31        var centered = new OpenLayers.Pixel(12, 300); 
    3132        this._addButton("zoombox", "drag-rectangle-off.png", "drag-rectangle-on.png", centered, sz); 
    32         this._addButton("pan", "panning-hand-off.png", "panning-hand-on.png", new OpenLayers.Pixel(100,47), sz); 
     33        this._addButton("pan", "panning-hand-off.png", "panning-hand-on.png", new OpenLayers.Pixel(12,328), sz); 
     34        this._addButton("measure", "measuring-stick-off.png", "measuring-stick-on.png", new OpenLayers.Pixel(12,356), sz); 
     35        this.switchModeTo("pan"); 
     36        this.map.events.register("zoomend", this, function() { this.switchModeTo("pan"); }); 
    3337        return this.div; 
     38         
    3439    }, 
    3540     
     
    7176    */ 
    7277    defaultDblClick: function (evt) { 
     78        this.switchModeTo("pan"); 
    7379        var newCenter = this.map.getLonLatFromScreenPx( evt.xy );  
    7480        this.map.setCenter(newCenter, this.map.zoom + 2); 
     
    104110                break; 
    105111            case "measure": 
     112                var distance = ""; 
     113                if (this.measureStart) { 
     114                    measureEnd = this.map.getLonLatFromScreenPx(this.mouseDragStart); 
     115                    distance = OpenLayers.Util.distVincenty(this.measureStart, measureEnd); 
     116                    distance = Math.round(distance * 100) / 100; 
     117                    distance = distance + "km"; 
     118                    this.measureStartBox = this.measureBox; 
     119                }     
     120                this.measureStart = this.map.getLonLatFromScreenPx(this.mouseDragStart);; 
     121                this.measureBox = OpenLayers.Util.createDiv(null, 
     122                                                         this.mouseDragStart.add( 
     123                                                           -2-parseInt(this.map.layerContainerDiv.style.left), 
     124                                                           -2-parseInt(this.map.layerContainerDiv.style.top)), 
     125                                                         null, 
     126                                                         null, 
     127                                                         "absolute"); 
     128                this.measureBox.style.width="4px"; 
     129                this.measureBox.style.height="4px"; 
     130                this.measureBox.style.backgroundColor="red"; 
     131                this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; 
     132                this.map.layerContainerDiv.appendChild(this.measureBox); 
     133                if (distance) { 
     134                    this.measureBoxDistance = OpenLayers.Util.createDiv(null, 
     135                                                         this.mouseDragStart.add( 
     136                                                           -2-parseInt(this.map.layerContainerDiv.style.left), 
     137                                                           2-parseInt(this.map.layerContainerDiv.style.top)), 
     138                                                         null, 
     139                                                         null, 
     140                                                         "absolute"); 
     141                     
     142                    this.measureBoxDistance.innerHTML = distance; 
     143                    this.measureBoxDistance.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; 
     144                    this.map.layerContainerDiv.appendChild(this.measureBoxDistance); 
     145                    this.measureDivs.append(this.measureBoxDistance); 
     146                } 
     147                this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; 
     148                this.map.layerContainerDiv.appendChild(this.measureBox); 
     149                this.measureDivs.append(this.measureBox); 
    106150                break; 
    107151            default: 
     
    114158    switchModeTo: function(mode) { 
    115159        if (mode != this.mode) { 
     160            if (this.mode) { 
     161                this.buttons[this.mode].firstChild.src = this.buttons[this.mode].imgLocation; 
     162            } 
     163            if (this.mode == "measure" && mode != "measure") { 
     164                for(var i = 0; i < this.measureDivs.length; i++) { 
     165                    if (this.measureDivs[i]) {  
     166                        this.map.layerContainerDiv.removeChild(this.measureDivs[i]); 
     167                    } 
     168                } 
     169                this.measureDivs = []; 
     170                this.measureStart = null; 
     171            } 
    116172            this.mode = mode; 
    117173            this.buttons[mode].firstChild.src = this.buttons[mode].activeImgLocation; 
    118         } else { 
    119             this.leaveMode(); 
    120         } 
     174        }  
    121175    },  
    122176 
    123177    leaveMode: function() { 
    124         var oldMode = this.mode; 
    125         this.mode = null; 
    126         if (oldMode) { 
    127             this.buttons[oldMode].firstChild.src = this.buttons[oldMode].imgLocation; 
    128         } 
     178        this.switchModeTo("pan"); 
    129179    }, 
    130180     
     
    180230                this.map.viewPortDiv.removeChild(document.getElementById("zoomBox")); 
    181231                this.zoomBox = null; 
    182                 break; 
    183         } 
    184         if (this.mouseDragStart) { 
    185             this.leaveMode(); 
     232                this.leaveMode(); 
     233                break; 
    186234        } 
    187235        this.mouseDragStart = null;