Changeset 387

Show
Ignore:
Timestamp:
04/14/09 23:39:20 (1 year ago)
Author:
dwins
Message:

Add scale overlay with scale chooser, scale bar, and a decorative label

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js

    r385 r387  
    7979 
    8080        var toolbarItems = this.initMapControlsAndToolbar(); 
     81 
     82        var mapOverlayPanel = this.initMapOverlay(); 
    8183         
    8284        // place map in panel 
     
    8991            center: mapConfig.center && new OpenLayers.LonLat(mapConfig.center[0], mapConfig.center[1]), 
    9092            // TODO: update the OpenLayers.Map constructor to accept an initial zoom 
    91             zoom: mapConfig.zoom 
     93            zoom: mapConfig.zoom, 
     94            layout: 'anchor', 
     95            items: [mapOverlayPanel] 
    9296        }); 
    9397 
     
    99103            region: 'center', 
    100104            title: "Layers", 
    101             anchor: "100%, -200", 
    102105            items: [{ 
    103106                xtype: "treepanel", 
     
    262265    showCapabilitiesGrid: function(){ 
    263266        this.capGrid.show(); 
     267    }, 
     268 
     269    initMapOverlay: function() { 
     270        var scaleLinePanel = new Ext.Panel({ 
     271            cls: 'olControlScaleLine', 
     272            border: false, 
     273            bodyStyle: 'position: relative' 
     274        }); 
     275 
     276        scaleLinePanel.on('render', function(){ 
     277            var scaleLine = new OpenLayers.Control.ScaleLine({ 
     278                div: scaleLinePanel.body.dom 
     279            }); 
     280 
     281            this.map.addControl(scaleLine); 
     282            scaleLine.activate(); 
     283        }, this); 
     284 
     285        var zoomStore = new GeoExt.data.ScaleStore({ 
     286            map: this.map 
     287        }); 
     288 
     289        var zoomSelector = new Ext.form.ComboBox({ 
     290            emptyText: 'Zoom level', 
     291            tpl: '<tpl for="."><div class="x-combo-list-item">1 : {[parseInt(values.scale)]}</div></tpl>', 
     292            editable: false, 
     293            triggerAction: 'all', 
     294            mode: 'local', 
     295            store: zoomStore, 
     296            width: 90 
     297        }); 
     298 
     299        zoomSelector.on('select', function(combo, record, index) { 
     300                this.map.zoomTo(record.data.level); 
     301            }, 
     302            this 
     303        ); 
     304 
     305        this.map.events.register('zoomend', this, function() { 
     306            var scale = zoomStore.queryBy(function(record){ 
     307                return this.map.getZoom() == record.data.level; 
     308            }); 
     309 
     310            if (scale.length > 0) { 
     311                scale = scale.items[0]; 
     312                zoomSelector.setValue("1 : " + parseInt(scale.data.scale)); 
     313            } else { 
     314                if (!zoomSelector.rendered) return; 
     315                zoomSelector.clearValue(); 
     316            } 
     317        }); 
     318 
     319        var mapOverlay = new Ext.Panel({ 
     320            // title: "Overlay", 
     321            cls: 'map-overlay', 
     322            style: { 
     323                'z-index': 1000,  
     324                position: 'absolute',  
     325                right: 10,  
     326                bottom: 10 
     327            }, 
     328            items: [ 
     329                {border: false, html: "hi there"}, 
     330                scaleLinePanel, 
     331                zoomSelector 
     332            ] 
     333        }); 
     334 
     335        mapOverlay.on("afterlayout", function(){ 
     336            scaleLinePanel.body.dom.style.position = 'relative'; 
     337            scaleLinePanel.body.dom.style.display = 'inline'; 
     338        }, this); 
     339 
     340        return mapOverlay; 
    264341    }, 
    265342 
  • apps/opengeo/geoexplorer/trunk/theme/geoexplorer.css

    r376 r387  
    4646    font-weight: bold; 
    4747} 
     48 
     49.map-overlay>div.x-panel-bwrap>div.x-panel-body>div { 
     50    display:inline; 
     51    float:left; 
     52    margin: 5px; 
     53}