Infrastructure Map Server Developer

Reply
Active Member
francisco.rojas
Posts: 9
Registered: ‎08-29-2005
Message 1 of 2 (415 Views)

AIMS Fusion Dev Examples not working at all, and not updated since version 2012

415 Views, 1 Replies
09-06-2013 11:11 AM

Hi,

 

I realized that there is still the same problem with Fusion Dev’s Guide Example 2 in AIMS 2013 and 2014 as you can read from either

 

http://wikihelp.autodesk.com/Infr._Map_Server/enu/2013/Help/0005-Develope0/0105-Flexible105

 

Or

http://docs.autodesk.com/AIMS/2014/ENU/files/GUID-FF8342D1-CD98-4DD9-B9D5-8DB10FEF20FF.htm.

 

In the past some months ago I’d asked Daniel Du the reason why this is not working, and he sent me a workaround but I realize that there are some drawbacks as I explain below.

 

Example 2 fails since there is an error when we are trying to invoke getMapName method due to there isn't a getMapName method in Map.js used by the MapWidget, therefore Daniel’s approach was to add the method to Map.js

C:\Program Files\Autodesk\Autodesk Infrastructure Web Server Extension <2013|2014> \www\fusion\lib\Map.js:

 

   //Added by Daniel 2012/11/01

       getMapName: function() {

              return this.aMaps[0]._sMapname;

       },

 

Digging some other posts this code also works:

 

     getMapName: function () {

        for (var i = 0; i < this.aMaps.length; i++) {

            var aMap = this.aMaps[i];

            if (aMap.layerType == "MapGuide") {

                return aMap._sMapname;               

            }

        }

 

At this point I can't see the reason why the main map is in such layer named "MapGuide" or if the  main Map is always the first element (aMaps[0]) in the aMaps array from the MapWidget. Could you tell me which code is likely to work in all AIMS current versions?.

 

Secondly this implies editing the index.html file from the template where using in our Flexible Web Layout, changing the following line, for the second one:

 

<script type="text/javascript" src="../../../lib/fusionSF-compressed.js"></script>

 

Now it should be:

 

<script type="text/javascript" src="../../../lib/fusion.js"></script>

 

Otherwise our edited version of Map.js won't be loaded , I guess that fusionSF-compressed.js was generated with some tool like uglify.js that parses and compress a set of JS files into just one.

 

I realized that if we are trying to fix the Example 2, we could better implement the function within the JS as follows instead of modifying Map.js and changing the index.html file as follows:

 

 

var theMap = Fusion.getWidgetById("Map");
if (!theMap.hasSelection())
{
  alert("Nothing selected");
  return;
}
var oSelection = selection[this.getMapName()];

var thisLayer = oSelection.getLayerByName('Parcels');

for (var layerNum = 0; layerNum < oSelection.getNumLayers();
    layerNum++)
{
  var thisLayer = oSelection.getLayer(layerNum);
  var selectedFeaturesThisLayer = thisLayer.getNumElements();
  if (selectedFeaturesThisLayer > 0)
  {
    // Process the selected features
  }
}
....

getMapName: function()
    {
        var map = this.getMap();
        for(var i = 0; i<map.aMaps.length;i++){
            var aMap = map.aMaps[i];
            if(aMap.layerType=="MapGuide"){
                return aMap.getMapName();
            }
        }
        return '';
    },

 

I want to know if this approach is good enough in order to still use fusionSF-compressed.js and the fusion templates out-the-box.

 

Also I have see a lot of one-year-old posts with Fusion samples like this, that reffers to put this code line in JS:

 

http://adndevblog.typepad.com/infrastructure/2012/04/toggle-visibility-of-layer-in-fusion-does-not-w...

 

<scripttype="text/javascript"language="javascript"
    src="../mapserver2012/fusion/layers/MapGuide/MapGuideViewerApi.js">
    </script>

<scripttype="text/javascript">
        // set isFusion to false if you are using Ajax viewer
        var isFusion = true;


function RefreshMap() {
            if (isFusion) {                
                Fusion = window.top.Fusion;
                //...                


                //reload the Map to refresh legend
                Fusion.getWidgetById('Map').reloadMap();
            }
            else {              

                // if using basic weblayout, referenceing 
                // to MapGuideViewerApi.js should be removed
                parent.parent.Refresh();
            }
        }
</script>
</head>
<bodyonload="javascript&colon;RefreshMap()">
</body>
</html>

 

 

 

 

But in some scenarios involving Custom Widgets or Invoke URL Widget doesn't work, by digging in some other posts they remove this line of code:

 

Fusion = window.top.Fusion;

 

 

Why is that?, also I realized that I was also removed from MapGuide/MapGuideViewerApi.js functions as follows:

 

function Refresh() {
    //var Fusion = window.top.Fusion;
    var mapWidget = Fusion.getWidgetById(mgApiMapWidgetId);
    if (mapWidget && mapWidget.isMapLoaded()) {
        mapWidget.redraw();
    }
}

function SetSelectionXML(selectionXml) {
    //var Fusion = window.top.Fusion;
    var mapWidget = Fusion.getWidgetById(mgApiMapWidgetId);
    if (mapWidget && mapWidget.isMapLoaded()) {
        mapWidget.setSelection(selectionXml, true);
    }
}

 

 

Finaly regarding Example 3 it wasn't working in AIMS 2013, I don't know if someone have tried this on AIMS 2014.

 

Regards,

 

Francisco Rojas

 

 

Board Manager
Daniel.Du
Posts: 182
Registered: ‎12-23-2008
Message 2 of 2 (265 Views)

Re: AIMS Fusion Dev Examples not working at all, and not updated since version 2

02-16-2014 06:56 PM in reply to: francisco.rojas

Hi, 

 

First question: 

Fusion is based on OpenLayers, and the concept of 'layer' in OpenLayers and in MapGuide or AIMS are differenct, as OpenLayers can contains 'mapguide' layer , as well as other layer types, such as google map layers, wms layers ,etc. so 'mapguide' layer in OpenLayers actually is a 'map' in mapguide. 

 

So following code snippet is better.

 

 getMapName: function () {

        for (var i = 0; i < this.aMaps.length; i++) {

            var aMap = this.aMaps[i];

            if (aMap.layerType == "MapGuide") {

                return aMap._sMapname;               

            }

        }

 

 

Second one: 

As the name implies, fusionSF-compressed.js means compressed single file of fusion libarary. Javascript compressed the different javascript files into single file and compress them by removing comments/spaces etc to improve performace. But for debuging, we need to use the origenal version,  that's why we need to change like this: 

<script type="text/javascript" src="../../../lib/fusion.js"></script>

 

 

But of cause, you can do the compression process to generate the fusionSF-compressed.js after you did some modification. Many tools can be used to do this.

 

 

Thrid one: 

The code to get Fusion object depens how you use fusion viewer. As the sample demoed, fusion is used in one of built-in templates, it is something like 

window.top.Fusion;

But if you open the fusion viewer in nother window, it may be 

window.opener.Fusion;

Or if you embed fusion into an iframe tag, it will be a different way. anyway, it really depends how you use it, and it depend some javascript knowledget. 

 

Hope this clarifies. 

 



Daniel Du
Developer Technical Services
Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community