[Users] Adding a menu item to an existing Tbar, not working

Andrew Stewart Andrew.Stewart at reddeer.ca
Tue Oct 5 16:47:36 CEST 2010


Thank you for the suggestion, so it is almost working now. Unfortunately for some reason my pan tool is broken. Not sure why because I basically copied/pasted the code from my zoom tool which works good. Every other tool works when you click the redline ones they work until you click a different tool (other than pan) and it switches to that tool. Except only when I click on pan it goes back to the previous redline tool.. Makes no sense why. Very much appreciate the assistance, below is my code but I still cannot figure out why the pan tool goes back to using the previous redline tool but all others work.


//---------------------------------Begin ToolBar


        var ctrl, toolbarItems = [], action, actions = {};
        
                //Home Action
                action = new GeoExt.Action({
                text: "  Home",
                handler: function() {window.location.reload();},
                map: map,
                cls: 'x-btn-text-icon',
                tooltip: 'Home',
                icon: '../images/toolbar/home.gif'
                });
                
                actions["home"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');
                
                
                //Queries Action
                action = new GeoExt.Action({
                text: "  Queries",
                handler: function() {document.getElementById('show-btn').click();},
                map: map,
                cls: 'x-btn-text-icon',
                tooltip: 'Queries',
                icon: '../images/toolbar/query.gif'
                });
                
                actions["queries"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');
                
                //Zoom In Action
                action = new GeoExt.Action({
                text: "  Zoom In",
                control: new OpenLayers.Control.ZoomBox({alwaysZoom:true}),
                map: map,
                toggleGroup: "tools",
                group: "tools",
                cls: 'x-btn-text-icon',
                tooltip: 'Zoom In',
                icon: '../images/toolbar/zoomin.gif'
                });
                
                actions["zoom_in"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');
                
                //Zoom Out Action
                action = new GeoExt.Action({
                text: "  Zoom Out",
                control: new OpenLayers.Control.ZoomBox({alwaysZoom:true, out:true}),
                map: map,
                toggleGroup: "tools",
                group: "tools",
                cls: 'x-btn-text-icon',
                tooltip: 'Zoom Out',
                icon: '../images/toolbar/zoomout.gif'
                });
                
                actions["zoom_out"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');

                //Zoom Previous Action
                action = new GeoExt.Action({
                text: "  Zoom Previous",
                control: nav.previous,
                map: map,
                cls: 'x-btn-text-icon',
                tooltip: 'Zoom Previous',
                icon: '../images/toolbar/zoomprevious.gif'
                });
                
                actions["zoom_previous"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');
                
                //Pan Map Action
                action = new GeoExt.Action({
                text: "  Pan",
                control: new OpenLayers.Control.MouseDefaults(),
                map: map,
                toggleGroup: "tools",
                group: "tools",
                cls: 'x-btn-text-icon',
                tooltip: 'Pan',
                icon: '../images/toolbar/pan.gif'
                });
                
                actions["pan_map"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');

 
                //Center Map Action
                action = new GeoExt.Action({
                text: "  Center Map",
                control: click,
                map: map,
                toggleGroup: "tools",
                group: "tools",
                cls: 'x-btn-text-icon',
                tooltip: 'Center Map',
                icon: '../images/toolbar/mapcenterclick.gif'
                });
                
                actions["center_map"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');
                
                //Fit Map Action            
                action = new GeoExt.Action({
                text: "  Fit Map",
                handler: function(){var bounds = new OpenLayers.Bounds(-12688352.278757,6834703.490456,-12648605.022533,6864246.4030152); map.zoomToExtent(bounds)},
                map: map,
                cls: 'x-btn-text-icon',
                tooltip: 'Fit Map',
                icon: '../images/toolbar/overview.gif'
                });
                
                actions["fit_map"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');
                
                
  // -------- Begin RedLine Menu Items------------------------// 
  
  
               //Redline Line
                action = new GeoExt.Action({
                text: "Line",
                control: drawLine,
                map: map,
                toggleGroup: "tools",
                group: "tools"
                });
                
                actions["redline"] = action;
                
               
                //Redline Polgygon
                action = new GeoExt.Action({
                text: "Polygon",
                control: drawPolygon,
                map: map,
                toggleGroup: "tools",
                group: "tools"
                });
                
                actions["polygon"] = action;
                
                
                //Redline Point
                action = new GeoExt.Action({
                text: "Point",
                control: drawPoint,
                enableToggle: true,
                toggleGroup: "tools",
                group: "tools",
                map: map
                });
                
                actions["point"] = action;
                
                //Delete All Redlines
                action = new GeoExt.Action({
                text: "Delete Redlines",
                handler: function() {Ext.Msg.show({title:'Delete Red Lines?', msg: 'You are about to delete Redlines from map, are you sure?',buttons: 		    Ext.Msg.YESNOCANCEL,fn: processResult,animEl: 'elId',icon: Ext.MessageBox.QUESTION}); function processResult(){map.removeLayer(vlayer);}},
                map: map
                });
                
                actions["delete"] = action;
                
                //Create menu for Redlines
                toolbarItems.push({
                    text: 'Redline Toolbox',
                    toggleGroup: "tools",
                    group: "tools",
                    menu: new Ext.menu.Menu({
                        items: [
                        //Redline
                        new Ext.menu.CheckItem(actions["redline"]),
                        //Polygon
                        new Ext.menu.CheckItem(actions["polygon"]),
                        //Point
                        new Ext.menu.CheckItem(actions["point"]),
                        //Delete Redlines
                        new Ext.menu.CheckItem(actions["delete"])
                        ]
                       })
                   });
                

 //------------------End RedLine Menu Items -------------------// 
 
 
                //Print Action
                action = new GeoExt.Action({
                text: "  Print Map",
                handler: function() {window.print(); },
                map: map,
                cls: 'x-btn-text-icon',
                tooltip: 'Print Map',
                icon: '../images/toolbar/print.gif'
                });
                
                actions["print"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');
                
                 
                //Help Action
                action = new GeoExt.Action({
                text: "  Help",
                handler: function() {window_Help.show();},
                map: map,
                cls: 'x-btn-text-icon',
                tooltip: 'Display Help',
                icon: '../images/toolbar/help.gif'
                });
                
                actions["help"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');

                //Tutorial Action
                action = new GeoExt.Action({
                text: "  Tutorial",
                handler: function() {window_Tutorial.show();},
                map: map,
                cls: 'x-btn-text-icon',
                tooltip: 'Display Tutorial',
                icon: '../images/toolbar/tutorial.gif'
                });
                
                actions["tutorial"] = action;
                toolbarItems.push(action);
                toolbarItems.push('-');

           //Define MapPanel for use with GeoExt
            
            var mapPanel = new GeoExt.MapPanel({
            collapsed: false,
            height: 800,
            renderTo: '',
            map: map,
            center: lonLat,
            zoom: startupLevel,
            tbar: toolbarItems



-----Original Message-----
From: Eric Lemoine [mailto:eric.lemoine at camptocamp.com] 
Sent: October 05, 2010 12:19 AM
To: Andrew Stewart
Cc: users at geoext.org
Subject: Re: [Users] Adding a menu item to an existing Tbar, not working

On Monday, October 4, 2010, Andrew Stewart <Andrew.Stewart at reddeer.ca> wrote:
>
>
>
>
>
>
>
>
>
> I am trying to add a button with a menu to my existing toolbar but unfortunately when I click on it the drawfeature control associated with the button won't fire and the pan tool stays active. If I just add the GeoExt.Action that adds redline directly
> to the tbar this works, but if I add the menu with it it doesn't. Not sure what I am missing here just trying to get a menu because I want to allow the drawfeature to use options for a line or polygon. Any help appreciated.

You may might a CheckItem for the Redline action. See the toolbar
example again, <http://trac.geoext.org/browser/core/trunk/geoext/examples/toolbar.js>.

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com


[This message has been scanned for security content threats and viruses.]

[The City of Red Deer I.T. Services asks that you please consider the environment before printing this e-mail.]






More information about the Users mailing list