在使用MapGuide Fusion viewer时,经常会用Fusion API,而Fusion API中最重要的对象就是Fusion对象,Map或者其他Widget都是通过Fusion这个全局对象来获得的。
下面是如何获取Fusion对象的javascript代码,存在这里备用,也供大家参考:
var mgApiMapWidgetId = 'Map';
var MainFusionWindow = GetFusionWindow();
var OpenLayers = MainFusionWindow.OpenLayers;
var Fusion = MainFusionWindow.Fusion;
alert(Fusion);
/* locate the Fusion window */
function GetFusionWindow() {
var curWindow = window;
while (!curWindow.Fusion) {
if (curWindow.parent && curWindow != curWindow.parent) {
curWindow = curWindow.parent;
} else if(curWindow.opener) {
curWindow = curWindow.opener;
} else {
alert('Could not find Fusion instance');
break;
}
}
return curWindow;
}
var MainFusionWindow = GetFusionWindow();
var OpenLayers = MainFusionWindow.OpenLayers;
var Fusion = MainFusionWindow.Fusion;
alert(Fusion);
/* locate the Fusion window */
function GetFusionWindow() {
var curWindow = window;
while (!curWindow.Fusion) {
if (curWindow.parent && curWindow != curWindow.parent) {
curWindow = curWindow.parent;
} else if(curWindow.opener) {
curWindow = curWindow.opener;
} else {
alert('Could not find Fusion instance');
break;
}
}
return curWindow;
}
获取Fusion对象后,就可以通过Fusion.getMapById()来获取地图对象,通过Fusion.getWidgetById()或者Fusion.getWidgetsByType()来获取Widget了。
Cheers,
峻祁连