tedp
Version:
terra dp init
206 lines (174 loc) • 6.06 kB
JavaScript
import Vue from 'vue';
import Main from './main.vue';
import {
TUMap,
TUBounds,
TUVector3,
TUVector2,
TURotator,
TUColor,
TUTransForm
} from "../../lib/tumap";
let TrameConstructor = Vue.extend(Main);
let instance;
let webGis = null;
let mult = 0;
const Trame = function (options) {
options = options || {};
Trame.def(options);
options.adapStyle = Trame.selfAdaption(options);
instance = new TrameConstructor({
data: options
});
typeof options.elem === 'object' ? instance.$mount(options.elem) : document.getElementById(options.elem) ? instance.$mount('#' + options.elem) : instance.$mount() && document.body.appendChild(instance.$el);
instance.load = true;
//是否使用内置三维引擎
if (options.isBuiltIn) {
let me = this;
Trame.setGis(options, function () {
me.trame = instance;
me.webGis = webGis;
me.mult = mult;
});
} else {
options.externalfn && typeof options.externalfn === 'function' ? options.externalfn({
id: 'te-gis'
}) : window.console.error('tedp:未使用内置引擎,应调用externalfn方法初始化三维');
this.trame = instance;
this.webGis = null;
this.mult = mult;
}
};
Trame.selfAdaption = function (options) {
let _w = window.screen.width,
_h = window.screen.height,
_stylyObj = {};
mult = _w / options.width;
_stylyObj.ungis = {
'transform': 'scale(' + _w / options.width + ',' + _h / options.height + ')',
'width': options.width + 'px',
'height': '0px',
'transformOrigin': '0 0'
}
_stylyObj.nav = {
'width': options.width + 'px',
'height': options.navtop + 'px'
}
_stylyObj.sub = {
'top': options.navtop + 20 + 'px'
}
_stylyObj.left = {
'width': options.prop[0] + 'px',
'height': options.height + 'px',
'padding-top': options.navtop + 'px',
}
_stylyObj.right = {
'width': options.prop[1] + 'px',
'height': options.height + 'px',
'padding-top': options.navtop + 'px',
}
// _stylyObj.ue = {
// 'width': options.width + 'px',
// 'height': options.height + 'px'
// }
options.multscreen = _w / options.width;
return _stylyObj
}
Trame.def = function (options) {
options.elem = options.elem || '';
options.width = options.width || 3840;
options.height = options.height || 1080;
options.navtop = options.navtop || 100;
options.prop = options.prop || [700, 700];
// options.gisType = options.gisType || 'hf';
options.showSub = options.showSub;
options.isBuiltIn = options.isBuiltIn === undefined ? true : options.isBuiltIn
// options.gisrefer = options.gisrefer || {
// cesium: Cesium,
// image: "http://183.162.245.49:1988/sdkdemo/src/static/image/earth.jpg",
// position: null
// };
options.module = options.module || {};
options.compss = options.compss || [];
options.nav = options.nav || {};
}
Trame.setGis = function (options, callback) {
let option = options.gisrefer || {};
switch (options.gisType) {
case 'hf&ue':
webGis = new SmartEarth.SGWorld('te-gis', option, () => {
typeof options.gisInit === 'function' ? options.gisInit(webGis) : ''
});
callback && typeof callback === 'function' ? callback() : ''
break
case 'hf':
// options.gisshow = false
webGis = new SmartEarth.SGWorld('te-gis', option, function () {
typeof options.gisInit === 'function' ? options.gisInit(webGis) : ''
})
callback && typeof callback === 'function' ? callback() : ''
break;
case 'bj':
// options.gisshow = false
GeoworldLib.createInstance('te-gis', {
sdkType: "release",
configLink: option.configLink,
gisserver: option.gisserver
}, function (e) {
webGis = e;
callback && typeof callback === 'function' ? callback() : ''
typeof options.gisInit === 'function' ? options.gisInit(webGis) : ''
})
break;
case 'ue':
webGis = TUMap.createMap({
id: "te-gis",
url: option.ueUrl,
timeOut: option.timeOut || 15000, //超时时间 加载场景超时设置 默认 15秒
resolution: option.timeOut || null, //默认分辨率 {width:1920,height:1080}
doubleRender: option.timeOut || false, //是否开启双倍渲染
location: option.timeOut || null, //默认镜头位置
rotation: option.timeOut || null, //默认镜头旋转角度
distance: option.timeOut || null, //默认镜头高度
//成功建立链接
onInit: () => {
webGis = Object.assign(webGis, {
TUMap,
TUBounds,
TUVector3,
TUVector2,
TURotator,
TUColor,
TUTransForm
})
typeof options.onInit === 'function' ? options.onInit() : '';
typeof options.gisInit === 'function' ? options.gisInit(webGis) : ''
},
//加载失败处理
onError: () => {
typeof option.onError === 'function' ? option.onError() : ''
},
//开始场景渲染处理
onBegin: () => {
typeof option.onBegin === 'function' ? option.onBegin() : ''
},
//远程流关闭处理
onClose: () => {
typeof option.onClose === 'function' ? option.onClose() : ''
},
//镜头变化处理
onCameraChange: () => {
typeof option.onCameraChange === 'function' ? option.onCameraChange() : ''
},
})
callback && typeof callback === 'function' ? callback() : ''
// webGis = new Ue("te-ue");
// options.ueurl = option.ueUrl;
// window.mainPage = function () {
// typeof options.gisInit === 'function' ? options.gisInit(webGis) : ''
// }
break;
}
}
Trame.fn = Trame.prototype;
export default Trame;