zhitong.yu
2024-12-27 8abbee975353926e51a426a75c67119337fbdae4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"use script"
 
const parentGlobal = window.parent || window
 
parentGlobal.mars3d = mars3d // widget中使用
 
function init() {
    // 判断webgl支持
    if (!mars3d.Util.webglreport()) {
        mars3d.Util.webglerror()
    }
    // 读取 config.json 配置文件
    mars3d.Util.fetchJson({ url: "/config/config.json" })
        .then(function (json) {
            console.log("读取 config.json 配置文件完成", json) // 打印测试信息
 
            //创建三维地球场景
            const initMapFun = window.initMap ? window.initMap : globalInitMap
            var map = initMapFun(json.map3d)
 
            if (window.onMounted) {
                window.onMounted(map)
            }
 
            if (window.initUI) {
                window.initUI()
            }
 
            if (window.es5widget) {
                initWidget(map)
            }
        })
        .catch(function (error) {
            console.log("加载JSON出错", error)
            globalAlert(error ? error.message : "加载JSON出错")
        })
}
init()
 
// 构造地图主方法【必须】
function globalInitMap(options) {
    if (window.mapOptions) {
        if (typeof window.mapOptions === "function") {
            options = window.mapOptions(options) || options
        } else {
            window.mapOptions = options = mars3d.Util.merge(options, window.mapOptions)
        }
    }
 
    // 创建三维地球场景
    return new mars3d.Map("mars3dContainer", options)
}
 
//初始化widget相关
function initWidget(map) {
    //初始化widget管理器
    es5widget.init(
        map,
        {
            defaultOptions: {
                style: "dark",
                windowOptions: { skin: "layer-mars-dialog animation-scale-up", position: { bottom: 50, left: 10 } }
            },
            openAtStart: [
                {
                    name: "右上角工具栏",
                    uri: "widgets/toolButton/menuBtn.js"
                }
            ],
            widgets: [
                {
                    name: "图层管理",
                    uri: "widgets/manageLayers/widget.js",
                    group: "forlayer",
                    autoCenter: true,
                    windowOptions: {
                        position: { top: 10, bottom: 40, left: 50 }
                    },
                    autoDisable: false,
                    disableOther: false
                }
            ]
        },
        "/"
    )
}
 
// 调用项目的消息提示(自动消失)
function globalMsg(content) {
    if (window.layer) {
        window.layer.msg(content) // 此方法需要引用layer.js
    } else if (window.toastr) {
        window.toastr.info(content) // 此方法需要引用toastr
    } else {
        window.alert(content)
    }
}
 
// 调用项目的弹窗提示(手动单击确定关闭窗口)
function globalAlert(content, title) {
    if (window.layer) {
        // 此方法需要引用layer.js
        window.layer.alert(content, {
            title: title || "提示",
            skin: "layui-layer-lan layer-mars-dialog",
            closeBtn: 0,
            anim: 0
        })
    } else if (window.toastr) {
        window.toastr.info(content, title) // 此方法需要引用toastr
    } else {
        window.alert(content)
    }
}
 
// 调用项目的右上角信息提示(可关闭)
function globalNotify(title, content) {
    if (window.toastr) {
        window.toastr.warning(content, title) // 此方法需要引用toastr
    } else if (window.layer) {
        // 此方法需要引用layer.js
        window.layer.alert(content, {
            title: title || "提示",
            skin: "layui-layer-lan layer-mars-dialog",
            closeBtn: 0,
            anim: 0
        })
    } else {
        window.alert(content)
    }
}
 
function showLoading() {
    haoutil.loading.show()
}
 
function hideLoading() {
    haoutil.loading.close()
}