Startup widgets possible?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Startup widgets possible?

Jackie Ng
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
Reply | Threaded
Open this post in threaded view
|

Re: Startup widgets possible?

Paul Deschamps
Have you played around with the map tips widget? I preforms a query when the mouse is still on a feature then creates a popup with a custom url that you can define based on the selected features data.

Cheers

Paul D

On Wed, Jul 22, 2009 at 9:04 PM, Jackie Ng <[hidden email]> 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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fusion-users



--
   Paul Deschamps
   Applications Specialist
   DM Solutions Group Inc.

   Office: (613) 565-5056 x28
   [hidden email]
   http://www.dmsolutions.ca
   http://research.dmsolutions.ca
   


_______________________________________________
fusion-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fusion-users
Reply | Threaded
Open this post in threaded view
|

Re: Startup widgets possible?

Paul Spencer-2
In reply to this post by Jackie Ng
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
> [hidden email]
> 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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fusion-users
Reply | Threaded
Open this post in threaded view
|

Re: Startup widgets possible?

Jackie Ng
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@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@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/fusion-users
Reply | Threaded
Open this post in threaded view
|

Re: Startup widgets possible?

David Wilhelmsson
For future reference (for people like me who found this post via Google), using #2, there is one line missing from the widget definition. Here's the entire definition:

MySelectionHandler.js:

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');
                 var url = this.url;
                 if (url.indexOf('?') < 0) {
                     url += '?';
                 } else if (url.slice(-1) != '&') {
                     url += '&';
                 }
                 url += params.join('&');
                 taskPaneTarget.setContent(url);
             }
         }
     },

     selectionOff: function() {
     }

});

Here's a widgetinfo that I created for this widget as well:

MySelectionHandler.xml:

<WidgetInfo>
        <Type>MySelectionHandler</Type>
        <LocalizedType></LocalizedType>
        <Description>A widget to call up a URL on selection</Description>
        <Location></Location>
        <Label></Label>
        <Tooltip></Tooltip>
        <StatusText></StatusText>
        <ImageUrl></ImageUrl>
        <ImageClass></ImageClass>
        <StandardUi>true</StandardUi>
        <ContainableBy>Any</ContainableBy>
        <Parameter>
                <Name>Target</Name>
                <Description>The frame, window, or TaskPane in which to display any UI for the widget. If empty, TaskPane is used</Description>
                <Type>String</Type>
                <Label>Target</Label>
                <DefaultValue>TaskPane</DefaultValue>
                <IsMandatory>true</IsMandatory>
        </Parameter>
        <Parameter>
                <Name>Url</Name>
                <Description>The URL to be opened in the target</Description>
                <Type>String</Type>
                <Label>Url</Label>
                <IsMandatory>true</IsMandatory>
        </Parameter>
</WidgetInfo>

Kind regards,
Dave.