linkScript.js
1.29 KB
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
window.projectName = '/frontweb'
window.mapBaseUrl = window.location.origin + window.projectName
var src = [
{
url: '/frontweb/js/arcgis_js_api/init.js',
type: 'script'
},
{
url: '/frontweb/js/arcgis_js_api/esri/css/main.css',
type: 'style'
},
]
// 插入地图绑定元素
var mapEle = document.getElementById('map')
if (mapEle) {
mapEle.setAttribute("style", "width: 100%;height: 100%;position: absolute;left: 0;right: 0;top: 0;bottom: 0;z-index: 1;");
} else {
var ele= document.createElement("div");
ele.setAttribute('id', 'map')
ele.setAttribute("style", "width: 100%;height: 100%;position: absolute;left: 0;right: 0;top: 0;bottom: 0;z-index: 1;");
document.body.appendChild(ele)
}
// 加载脚本
function addScriptsStyles (url, type) {
if (type === 'script') {
var ele= document.createElement("script");
ele.setAttribute("type", "text/javascript");
ele.setAttribute("src", url);
document.body.appendChild(ele)
}
if (type === 'style') {
var ele= document.createElement("link");
ele.setAttribute("rel", "stylesheet");
ele.setAttribute("href", url);
document.body.appendChild(ele)
}
}
src.forEach(item => {
addScriptsStyles(item.url, item.type)
})