"use script"; //开发环境建议开启严格模式 //系统主入口 var map; //地球对象 var request; //传入的get参数 //地图 $(document).ready(function () { //判断webgl支持 if (!mars3d.Util.webglreport()) { mars3d.Util.webglerror(); } //记录url传入参数 request = haoutil.system.getRequest(); if (window.top) { //有父级 request = $.extend(request, haoutil.system.getRequest(window.top)); } // try { // var jwtstr = request.JWT; // var strs_ = jwtstr.split('.'); // var jwt_header_ = new buffer.Buffer(strs_[0].toString('base64'), 'base64').toString(); // var jwt_payload_ = new buffer.Buffer(strs_[1].toString('base64'), 'base64').toString(); // var payload_ = JSON.parse(jwt_payload_); // mars3d.global_variables.userid = payload_.userid; // mars3d.global_variables.regionCode = payload_.divcode; // var hash = CryptoJS.HmacSHA256(strs_[0] + '.' + strs_[1], "sxyd"); // var hashInBase64 = base64UrlEncode(hash); // var reg = RegExp(strs_[2]); // if (!reg.exec(hashInBase64)) { // // verification failed, go back // window.top.location = mars3d.global_variables.un_authorization_url; // } // payload_ = JSON.parse(jwt_payload_); // if (!payload_ || !payload_.expires) { // // verification error ,go back // window.top.location = mars3d.global_variables.un_authorization_url; // } // var date1 = new Date(payload_.expires); // var date2 = new Date(); // if (date1 < date2) { // // expire, go back // window.top.location = mars3d.global_variables.un_authorization_url; // } // } // catch (err) { // window.top.location = mars3d.global_variables.un_authorization_url; // } // mars3d.global_variables.userid = request?.userid || 2; regionCode = mars3d.global_variables.regionCode var configfile = "config/config.json"; //默认地址 if (request.config) { //url传入地址 configfile = request.config; } haoutil.loading.show(); $.ajax({ type: "get", dataType: "json", url: configfile, timeout: 0, success: function (data) { haoutil.loading.hide(); //构建地图 initMap(data.map3d); const graphicLayer = new mars3d.layer.GraphicLayer() map.addLayer(graphicLayer) // 边界墙 const graphic = new mars3d.graphic.WallEntity({ positions: [[116.32506199981151, 36.969410000271353], [116.371552999771211, 36.965256000264276], [116.389993000276831, 36.974895999650698], [116.421746999624361, 36.97536999992559], [116.460959000257731, 36.943157000095539], [116.436708999820553, 36.922848999781593], [116.446725000358583, 36.893459999779225], [116.427553000270791, 36.905383000125425], [116.414283999906729, 36.900267999868333], [116.412234999845396, 36.88226000039873], [116.421554999763543, 36.864800000119942], [116.408044999976823, 36.854479999952105], [116.381089999803748, 36.79456499967506], [116.39952700017102, 36.750304000029644], [116.379615000132162, 36.725230000264332], [116.401406999633423, 36.706164999715043], [116.40525399987223, 36.656081000437894], [116.397864999969784, 36.623765000354524], [116.406567000167001, 36.601206999703322], [116.395699999955127, 36.572822000135261], [116.392356000429118, 36.527723999662896], [116.45561000000157, 36.479863000377236], [116.449808999585684, 36.453621999855443], [116.498309999606818, 36.444133000237798], [116.50787900021578, 36.425283999756857], [116.538654000281895, 36.417364999695053], [116.54008999995358, 36.408480000052009], [116.497193000256857, 36.374670000320293], [116.477875999777666, 36.340020999669434], [116.44576600020082, 36.342043000284264], [116.432187999976236, 36.320806000296727], [116.400360999960185, 36.321620000062978], [116.321885999939013, 36.29248099989826], [116.275327999587603, 36.227578999871014], [116.218596000405114, 36.171516000063377], [116.160924000142586, 36.171546999694328], [116.157717999785973, 36.142929000173297], [116.120307000367802, 36.137627000285875], [116.093739000054825, 36.111831999647109], [116.051767999893286, 36.104807000342817], [116.018760000273801, 36.067964000138545], [115.987160999980233, 36.045983000015497], [115.944715000396968, 36.037286000048937], [115.913217000264467, 36.018705000235627], [115.885051000003727, 36.024235999891516], [115.853598000147599, 36.003296000110367], [115.830831999797056, 36.01139999971025], [115.803676000247265, 36.008563000182392], [115.786888000380941, 35.986165999761113], [115.772614999582629, 35.98467999958234], [115.778792000250633, 35.976853000165875], [115.762683000220363, 35.959398000117687], [115.726523000036536, 35.947157000395293], [115.695283000110408, 35.947619000116788], [115.686322999706704, 35.932816000058381], [115.648277999829929, 35.928253000075927], [115.637112000218735, 35.918954000226961], [115.588733999574515, 35.922584000351378], [115.535494000447784, 35.891786000123886], [115.497657000270351, 35.882304999975815], [115.500099999615372, 35.918258999653176], [115.489360999910332, 35.915635000055261], [115.478842999604808, 35.906009000415111], [115.488057000030608, 35.878242999714701], [115.446062999707692, 35.860643000174377], [115.401473000178839, 35.809145000441447], [115.35718600023381, 35.779125000118711], [115.329103000203304, 35.796710999912762], [115.338192000260619, 35.837238000033722], [115.334569999605833, 35.866964000288419], [115.358971999857999, 35.896583000105409], [115.360993000426674, 35.923179999957085], [115.347386999810283, 35.939099000218732], [115.356481000098142, 35.970669000074338], [115.381246000002989, 35.974351999944872], [115.387555999609731, 35.989604000024656], [115.404072000422502, 35.99999099968494], [115.440966000280696, 36.010934999850406], [115.443836999577911, 36.058880000311831], [115.474897000196506, 36.110451999859947], [115.479236999787759, 36.139567999863345], [115.464518000005796, 36.258984000211512], [115.42178199963962, 36.283643999770845], [115.413484000086555, 36.322801999712567], [115.397147000333916, 36.324958000211609], [115.372335000060275, 36.318805999797121], [115.364170000345325, 36.308194999699538], [115.350655000328061, 36.30925800015666], [115.351064000303381, 36.318822999681743], [115.366877000173531, 36.329416999894704], [115.339385000417451, 36.36094999984266], [115.336421999575691, 36.398358000021744], [115.288609999851701, 36.411892000015825], [115.304197000091563, 36.438826000119889], [115.30047900040563, 36.461439999756237], [115.287163999718928, 36.459621000408902], [115.277301999987344, 36.48700299958881], [115.290024000307426, 36.506696000320233], [115.289604999870903, 36.520872000242662], [115.320669999820666, 36.546788000166146], [115.329476000317186, 36.581253000425704], [115.342814000266003, 36.58420299976865], [115.344471000236581, 36.594608000259029], [115.334769999835657, 36.599541000217016], [115.371049000111384, 36.631689999793707], [115.38243900015982, 36.655536999632886], [115.401156999995578, 36.664176999668825], [115.410456999890698, 36.683641999778501], [115.43853999992109, 36.694106000291754], [115.472470999836787, 36.757107999934306], [115.499030999780871, 36.769067000142002], [115.520371000021669, 36.762762999912582], [115.522029000038401, 36.773428999848534], [115.570568000013282, 36.775036000211287], [115.653799999970033, 36.810491000259503], [115.67725799985692, 36.813601999832485], [115.683915000177194, 36.845964000238496], [115.704876000027411, 36.880879999712249], [115.752800999566489, 36.916133000337766], [115.842139999661299, 36.911773999870263], [115.852757000035581, 36.903517999556072], [115.880086000368692, 36.907842000208177], [115.910592999767232, 36.891311999649133], [115.938282999660714, 36.892141000107131], [115.948542999759638, 36.88462999997455], [116.020105000245621, 36.893176000172332], [116.085736999762844, 36.883348000210106], [116.105239999826154, 36.894040999592505], [116.120048000115162, 36.892129999599831], [116.16420999969182, 36.920700999651444], [116.167034999565658, 36.947137000172461], [116.178836999727764, 36.961801000116111], [116.202035000215119, 36.965413000309752], [116.221435000025281, 36.996834999635553], [116.219721000124082, 37.022608000159153], [116.291621000009172, 36.997322999656774], [116.32506199981151, 36.969410000271353]], style: { diffHeight: 1500, material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.LineFlow, { image: "../img/textures/fence.png", color: "#bdf700", repeat: new Cesium.Cartesian2(5, 1), axisY: true, // 方向,true时上下,false左右 speed: 15 }) } }) graphicLayer.addGraphic(graphic) // 聊城边界 const maskLayer = new mars3d.layer.GeoJsonLayer({ id: 300, url: "../data/liaocheng.geojson", mask: true, zIndex:100, symbol: { styleOptions: { fill: true, color: "#111111", opacity: 0.9, outline: false, outlineColor: "#39E09B", outlineWidth: 8, outlineOpacity: 0.8, arcType: Cesium.ArcType.GEODESIC, clampToGround: true, }, }, show: true, flyTo: false }); map.addLayer(maskLayer); setTimeout(removeMask, 3000); //欢迎UI关闭处理 }, error: function (request, textStatus) { removeMask(); haoutil.loading.hide(); haoutil.alert("1.请检查文件内 json 语法是否存在问题。
2.请在浏览器输入文件url测试是否可以访问。", configfile + " 文件加载失败"); console.log(textStatus, request); }, }); initUI(); // const graphicLayer = new mars3d.layer.GraphicLayer() // map.addLayer(graphicLayer) }); function removeMask() { $("#mask").remove(); } //UI界面相关 function initUI() { haoutil.oneMsg("首次访问系统无缓存会略慢,请耐心等待!", "load3d_tip"); } //初始化地图 function initMap(mapOptions) { //合并属性参数,可覆盖config.json中的对应配置 // mapOptions = mars3d.Util.merge(mapOptions, {}) //创建三维地球场景 map = new mars3d.Map("mars3dContainer", mapOptions); //构造widget initWidget(map); initLayersByUserid(); //如果有xyz传参,进行定位 if (haoutil.isutil.isNotNull(request.x) && haoutil.isutil.isNotNull(request.y)) { map.setCameraView(request, { duration: 0, isWgs84: true }); } //开场动画 //map.openFlyAnimation(); //针对不同终端的优化配置 if (haoutil.system.isPCBroswer()) { // Cesium 1.61以后会默认关闭反走样,对于桌面端而言还是开启得好, map.scene.postProcessStages.fxaa.enabled = true; //鼠标滚轮放大的步长参数 map.scene.screenSpaceCameraController._zoomFactor = 2.0; //IE浏览器优化 if (window.navigator.userAgent.toLowerCase().indexOf("msie") >= 0) { map.viewer.targetFrameRate = 20; //限制帧率 map.viewer.requestRenderMode = true; //取消实时渲染 } } else { //鼠标滚轮放大的步长参数 map.scene.screenSpaceCameraController._zoomFactor = 5.0; //移动设备上禁掉以下几个选项,可以相对更加流畅 map.viewer.requestRenderMode = true; //取消实时渲染 map.scene.fog.enabled = false; map.scene.skyAtmosphere.show = false; map.scene.globe.showGroundAtmosphere = false; } //二三维切换不用动画 if (map.sceneModePicker) { map.sceneModePicker.viewModel.duration = 0.0; } //webgl渲染失败后,刷新页面 // map.on(mars3d.EventType.renderError, function (scene, error) { // window.location.reload(); // }); //绑定单击显示BIM的构件树 bindShowTilesParts(); //下面可以继续加项目相关的其他代码 } //初始化widget相关 function initWidget(map) { haoutil.loading.show(); $.ajax({ type: "get", dataType: "json", url: "config/widget.json", timeout: 0, success: function (widgetCfg) { haoutil.loading.hide(); //url如果有传参时的处理 if (haoutil.isutil.isNotNull(request.widget)) { if (request.onlyStart) { widgetCfg.openAtStart = []; } widgetCfg.openAtStart.push({ uri: request.widget, name: request.name || "", windowOptions: { closeBtn: !request.onlyStart, }, request: request, }); map.flyHome({ duration: 0 }); } //初始化widget管理器 mars3d.widget.init(map, widgetCfg, "./"); //tip: 第3个参数支持定义widget目录的相对路径。 if (window.lastWidgetItem) { activateWidget(lastWidgetItem); lastWidgetItem = null; } }, error: function (XMLHttpRequest, textStatus, errorThrown) { haoutil.loading.hide(); haoutil.alert("config/widget.json文件加载失败!"); }, }); //widget相关事件监听 // mars3d.widget.on(mars3d.widget.EventType.load, function (event) { // console.log("引入加载了widget的js", event); // }) // mars3d.widget.on(mars3d.widget.EventType.beforeCreate, function (event) { // console.log("不创建widet", event); // }) mars3d.widget.on(mars3d.widget.EventType.activated, function (event) { console.log("激活了widget", event); }); mars3d.widget.on(mars3d.widget.EventType.disabled, function (event) { console.log("释放了widget", event); }); } //bim构件的处理 function bindShowTilesParts() { //单击地图事件 map.on(mars3d.EventType.clickGraphic, function (event) { if (!(event.pickedObject instanceof Cesium.Cesium3DTileFeature)) { //不是BIM数据时跳出 return; } let layer = event.layer; if (!layer.options.scenetree) { //未配置scenetree时跳出 return; } var tilesParts = "widgets/tilesParts/widget.js"; if (mars3d.widget.isActivate(tilesParts)) { var parts = mars3d.widget.getClass(tilesParts); if (parts.config.layerCfg == layer.options) { //当前已激活,并且单击了相同模型时跳出 return; } } mars3d.widget.activate({ name: layer.name + " 构件", uri: tilesParts, layerCfg: layer.options, disableOther: false, }); }); } //外部页面调用 var lastWidgetItem; function activateWidget(item) { if (!map) { lastWidgetItem = item; return; } mars3d.widget.activate(item); } function disableWidget(item) { mars3d.widget.disable(item); } function activateFunByMenu(fun) { eval(fun); } function goHome() { mars3d.widget.disableAll(); map.flyHome(); } function base64UrlEncode(str) { var encodedSource = CryptoJS.enc.Base64.stringify(str); var reg = new RegExp('/', 'g'); encodedSource = encodedSource.replace(/=+$/,'').replace(/\+/g,'-').replace(reg,'_'); return encodedSource; }