Skyline(6.x)-Web二次開發-1多視窗對比
阿新 • • 發佈:2019-01-04
一個頁面載入多個TerraExplorer3DWindow和SGWorld等只有第一個能用(即使用iframe也是一樣)
所以我決定開啟兩個新頁面實現多視窗對比,然後我在《主頁面》使用window.open打開了兩個《新頁面》,但這兩個新頁面使用SGWorld時居然在主頁面(使用window.open的頁面)產生了效果,感覺和以前的一個頁面載入多個TerraExplorer3DWindow 和 SGWorld效果一樣了!!!
然後經過測試發現關閉主頁面新頁面就正常載入三維地圖了。可以看出使用window.open時主頁面和新頁面是有關聯的,我一開始試了很多方法都斷不開這個關聯,最後決定開啟新頁面時多開啟一個主頁面,然後關掉主頁面這種笨方法。
當使用window.close當前關閉視窗,居然沒有關上,我一搜發現了關閉前有這一行程式碼window.opener=null
opener 屬性是一個可讀可寫的屬性,可返回對建立該視窗的 Window 物件的引用。
opener 屬性非常有用,建立的視窗可以引用建立它的視窗所定義的屬性和函式。
斷開主頁面和新頁面關聯的方法找到了!!!
總結:
使用window.open開啟兩個視窗,然後設定window.opener為null,這樣就可以在不同視窗中開啟三維場景了。
修正:
今天又測試一下設定window.opener為null不好使,還是使用將主頁面關閉這種方法吧=_=
//遍歷工程樹,將所有的layer圖層、圖層名都存放在陣列中 var players=new Array(); var playersName=new Array(); function BuildTreeRecursive(current) { try{ while (current > 0) { itemName = SGWorld.ProjectTree.GetItemName(current); if (itemName != "地形修改" && itemName != "位置" && itemName != "PresentationRoute") { if (SGWorld.ProjectTree.IsGroup(current)) { if (SGWorld.ProjectTree.IsLayer(current)) { var name = SGWorld.ProjectTree.GetItemName(current); var layer = SGWorld.ProjectTree.GetLayer(current); playersName[playersName.length] = name; players[players.length] = layer; } else { var childItem = SGWorld.ProjectTree.GetNextItem(current, 11);//CHILD – 11,The first child item of ItemID. BuildTreeRecursive(childItem); } } } current = SGWorld.ProjectTree.GetNextItem(current, 13); } } catch (e) { alert(e)} } //下面是根據工程樹中layer圖層的名字獲取layer function GetLayerByLayerGroupName(layerGroupName) { if (playersName.length>0) { for (i = 0; i < playersName.length; i++) { if (playersName[i] == layerGroupName) return players[i]; } } else { alert("圖層名陣列為空,請檢查TR.BuildTreeRecursive()方法是否執行"); } };