Good day Cristiano,<br><br>All of the documentation that is currently available for fusion resides at <a href="http://trac.osgeo.org/fusion/wiki/Documentation" target="_blank">http://trac.osgeo.org/fusion/wiki/Documentation</a> unfortunately the docs there are kind of stale. <br>
<br>Read up on the API docs for these two. <br><a href="http://jxlib.org/" target="_blank">http://jxlib.org/</a> - The UI Toolkit fusion uses<br>
<a href="http://mootools.net/docs/core" target="_blank">http://mootools.net/docs/core</a> - the underlying technology that JX uses<br><br>and of course - Openlayers <a href="http://trac.openlayers.org/wiki/Documentation" target="_blank">http://trac.openlayers.org/wiki/Documentation</a><br>
<br>Someone should create some better documentation for fusion however until then. I've created a little widget that does a lot of the possible workflow in fusion; <br><br>in your ApplicationDefinition add this block:<br>
<br> <Widget><br> <Name>MyNewWidget</Name><br> <Type>MyNewWidget</Type><br> <Label>MyNewWidget</Label><br> <StatusItem/><br> <Extension><br>
<Foo>fooness</Foo><br> <Bar>barness</Bar><br> </Extension><br> </Widget><br><br>and in your html template add this<br><br><div id="MyNewWidget"></div><br>
<br>Here is the JS for the widget: copy this code to /fusion/widgets/MyNewWidget.js<br><br>/**<br> * Fusion.Widget.MyNewWidget<br> *<br> *<br> * Copyright (c) 20010, DM Solutions Group Inc.<br> * Permission is hereby granted, free of charge, to any person obtaining a<br>
* copy of this software and associated documentation files (the "Software"),<br> * to deal in the Software without restriction, including without limitation<br> * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
* and/or sell copies of the Software, and to permit persons to whom the<br> * Software is furnished to do so, subject to the following conditions:<br> *<br> * The above copyright notice and this permission notice shall be included<br>
* in all copies or substantial portions of the Software.<br> *<br> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br> * DEALINGS IN THE SOFTWARE.<br> */<br><br> /********************************************************************<br> * Class: Fusion.Widget.MyNewWidget<br>
*<br> * create a widget that does nothing useful except to illustrate some of the ways widgets work<br> *<br> * **********************************************************************/<br><br>/* <br>Lets create a custon event called 'MY_NEW_WIDGET_CUSTOM_EVENT"<br>
*/<br><br>Fusion.Event.MY_NEW_WIDGET_CUSTOM_EVENT = Fusion.Event.lastEventId++;<br><br>/* <br> Lets create the widget class<br>*/<br>Fusion.Widget.MyNewWidget = OpenLayers.Class(Fusion.Widget, {<br> isExclusive: true,<br>
uiClass: Jx.Button,<br> foo:'SOMETHING',<br> bar:'ELSE',<br> <br> initializeWidget: function(widgetTag){<br> alert('MyNewWidget:initializeWidget fired');<br>
console.dir(arguments);<br><br> //Set the appDef variables. <br> var json = widgetTag.extension;<br> this.foo = json.Foo ? json.Foo[0] : this.foo;<br> this.bar = json.Bar ? json.Bar[0] : this.bar;<br>
<br> console.log('MyNewWidget:initializeWidget:foo='+this.foo);<br> console.log('MyNewWidget:initializeWidget:bar='+this.bar);<br><br> // lets register the event in fusion<br> this.registerEventID(Fusion.Event.MY_NEW_WIDGET_CUSTOM_EVENT);<br>
<br> // Lets register this widget for the MY_NEW_WIDGET_CUSTOM_EVENT event. <br> this.registerForEvent(Fusion.Event.MY_NEW_WIDGET_CUSTOM_EVENT, OpenLayers.Function.bind(this.widgetCustomEvent, this));<br>
<br> // Lets register this widget for the MAP_ACTIVE_LAYER_CHANGED event. <br> this.getMap().registerForEvent(Fusion.Event.MAP_ACTIVE_LAYER_CHANGED, OpenLayers.Function.bind(this.doSomething, this));<br>
},<br> <br> activate : function() {<br> // this function is fired when the JX.button is pressed and initially when the widget is "activated"<br> alert('MyNewWidget:activate fired');<br>
alert('foo = '+this.foo);<br> /* <br> Lets do something with /fusion/layers/MapServer/php/SomePHPScript.php and send over the session and mapname so we can interact with<br> the map session. then fire doSomethingElse with the returned JSON. <br>
<br> To do this we need the arch, session and mapname. <br> */<br> var map = this.getMap().aMaps[0]; <br> var sl = Fusion.getScriptLanguage();<br> var queryScript = 'layers/' + map.arch + '/' + sl + '/SomePHPScript.' + sl;<br>
var params = {<br> 'mapname': map._sMapname,<br> 'session': map.getSessionID()<br> };<br> var ajaxOptions = {<br> // when the ajax is done return to "doSomethingElse"<br>
onSuccess: OpenLayers.Function.bind(this.doSomethingElse, this),<br> method: 'GET',<br> parameters: params<br> };<br> // fire the ajax request<br> Fusion.ajaxRequest(queryScript, ajaxOptions); <br>
},<br><br> deactivate : function() {<br> alert('MyNewWidget:deactivate fired');<br> },<br><br> execute: function (position, altZoom) {<br> alert('MyNewWidget:execute fired');<br>
},<br><br> doSomething: function(){<br> // this is fired when the MAP_ACTIVE_LAYER_CHANGED event is triggered. <br> alert('MyNewWidget:doSomething: fired');<br> },<br><br> doSomethingElse: function(r){<br>
// this is the callback to "activate" when the ajaxrequest returns. <br> alert('MyNewWidget:doSomethingElse: fired');<br> if (r.status == 200) {<br> var o;<br> eval('o='+r.responseText);<br>
alert('MyNewWidget:doSomethingElse:JSON: '+o.mapname);<br> }<br> // lets fire our custom event. <br> this.triggerEvent(Fusion.Event.MY_NEW_WIDGET_CUSTOM_EVENT);<br> },<br> widgetCustomEvent: function(event,r){<br>
/* <br> This is triggered from the custom event MY_NEW_WIDGET_CUSTOM_EVENT<br> once an event has been registerd in fusion you can call this event from any other widget. <br> */<br>
alert('MyNewWidget:widgetCustomEvent: fired');<br> }<br>});<br><br><br>
Here is the PHP for the widget: copy this code to /fusion/layers/MapServer/php/MyNewWidget.js<br><br><?php<br>/**<br> * SomePhpScript<br> *<br><br> * Portions copyright (c) 2006, DM Solutions Group Inc.<br> * Portions copyright (c) 2008, ENPLAN<br>
* Permission is hereby granted, free of charge, to any person obtaining a<br> * copy of this software and associated documentation files (the "Software"),<br> * to deal in the Software without restriction, including without limitation<br>
* the rights to use, copy, modify, merge, publish, distribute, sublicense,<br> * and/or sell copies of the Software, and to permit persons to whom the<br> * Software is furnished to do so, subject to the following conditions:<br>
*<br> * The above copyright notice and this permission notice shall be included<br> * in all copies or substantial portions of the Software.<br> *<br> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br> * DEALINGS IN THE SOFTWARE.<br> */<br><br>/* set up the session */<br>
include(dirname(__FILE__).'/../../../common/php/Utilities.php');<br>include(dirname(__FILE__).'/Common.php');<br>include(dirname(__FILE__).'/Utilities.php');<br><br>header('Content-type: application/json');<br>
header('X-JSON: true');<br><br>if (!isset($mapName)) {<br> die("{'error':'mapname not set'}");<br>}<br><br>if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {<br>
$oMap = ms_newMapObj($_SESSION['maps'][$mapName]);<br> <br> if ($oMap) {<br> for ($i=0;$i<$oMap->numlayers;$i++) {<br> // do something with the layers. <br> $layer = $oMap->getLayer($i);<br>
}<br> <br> // save the mapfile. <br> $oMap->save($_SESSION['maps'][$mapName]); <br><br> $oTmp = NULL;<br> $oTmp->mapname = $oMap->name;<br> echo json_encode($oTmp);<br>
}<br> else<br> {<br> echo "{'error':'Coud not open the mapfile.'}";<br> }<br>}<br>else<br>{<br>echo "{'error':'Session or mapname not set.'}";<br>
}<br>?><br><br><br>Hope this helps<br><br>Cheers<br><br>Paul D. <br><br>-- <br> Paul Deschamps<br> Applications Specialist<br> DM Solutions Group Inc.<br><br> Office: (613) 565-5056 x28<br> <a href="mailto:pdeschamps@dmsolutions.ca" target="_blank">pdeschamps@dmsolutions.ca</a><br>
<a href="http://www.dmsolutions.ca" target="_blank">http://www.dmsolutions.ca</a><br> <a href="http://research.dmsolutions.ca" target="_blank">http://research.dmsolutions.ca</a><br> <br><br>