[fusion-users] Get layer name from Legend right-click
Mike Adair
madair at dmsolutions.ca
Fri Apr 16 15:29:44 EDT 2010
Tom,
It depends on where you are writing this code, but in Legend.js, there
is createTreeItem (which has a reference to a layer object) and then
calls getContextMenu() to retrieve a context menu object. YOu may need
to pass in the layer object to that method. Is this what you mean?
Mike
Tom van der Putte wrote:
>
> Hi Mike,
>
> Thanks for the explanation, so far I think I understand.
> What I meant was the following:
>
> I can't figure out where I can get the layer variable from (containing
> the layer or layername that was right-clicked). You're passing the
> layer variable, but how do you get it to contain the right layer.
> Thats the main issue here. To simplify my problem:
>
> I have a context menu for the legend, containing an item: 'alert layer
> name', which functionality would be to do just that. I'd add these to
> lines to the Legend.Legendrenderer.
>
> this.alertLayernameAction= new
> Jx.Action(OpenLayers.Function.bind(alert( lyrName),null)); // (or
> something like that?)
> this.alertLayer= new Jx.MenuItem(this.executeRasterQueryAction,
> {label:OpenLayers.i18n('alert layer name')});
>
> My issue her is where do I get lyrname from? Is the name of the node
> that was right-clicked available somewhere?
>
> Hope this is clearer, thanks so much!
>
> Tom
>
> On Thu 15/04/10 17:25 , Mike Adair madair at dmsolutions.ca sent:
>
> Tom,
>
> Then your getRasterQuery method would look like:
>
> function getRasterQuery(layer) {
> var temp = layer.name;
> ...
> }
>
> For the OpenLayers.Function.bind method, the first arg is the
> method to
> be bound, the second arg is the object to bind to (object will be
> 'this'
> inside the method), and then the rest of the arguments will be
> passed to
> the bound method as arguments.
>
> Mike
>
>
> Tom van der Putte wrote:
> > Hi Mike,
> >
> > I was trying your solution, but I'm still a bit confused.
> >
> > This is my current code (within Legend.LegendRenderer)
> >
> > this.executeRasterQueryAction = new
> > Jx.Action(OpenLayers.Function.bind(this.getRasterQuery, this));
> > this.executeRasterQueryItem = new
> > Jx.MenuItem(this.executeRasterQueryAction, {label:
> > OpenLayers.i18n('Execute raster query')});
> >
> > According to your explanation, the first line should then be:
> >
> > this.executeRasterQueryAction = new
> > Jx.Action(OpenLayers.Function.bind(this.getRasterQuery, this,
> layer));
> >
> > Or am I wrong here? But how do I get the reference to the layer
> thats
> > clicked? Does that make sense what I'm saying? :) I'm not really
> into
> > the whole binding stuuf yet. Getting there though...
> >
> > Cheers,
> > Tom
> >
> >
> >
> > On Thu 15/04/10 15:52 , Mike Adair madair at dmsolutions.ca
> <javascript:top.opencompose('madair at dmsolutions.ca','','','')> sent:
> >
> > Tom,
> >
> > The menu items are only bound to the legend tree items/folders at
> > this
> > point. I think what you would need to do is bind whatever object you
> > need when setting up your onclick event, eg. the existing code
> > looks like:
> > onClick:
> > OpenLayers.Function.bind(this.collapseBranch, this, this.oRoot)
> >
> > but you probably want:
> >
> > onClick:
> > OpenLayers.Function.bind(this.collapseBranch, this, this.oRoot,
> layer)
> >
> > (or similar) and then in the method being bound, layer will appear as
> > one of the arguments.
> >
> >
> > Mike
> >
> >
> > Tom van der Putte wrote:
> > > Hi All,
> > >
> > > When right-clicking an item in the legend, a context manu appears.
> > > I've added a entry to this menu, and clicking on it results in a
> > > certain function beeing executed. However, I want to check if the
> > item
> > > that was right-clicked in the legend is of a certain type. How
> can I
> > > get to the layer name? I found something like targetFolder in the
> > > legend widget, but this obviously goes only for the folders?
> > >
> > > Cheers,
> > >
> > > Tom
> > >
> ------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > fusion-users mailing list
> > > fusion-users at lists.osgeo.org
> <javascript:top.opencompose('fusion-users at lists.osgeo.org','','','')>
> >
> > > http://lists.osgeo.org/mailman/listinfo/fusion-users
> <parse.php?redirect=http%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Ffusion-users>
> >
> > >
> >
> > --
> > Michael Adair
> > Senior Software Architect
> > DM Solutions Group Inc.
> >
> > Office: (613) 565-5056 x26
> > madair at dmsolutions.ca
> <javascript:top.opencompose('madair at dmsolutions.ca','','','')>
> >
> > http://www.dmsolutions.ca
> <parse.php?redirect=http%3A%2F%2Fwww.dmsolutions.ca>
> > http://www.dmsolutions.ca
> <parse.php?redirect=%3Ca%20href=>">www.dmsolutions.ca>
> > http://research.dmsolutions.ca
> <parse.php?redirect=http%3A%2F%2Fresearch.dmsolutions.ca>
> >
> >
> >
> >
>
> --
> Michael Adair
> Senior Software Architect
> DM Solutions Group Inc.
>
> Office: (613) 565-5056 x26
> madair at dmsolutions.ca
> <javascript:top.opencompose('madair at dmsolutions.ca','','','')>
> http://www.dmsolutions.ca
> <parse.php?redirect=http%3A%2F%2Fwww.dmsolutions.ca>
> http://research.dmsolutions.ca
> <parse.php?redirect=http%3A%2F%2Fresearch.dmsolutions.ca>
>
>
>
--
Michael Adair
Senior Software Architect
DM Solutions Group Inc.
Office: (613) 565-5056 x26
madair at dmsolutions.ca
http://www.dmsolutions.ca
http://research.dmsolutions.ca
More information about the fusion-users
mailing list