[fusion-dev] Information on development

Paul Deschamps pdeschamps at dmsolutions.ca
Tue Aug 24 10:50:29 EDT 2010


Good day Cristiano,

All of the documentation that is currently available for fusion resides at
http://trac.osgeo.org/fusion/wiki/Documentation unfortunately the docs there
are kind of stale.

Read up on the API docs for these two.
http://jxlib.org/ - The UI Toolkit fusion uses
http://mootools.net/docs/core - the underlying technology that JX uses

and of course - Openlayers http://trac.openlayers.org/wiki/Documentation

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;

in your ApplicationDefinition add this block:

   <Widget>
      <Name>MyNewWidget</Name>
      <Type>MyNewWidget</Type>
      <Label>MyNewWidget</Label>
      <StatusItem/>
      <Extension>
        <Foo>fooness</Foo>
        <Bar>barness</Bar>
      </Extension>
    </Widget>

and in your html template add this

<div id="MyNewWidget"></div>

Here is the JS for the widget: copy this code to
/fusion/widgets/MyNewWidget.js

/**
 * Fusion.Widget.MyNewWidget
 *
 *
 * Copyright (c) 20010, DM Solutions Group Inc.
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
"Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

 /********************************************************************
 * Class: Fusion.Widget.MyNewWidget
 *
 * create a widget that does nothing useful except to illustrate some of the
ways widgets work
 *
 * **********************************************************************/

/*
Lets create a custon event called 'MY_NEW_WIDGET_CUSTOM_EVENT"
*/

Fusion.Event.MY_NEW_WIDGET_CUSTOM_EVENT = Fusion.Event.lastEventId++;

/*
 Lets create the widget class
*/
Fusion.Widget.MyNewWidget = OpenLayers.Class(Fusion.Widget, {
    isExclusive: true,
    uiClass: Jx.Button,
    foo:'SOMETHING',
    bar:'ELSE',

     initializeWidget: function(widgetTag){
          alert('MyNewWidget:initializeWidget fired');
          console.dir(arguments);

          //Set the appDef variables.
          var json = widgetTag.extension;
          this.foo = json.Foo ? json.Foo[0] : this.foo;
          this.bar = json.Bar ? json.Bar[0] : this.bar;

          console.log('MyNewWidget:initializeWidget:foo='+this.foo);
          console.log('MyNewWidget:initializeWidget:bar='+this.bar);

          // lets register the event in fusion
          this.registerEventID(Fusion.Event.MY_NEW_WIDGET_CUSTOM_EVENT);

          // Lets register this widget for the MY_NEW_WIDGET_CUSTOM_EVENT
event.
          this.registerForEvent(Fusion.Event.MY_NEW_WIDGET_CUSTOM_EVENT,
OpenLayers.Function.bind(this.widgetCustomEvent, this));

          // Lets register this widget for the MAP_ACTIVE_LAYER_CHANGED
event.

this.getMap().registerForEvent(Fusion.Event.MAP_ACTIVE_LAYER_CHANGED,
OpenLayers.Function.bind(this.doSomething, this));
     },

    activate : function() {
         // this function is fired when the JX.button is pressed and
initially when the widget is "activated"
          alert('MyNewWidget:activate fired');
          alert('foo = '+this.foo);
          /*
          Lets do something with
/fusion/layers/MapServer/php/SomePHPScript.php and send over the session and
mapname so we can interact with
          the map session. then fire doSomethingElse with the returned JSON.


          To do this we need the arch, session and mapname.
          */
          var map = this.getMap().aMaps[0];
          var sl = Fusion.getScriptLanguage();
          var queryScript = 'layers/' + map.arch + '/' + sl  +
'/SomePHPScript.' + sl;
          var params = {
            'mapname': map._sMapname,
            'session': map.getSessionID()
          };
          var ajaxOptions = {
               // when the ajax is done return to "doSomethingElse"
               onSuccess: OpenLayers.Function.bind(this.doSomethingElse,
this),
               method: 'GET',
               parameters: params
          };
          // fire the ajax request
          Fusion.ajaxRequest(queryScript, ajaxOptions);
    },

    deactivate : function() {
         alert('MyNewWidget:deactivate fired');
    },

    execute: function (position, altZoom) {
         alert('MyNewWidget:execute fired');
    },

    doSomething: function(){
         // this is fired when the MAP_ACTIVE_LAYER_CHANGED event is
triggered.
         alert('MyNewWidget:doSomething: fired');
    },

    doSomethingElse: function(r){
         // this is the callback to "activate" when the ajaxrequest returns.

         alert('MyNewWidget:doSomethingElse: fired');
         if (r.status == 200) {
            var o;
            eval('o='+r.responseText);
            alert('MyNewWidget:doSomethingElse:JSON: '+o.mapname);
         }
         // lets fire our custom event.
         this.triggerEvent(Fusion.Event.MY_NEW_WIDGET_CUSTOM_EVENT);
    },
     widgetCustomEvent: function(event,r){
          /*
               This is triggered from the custom event
MY_NEW_WIDGET_CUSTOM_EVENT
               once an event has been registerd in fusion you can call this
event from any other widget.
          */
         alert('MyNewWidget:widgetCustomEvent: fired');
     }
});


Here is the PHP for the widget: copy this code to
/fusion/layers/MapServer/php/MyNewWidget.js

<?php
/**
 * SomePhpScript
 *

 * Portions copyright (c) 2006, DM Solutions Group Inc.
 * Portions copyright (c) 2008, ENPLAN
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
"Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

/* set up the session */
include(dirname(__FILE__).'/../../../common/php/Utilities.php');
include(dirname(__FILE__).'/Common.php');
include(dirname(__FILE__).'/Utilities.php');

header('Content-type: application/json');
header('X-JSON: true');

if (!isset($mapName)) {
    die("{'error':'mapname not set'}");
}

if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);

     if ($oMap) {
          for ($i=0;$i<$oMap->numlayers;$i++) {
             // do something with the layers.
             $layer = $oMap->getLayer($i);
          }

     // save the mapfile.
     $oMap->save($_SESSION['maps'][$mapName]);

     $oTmp = NULL;
     $oTmp->mapname = $oMap->name;
     echo json_encode($oTmp);
     }
     else
     {
          echo "{'error':'Coud not open the mapfile.'}";
     }
}
else
{
echo "{'error':'Session or mapname not set.'}";
}
?>


Hope this helps

Cheers

Paul D.

-- 
    Paul Deschamps
    Applications Specialist
    DM Solutions Group Inc.

    Office: (613) 565-5056 x28
    pdeschamps at dmsolutions.ca
    http://www.dmsolutions.ca
    http://research.dmsolutions.ca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/fusion-dev/attachments/20100824/3984f033/attachment-0001.html


More information about the fusion-dev mailing list