天天看點

運作靈活網頁布局的示例程式

相信現在使用靈活網頁布局的童鞋們越來越多了,也許你注意到了在安裝CD光牒上提供了一下擴充fusion的示例代碼,并且在wikihelp文檔上提供了如何使用這些例子的方法。可惜這些示例和文檔稍微有點過時,需要更新一下,我快速的對前兩個例子試了一下,發現一些問題,下面是我的測試過程,也許對你有幫助。現在在忙于devday,後面幾個還沒時間研究,如果你感興趣,可以檢視相關源代碼。

The zip file, FlexibleWebLayoutsExamples.zip, contains source files. Unzip this into theinstallDir\WebServerExtensions\www folder with “Use folder names” selected in WinZip. It installs the following files:

<a></a>

fusion\templates\mapguide\examples\*

fusion\widgets\Example*.js

fusion\widgets\widgetinfo\example*.xml

fusion\widgets\example*\*

Run Example 1:

Example 1 demos how to create the simplest widget. After installing the code, you will find a new widget name “Example1” available in flexible web layout editor.

1. Create a new flexible web layout in Infrastructure Studio 2013 by c, select a template, I am using slate. Of cause, please make sure MapServer is running first.

2. Assign a map for the Map Tab, I am using the Sheboygan dataset.

運作靈活網頁布局的示例程式

3. I would like to add my test widget into “Toobar(Main Menu)”, you can also put it into other menu if you’d like to, so I switch to “Toobar(Main Menu)” tab, and click “New” in components available in this layout section:

運作靈活網頁布局的示例程式

4. You should see a mater type names as “Example1”, if not, try refresh. If it does not appear even after refreshing, then your probably made some mistakes at installation, a common problem is to install the JS/xml files into wrong folder, so please make sure you have same folder structure with the existing widgets. Select “Example1” as master type then click OK button.

運作靈活網頁布局的示例程式

5. Now I have a new component in the flexible web layout, you can change the ID as you will, I am using the default ID “Example1”:

運作靈活網頁布局的示例程式

6. Add this component into layout UI, dragging “Example1” into the window left side, a new button is created in main menu toolbar:

運作靈活網頁布局的示例程式

7. view in browser, and click “Example1” button in main menu toolbar, the “hello word” message shows up:

運作靈活網頁布局的示例程式

Running Example2

Example 1 is pretty simple, I will move next to Example2. Example 2 is a widget that is designed to be called as a command from a menu, it output the information of selected feature. It requires Mozilla® Firefox® 3.6 or higher and the Firebug extension because it writes to the Firebug console.

I am following the same process as example1 to add a new button into main menu toolbar, and browse it in Firefox this time. To run this example, I need to select some features first, then click  the “Example2 ” button.

Oops! I got an error message:

運作靈活網頁布局的示例程式

Fusion Error: 

WARNING: Exception occurred in AJAX callback. 

Message: theMap.getMapName is not a function 

Response: {"layers":["Parcels"],"extents":{"minx":-87.739602320342,"miny":43.765720296224,"maxx":-87.737804056497,"maxy":43.766709329904},"Parcels":{"propertynames":["RLDESCR1","RTYPE","RACRE","RLOT","RNAME","RLDESCR2","RLDESCR3","RBILAD","RSQFT","RLDESCR4"],"propertyvalues":["Description1","Zone","Acreage","Lot Dimensions","Owner","Description2","Description3","Billing Address","Lot Size (SqFt)","Description4"],"propertytypes":[9,9,9,9,9,9,9,9,7,9],"metadatanames":["dimension","bbox","center","area","length"],"numelements":15,"values":[["BRAND SUBD","RES","0.17","60X124","THIEME, ELAINE M","LOT 11 BLK 3","","2008 N. 25TH ST.","7440",""],["BRAND SUBD","RES","0.25","80X135","RAFFEL, JAMES E","LOT 3 &amp;amp; THE N 20\\' OF LOT 4","BLK 2","2006 N. 24TH ST.","10800",""],["BRAND SUBD","RES","0.25","80X135","FUERST, ROBERT O","N 30\\' OF LOT 23 &amp;amp; S 50\\' OF","LOT 24 BLK 2","2005 N. 25TH ST.","10800",""],["BRAND SUBD","RES","0.17","60X124","TUPPER, ANSEL JR","LOT 12 BLK 3","","2002 N. 25TH ST.","7440",""],["BRAND SUBD","RES","0.22","70X135","YANG, SHOUA PAO","THE S 40\\' OF LOT 4 &amp;amp; THE N","30\\' OF LOT 5 BLK 2","2002 N. 24TH ST.","9450",""],["BRAND SUBD","RES","0.23","75X135","RAKOW, GLEN J.","N 45\\' OF LOT 22 &amp;amp; S 30\\' OF","LOT 23 BLK 2","1919 N. 25TH ST.","10125",""],["BRAND SUBD","RES","0.17","60X124","MATELKO, RICHARD A.","LOT 13 BLK 3","","1918 N. 25TH ST.","7440",""],["BRAND SUBD","RES","0.28","90X135","CASTELLAN, MARY","THE S 30\\' OF LOT 5 &amp;amp; ALL OF","LOT 6 BLK 2","1914 N. 24TH ST.","12150",""],["BRAND SUBD","RES","0.23","75X135","ROERDINK, JAMES P.","LOT 21 &amp;amp; S 15\\' OF LOT 22 BLK","2","1913 N. 25TH ST.","10125",""],["BRAND SUBD","RES","0.22","75X125","PIONTKOWSKI, JOHN A.","S 45\\' OF LOT 15 &amp;amp; N 30\\' OF","LOT 16 BLK 3","1904 N. 25TH ST.","9375",""],["BRAND SUBD","RES","0.19","60X135","HAMER, MARGARET J","LOT 19 BLK 2","","1849 N. 25TH ST.","8100",""],["BRAND SUBD","RES","0.19","60X135","BOPHA, DAVID &amp;amp; MANYP","LOT 8 BLK 2","","1850 N. 24TH ST.","8100",""],["BRAND SUBD","RES","0.22","75X125","HORWITZ, DONALD","LOT 14 &amp;amp; THE N 15\\' OF LOT 15","BLK 3","1912 N. 25TH ST.","9375",""],["BRAND SUBD","RES","0.19","60X135","ABRAHAM, ROBERT A.","LOT 20 BLK 2","","1905 N. 25TH ST.","8100",""],["BRAND SUBD","RES","0.19","60X135","LAMB, DANIEL F","LOT 7 BLK 2","","1906 N. 24TH ST.","8100",""]],"metadata":[["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""],["","","","",""]]}}

You may get scared with such a long error message at first glance, To be frankly, I got a high blood pressure as well when I saw this first time 

運作靈活網頁布局的示例程式

. But let’s clam down and looked into the error again, I highlighted and marked it as bold. Message: theMap.getMapName is not a function , it seems that theMap object does not have a method “getMapName”. So I looked into the source code of map widget, which is C:\Program Files\Autodesk\Autodesk Infrastructure Web Server Extension 2013\www\fusion\lib\Map.js by default. Yes, that’s the reason, getMapName method is missing, so I went ahead to add this method as below, around line 1247:

//Added by Daniel 2012/11/01 

getMapName: function() { 

    return this.aMaps[0]._sMapname; 

},

It is pretty simple one. 

&lt;script type="text/javascript" src="../../../lib/fusion.js"&gt;&lt;/script&gt;

Now let’s refresh the page and test again, the information about the selection has been written to the firebug console:

運作靈活網頁布局的示例程式

Look at it closer:

運作靈活網頁布局的示例程式

Good luck!

郵箱:[email protected] 

轉載請保留此資訊。

本文轉自峻祁連. Moving to Cloud/Mobile部落格園部落格,原文連結:http://www.cnblogs.com/junqilian/archive/2012/11/21/2780108.html,如需轉載請自行聯系原作者

繼續閱讀