初遇Citymaker (四)
这个系列最重要的来了 cw5这个类主要是构建地图加载
针对citymaker初始化
-
<div class="map-container" style="float:left;width:1200px;height:800px;">
-
<object id="__g" type="application/x-cm-3d" ref="cwBox" style="width:100%;height:100%;"></object>
-
</div>
-
cw5.init();
-
cw5.loadMap();
cw5主类
```javascript
/**
- 本文件主要负责,地图加载,不负责具体的业务逻辑
*/
import {cwEventBus} from '../eventBus/eventBus.js';
import {skyBox} from "../skyBox/skyBox"
import {isSupport3d} from '../isSupport3d/isSupport3d.js'
export const cw5 = {};
cw5.__g = null;
cw5.isInit= false;
cw5.licenseLoad = false;
cw5.rootId = '11111111-1111-1111-1111-111111111111';
cw5.version=null;
cw5.fullButton=null;
cw5.callback={};
/**
-
初始化地图场景
-
@param id id是html中承载三维场景的object标签的id
-
@returns {string}
*/
cw5.init = function (id = "__g") {
this.__g = document.getElementById(id);
if( this.__g.type=="application/x-cm-3d"){
cw5.version=7;
}
else if( this.__g.type=="application/x-cm-3d8"){
cw5.version=8;
}
else{
cw5.version= map3dConfig.version;}
isSupport3d.init();
//初始化地图
let ps = this.__g.new_PropertySet;
// 检测浏览器是否支持三维或是否安装三维引擎ps.setProperty("RenderSystem", "OpenGL");
ps.setProperty("QuadBufferStereo", false);
//是否支持多点触控
if(map3dConfig.multiTouch){
ps.setProperty("MultiTouch", true);
}
let bInit = this.__g.initialize(true, ps);
if (!bInit) {
if (confirm("未检测到插件,是否下载?")) {
console.log("请安装CityMaker系列软件!");}
return
}
this.__g.camera.flyTime = 2;
skyBox.setSkybox();
cw5.confirmLicense();
cw5.fullScreenButton();
cw5.isInit=true;
};
/** -
验证三维证书是否可用
*/
cw5.confirmLicense = function () {
var license = __g.new_LicenseServer;
let _this = this;
if (!this.licenseLoad) {
let licUrl = map3dConfig.license.protocal + "://" + map3dConfig.license.host + ":" + map3dConfig.license.port;
try {
if (map3dConfig.license.path != "") {
console.log(map3dConfig.license.path)
license.setHost(map3dConfig.license.path, 0, "");
if(cw5.version==7){
if(!license.internalGetData().pVal2)
{
console.log("授权失败",license.internalGetData().pVal1)
}else{
console.log("授权成功",license.internalGetData().pVal1);
}
}
else if(cw5.version==8){
if(!license.hasRuntimeLicense)
{
console.log("授权失败")
}else{
console.log("授权成功");
}
}-
_this.licenseLoad = true;
}
} catch (e) {
console.error("设置授权异常:" + e.message);
}
}
}; -
/**
- 设置登录citymaker服务器的token信息
- @param infoData
*/
cw5.setToken = function (infoData) {
this.__g.addToken(infoData.Host, infoData.Token);
this.__g.cacheManager.fileCacheEnabled = true;
this.__g.camera.flyTime = 2;
};
/**
- 获取cm7的宏映射
- @param strEnum
- @param strValue
- @returns {null}
- @constructor
*/
cw5.GetEnumValue1 = function (strEnum, strValue) {
for (let k in strEnum)
if (k === strValue)
return strEnum[strValue] ? strEnum[strValue] : null;
};
/**
-
异常处理
-
@param e
-
@param mapInfo
*/
cw5.exceptionHandler = function(e,mapInfo) {
let msg = (typeof e == "object") ? e.message : e;
console.error("图层加载错误:"+mapInfo.handle);
console.error("出错信息:"+msg);//如果需要自定义异常描述信息
//如果是IE浏览器,可以直接用e中取出错误码:var code = e.number;
let code = parseInt(msg.substring(msg.indexOf("[") + 1, msg.length - 1));
if (code == -2147220504) {
console.error("此类型的数据源不支持此操作!");
}
};
/**
- 遍历地图配置项,并加载地图
*/
cw5.loadMap = function (map3dGroup) {
if(cw5.isInit!=true){
console.log("cw未初始化")
return
}
map3dGroup = map3dGroup || map3dLayers;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律