[fusion-users] Startup widgets possible?

Jackie Ng jumpinjackie at gmail.com
Fri Jul 24 01:15:55 EDT 2009


Hi Paul,

Yeah I was aware of technique #1, but wanted a more "portable" approach like
#2. Thanks for the pointers, it will give me something to work with.

- Jackie


Paul Spencer-2 wrote:
> 
> 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/
> 
> _______________________________________________
> fusion-users mailing list
> fusion-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fusion-users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Startup-widgets-possible--tp3306936p3313889.html
Sent from the Fusion Users mailing list archive at Nabble.com.


More information about the fusion-users mailing list