Layer status

4 messages Options
Embed this post
Permalink
jcabrera

Layer status

Reply Threaded More More options
Print post
Permalink
What is the best way to detect when a layer has been turned on or off?  Have been trying to attach an event to the layer itself, but none of what I tried has worked:

                layer.registerForEvent(Fusion.Event.LAYER_PROPERTY_CHANGED, dynamicLayerOn.bind(layer));
or
                layer.legend.checkBox.attachEvent("onclick", dynamicLayerOn.bind(layer))
or                
                Event.observe(layer.legend.checkBox, 'click', dynamicLayerOn.bind(layer) );

Any ideas?

Jorge
Paul Spencer-2

Re: Layer status

Reply Threaded More More options
Print post
Permalink
Um, there is no event that you can use for this right now.  Ideally,  
you could register for an event on the map object.  This would require  
a new event type and some code to trigger the event in Map.js,  
MapServer.js and MapGuide.js

Cheers

Paul

On 18-Jun-08, at 11:20 AM, Jorge Cabrera wrote:

>
> What is the best way to detect when a layer has been turned on or  
> off?  Have
> been trying to attach an event to the layer itself, but none of what  
> I tried
> has worked:
>
>                
> layer.registerForEvent(Fusion.Event.LAYER_PROPERTY_CHANGED,
> dynamicLayerOn.bind(layer));
> or
>                layer.legend.checkBox.attachEvent("onclick",
> dynamicLayerOn.bind(layer))
> or
>                Event.observe(layer.legend.checkBox, 'click',
> dynamicLayerOn.bind(layer) );
>
> Any ideas?
>
> Jorge
> --
> View this message in context: http://www.nabble.com/Layer-status-tp17985081p17985081.html
> Sent from the Fusion Users mailing list archive at Nabble.com.
>
> _______________________________________________
> fusion-users mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/fusion-users


__________________________________________

    Paul Spencer
    Chief Technology Officer
    DM Solutions Group Inc
    http://www.dmsolutions.ca/

_______________________________________________
fusion-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fusion-users
Paul Deschamps

Re: Layer status

Reply Threaded More More options
Print post
Permalink
In reply to this post by jcabrera
I  though I would give a little walk through on how to add events in Fusion Widgets for those of you who want to "extend" events in some of the widgets.

For this example lets use the legend widget.

First add the new event obj, before the "OpenLayers.Class(Fusion.Widget"

// CODE BLOCK [legend.js] ---------------------------------
Fusion.Event.LEGEND_LAYER_VIS_ON = Fusion.Event.lastEventId++;
Fusion.Event.LEGEND_LAYER_VIS_OFF = Fusion.Event.lastEventId++;

Fusion.Widget.Legend = OpenLayers.Class(Fusion.Widget,  {

//END CODE BLOCK ---------------

Next bind this event to the init section of the class around line 70:

// CODE BLOCK [legend.js] ---------------------------------
//console.log('Legend.initialize');
Fusion.Widget.prototype.initialize.apply(this, [widgetTag, true]);
       
var json = widgetTag.extension;

this.registerEventID(Fusion.Event.LEGEND_LAYER_VIS_ON);
this.registerEventID(Fusion.Event.LEGEND_LAYER_VIS_OFF);

//END CODE BLOCK ---------------

Now trigger the event in the legend class,  for this we want to trigger it when the layer checkbox is clicked: around line 499:

// CODE BLOCK [legend.js] ---------------------------------
    stateChanged: function(obj) {
        if (obj.legend && obj.legend.checkBox) {
            if (obj.legend.checkBox.checked) {
                this.triggerEvent(Fusion.Event.LEGEND_LAYER_VIS_ON, obj);
                obj.show();
            } else {
                this.triggerEvent(Fusion.Event.LEGEND_LAYER_VIS_OFF, obj);
                obj.hide();
            }
        }
    }
//END CODE BLOCK ---------------

Now in your supporting js for the Fusion application you should have a function called when fusion is initialized. inside this function you will need to registerForEvent on the legend widget to handle this trigger. :

// CODE BLOCK ---------------------------------
var legend = Fusion.getWidgetsByType('Legend');
      if (legend.length > 0) { // 0 is the first legend widget.
            legend[0].registerForEvent(Fusion.Event.LEGEND_LAYER_VIS_ON, layerON);
            legend[0].registerForEvent(Fusion.Event.LEGEND_LAYER_VIS_OFF, layerOFF);
      }
// END CODE BLOCK ---------------------------------

and finally add your layerON and layerOff functions:

// CODE BLOCK ---------------------------------
function layerON(obj,resp){
    console.dir(resp);
}

function layerOFF(obj,resp){
    console.dir(resp);
}
// END CODE BLOCK ---------------------------------

That's it you should see the object passed back from the widget to the application.

Hope this helps.

Cheers

Paul D.

_______________________________________________
fusion-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fusion-users
jcabrera

Re: Layer status

Reply Threaded More More options
Print post
Permalink
Excellent!  Thanks Paul, this is really helpful and will make things much easier.

Jorge