[fusion-users] Startup widgets possible?

Paul Spencer pspencer at dmsolutions.ca
Thu Jul 23 09:55:53 EDT 2009


Jackie,

you have two choices

1) in your template (which you don't want but which I am including for  
completeness and also because widgets will work with selections in  
much the same way)

Fusion.registerForEvent(Fusion.Event.FUSION_INITIALIZED, function() {
   var map = Fusion.getMapByIndice(0); // or getMapById()
   map.registerForEvent(Fusion.Event.MAP_SELECTION_ON, handleSelection);
   map.registerForEvent(Fusion.Event.MAP_SELECTION_OFF, clearSelection);
});

function handleSelection() {
   var map = Fusion.getMapByIndice(0);
   map.getSelection(selectionCallback);
}

function selectionCallback(sel) {
   // sel is a selection object with a collection of  
SelectionObject.Layer objects
   for (var i=0; i<sel.getNumLayers(); i++) {
     var selLayer = sel.getLayer(i);
     // selLayer has:
     // getName, getNumElements, getNumProperties, getPropertyNames,  
getPropertyTypes, getElementValue
   }
}

function clearSelection() {
   // the user cleared the selection
}


2) in a widget

/* a widget that loads a url in the task pane when a selection is made
  * <Widget>
  *   <Name>SomeId</Name>
  *   <Type>MySelectionHandler</Type>
  *   <Extension>
  *     <Target>TaskPane</Target>
  *     <Url>path/to/my/code</Url>
  *   </Extension>
  * </Widget>
  */
Fusion.Widget.MySelectionHandler = OpenLayers.Class(Fusion.Widget, {
     target: null,
     url: null,
     initializeWidget: function(widgetTag) {
         var json = widgetTag.extension;
         this.target = json.Target ? json.Target[0] : "TaskPane";
this.url = json.Url ? json.Url[0] : null;
         this.getMap().registerForEvent(Fusion.Event.MAP_SELECTION_ON,  
OpenLayers.Function.bind(this.selectionOn, this));
          
this.getMap().registerForEvent(Fusion.Event.MAP_SELECTION_OFF,  
OpenLayers.Function.bind(this.selectionOFf, this));
     },

     selectionOn: function() {
         if (this.url) {
             var taskPaneTarget = Fusion.getWidgetById(this.target);
             if (taskPaneTarget) {
                 var map = this.getMap();
                 var mapLayers = map.getAllMaps();
                 var params = [];
                 params.push('LOCALE='+Fusion.locale);
                 params.push('SESSION='+mapLayers[0].getSessionID());
                 params.push('MAPNAME='+mapLayers[0].getMapName());
                 params.push('POPUP=false');
                 if (url.indexOf('?') < 0) {
                     url += '?';
                 } else if (url.slice(-1) != '&') {
                     url += '&';
                 }
                 url += params.join('&');
                 taskPaneTarget.setContent(url);
             }
         }
     },

     selectionOff: function() {
     }

});

The only problem with this widget is that it is not included in the  
application by default, which is a limitation I hope to fix some time,  
so you need to include <div id="SomeId"></div> in your template.  Or,  
actually, you can add it to a toolbar or menu

<Item>
   <Function>Widget</Function>
   <Widget>SomeId</Widget>
</Item>

and it will be created with no UI

Hope this works (untested though) or at least gets you going in the  
right direction.

Cheers

Paul

On 22-Jul-09, at 9:04 PM, Jackie Ng wrote:

>
> Hi All,
>
> We have maps where we need to perform an action (load a url in the  
> task
> pane) in response to a map selection.
>
> In the AJAX viewer, it would be a simple case of hooking into the  
> viewer
> events and overriding the selection handler
> (http://trac.osgeo.org/mapguide/wiki/CodeSamples/JavaScript/AJAXViewerEventHooking 
> )
>
> But in Fusion, with its template and widget driven approach, this  
> seems to
> be a bad idea. So, short of hacking each template to support this
> functionality (worst case), it is possible to make a "startup"  
> widget that
> listens to the widget events I'm after and bind them to inline code  
> also
> defined in the widget. Sort of like a automatic InvokeScript?
>
> - Jackie
> -- 
> View this message in context: http://n2.nabble.com/Startup-widgets-possible--tp3306936p3306936.html
> Sent from the Fusion Users mailing list archive at Nabble.com.
> _______________________________________________
> fusion-users mailing list
> fusion-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fusion-users


__________________________________________

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



More information about the fusion-users mailing list