• 初遇Citymaker (四)


    这个系列最重要的来了 cw5这个类主要是构建地图加载

    针对citymaker初始化

    • <div class="map-container" style="float:left;1200px;height:800px;">
    • <object id="__g" type="application/x-cm-3d" ref="cwBox" style="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;

  • 相关阅读:
    [转]OOA/OOD/OOP区别
    Get / Post
    1.PHP环境搭配
    6.WCF Rest
    消除关闭按钮时的IE弹出提示
    TSQL DML学习笔记
    javascript 中类的定义
    $().each() 与 $.each()区别,以及 jquery ajax 应用
    TSQL 数据库的创建
    删除用户表 存储过程 索引..
  • 原文地址:https://www.cnblogs.com/haibalai/p/15829590.html
Copyright © 2020-2023  润新知