123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- /**
- * [ONEMAP.M.projectController]
- * @return {[object]}
- */
- define(function (tplLayout) {
- /**
- * 初始化并订阅事件
- * @return {[type]} [description]
- */
- /**
- * 模块数据 用于数据存储和外部调用
- * @type {Object}
- * 数据存放
- */
- var modValue = {
- RASTER: {},
- model: {},
- seleted_guid: null,
- stereoscopic_handle: null,
- }
- /**
- * 状态值
- * @type {Boolean}
- * @default false
- * @private
- */
- var status = {
- initialized: false,
- isShowChild: false,
- connect: false,
- webSocketState: false
- };
- function init() {
- if (!localStorage.getItem("systemToken")) {
- ONEMAP.C.publisher.publish({
- type: 'warning',
- message: '用户尚未登录!'
- }, 'noteBar::add');
- return;
- }
- if (!status.initialized) {
- subscribe();
- bindEvent();
- // prototypeBind();
- status.initialized = true;
- // $("#threeData").parent().find(".menu-content").show();
- }
- ONEMAP.C.publisher.publish({
- modName: 'raster'
- }, 'menuListClick');
- }
- function prototypeBind() {
- //1.0GLTG插件
- var fixGltf = function (gltf) {
- if (!gltf.extensionsUsed) {
- return;
- }
- var v = gltf.extensionsUsed.indexOf('KHR_technique_webgl');
- var t = gltf.extensionsRequired.indexOf('KHR_technique_webgl');
- // 中招了。。
- if (v !== -1) {
- gltf.extensionsRequired.splice(t, 1, 'KHR_techniques_webgl');
- gltf.extensionsUsed.splice(v, 1, 'KHR_techniques_webgl');
- gltf.extensions = gltf.extensions || {};
- gltf.extensions['KHR_techniques_webgl'] = {};
- gltf.extensions['KHR_techniques_webgl'].programs = gltf.programs;
- gltf.extensions['KHR_techniques_webgl'].shaders = gltf.shaders;
- gltf.extensions['KHR_techniques_webgl'].techniques = gltf.techniques;
- var techniques = gltf.extensions['KHR_techniques_webgl'].techniques;
- gltf.materials.forEach(function (mat, index) {
- gltf.materials[index].extensions['KHR_technique_webgl'].values = gltf.materials[index].values;
- gltf.materials[index].extensions['KHR_techniques_webgl'] = gltf.materials[index].extensions['KHR_technique_webgl'];
- var vtxfMaterialExtension = gltf.materials[index].extensions['KHR_techniques_webgl'];
- for (var value in vtxfMaterialExtension.values) {
- var us = techniques[vtxfMaterialExtension.technique].uniforms;
- for (var key in us) {
- if (us[key] === value) {
- vtxfMaterialExtension.values[key] = vtxfMaterialExtension.values[value];
- delete vtxfMaterialExtension.values[value];
- break;
- }
- }
- };
- });
- techniques.forEach(function (t) {
- for (var attribute in t.attributes) {
- var name = t.attributes[attribute];
- t.attributes[attribute] = t.parameters[name];
- };
- for (var uniform in t.uniforms) {
- var name = t.uniforms[uniform];
- t.uniforms[uniform] = t.parameters[name];
- };
- });
- }
- }
- Object.defineProperties(Cesium.Model.prototype, {
- _cachedGltf: {
- set: function (value) {
- this._vtxf_cachedGltf = value;
- if (this._vtxf_cachedGltf && this._vtxf_cachedGltf._gltf) {
- fixGltf(this._vtxf_cachedGltf._gltf);
- }
- },
- get: function () {
- return this._vtxf_cachedGltf;
- }
- }
- });
- }
- function bindEvent() {
- $.ajax({
- type: "POST",
- headers: {
- token: localStorage.getItem("systemToken"),
- },
- data: {
- columnId: onemapUrlConfig.columnConfig.raster.id,
- states: "3",
- pageSize: 1000,
- page: 0,
- },
- dataType: "json",
- url: onemapUrlConfig.DMS_URL + '/dms/content/selectContentList',
- success: function (result) {
- if (result.code != 200) {
- ONEMAP.C.publisher.publish({
- type: 'warning',
- message: result.message,
- }, 'noteBar::add');
- return
- }
- let data = result.content.data;
- let thrData = data.map(function (item) {
- return {
- "category": "倾斜摄影",
- "info": "",
- "type": "raster",
- "name": item.title,
- "item": item
- }
- })
- let threeLength = thrData.length;
- var ul = $('<ul class="menu-content"></ul>');
- for (var i = 0; i < threeLength; i++) {
- var threeDlist = $('<li class="item" cid="' + i + '"><input type="checkbox" class="zt-cbx" layer=""><span class="meun-checkBox menu-select-no"></span><span class="no-bg">' + thrData[i].name + '</span></li>');
- ul.append(threeDlist);
- }
- var html = ul.html();
- $(".rasterContent .menu-content").html(html);
- $(".rasterContent li").unbind('click').bind('click', function () {
- var menuCheckBox = $(this).find('.meun-checkBox');
- var ztCbx = $(this).find('.zt-cbx');
- if (menuCheckBox.hasClass("menu-select-no")) {
- menuCheckBox.removeClass('menu-select-no').addClass("menu-select");
- if (!map23DData.display.map3D) {
- $("#mapModelChange .bg")[0].click()
- }
- var idx = $(this).attr('cid');
- var modelData = thrData[idx];
- var guid = null
- var options = {};
- guid = add3DRASTER(modelData);
- options = {
- action: "add",
- DOM: {
- guid: guid,
- type: "RASTER",
- name: $(this).find('.no-bg').text(),
- },
- mod: "RASTER"
- }
- if (!guid) return
- ztCbx.attr("layer", guid);
- ztCbx.attr("class", "zt-cbx " + guid);
- ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层”
- ONEMAP.C.publisher.subscribe(layerAction, guid);
- } else {
- menuCheckBox.removeClass('menu-select').addClass("menu-select-no");
- var guid = ztCbx.attr("layer");
- removeRASTER(guid)
- ONEMAP.M.myLayers.myLayerControl({
- action: "remove",
- DOMid: guid
- }); // 移除数据层
- }
- })
- },
- error: function (result) {
- }
- })
- }
- function layerAction(options) {
- if (options.guid.split("-")[0] == "RASTER") {
- if (options.action == "remove") {
- removeRASTER(options.guid)
- } else if (options.action == "opacity") {
- opacityRASTER(options)
- } else if (options.action == "controlShow") {
- controlShowRASTER(options)
- } else if (options.action == "up" || options.action == "down") {
- } else if (options.action == "location") {
- locationVECTOR(options)
- }
- }
- }
- /**
- * 加载/移除倾斜摄影
- * @return {[type]} [description]
- */
- function add3DRASTER(options) {
- var guid = map23DControl.buildGuid('RASTER-3DData');
- var items = options.item;
- let indexGuid = "";
- if (items.tile_server_type == "0") {
- // arcgis
- indexGuid += "0"
- } else if (items.tile_server_type == "1") {
- // xyz
- indexGuid += "1"
- }
- if (items.c_epsg == "EPSG:4326") {
- indexGuid += "0"
- }
- if (items.c_epsg == "EPSG:sh2000") {
- indexGuid += "1"
- }
- var layer = null;
- switch (indexGuid) {
- case "00":
- layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.ArcGisMapServerImageryProvider({
- url: items.c_url
- }));
- break;
- case "01":
- layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.CGCS2000ArcGisMapServerImageryProvider({
- url: items.c_url
- }));
- break;
- case "10":
- layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
- url: items.c_url
- }));
- break;
- case "11":
- break;
- default:
- break;
- }
- var bbox = JSON.parse(items.c_bbox)
- var extentR = turf.bbox(bbox);
- Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3])
- map3DViewer.map.camera.flyTo({
- destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
- });
- modValue.RASTER[guid] = layer
- modValue.RASTER[guid + "_extent"] = extentR
- return guid;
- };
- function removeRASTER(guid) {
- map3DViewer.map.imageryLayers.remove(modValue.RASTER[guid]);
- delete modValue.RASTER[guid];
- }
- function opacityRASTER(options) {
- modValue.RASTER[options.guid].alpha = options.options.opacity
- }
- function controlShowRASTER(options) {
- if (options.options.show)
- modValue.RASTER[options.guid].show = true
- if (!options.options.show)
- modValue.RASTER[options.guid].show = false
- }
- function locationVECTOR(options) {
- let extentR = modValue.RASTER[options.guid + "_extent"]
- map3DViewer.map.camera.flyTo({
- destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
- });
- }
- /**
- * 设置界面
- */
- function setLayout() {
- }
- /**
- * 界面重置
- * @return {[type]} [description]
- */
- function layoutResize(options) {
- if (options.modName != "raster") {
- remove();
- } else {
- if (status.isShowChild) {
- remove();
- } else {
- $("#menu .rasterContent").addClass('active');
- status.isShowChild = true;
- if (map23DData.show3DAlert) {
- ONEMAP.C.publisher.publish('3D', 'layout::mapStyle');
- }
- }
- }
- }
- /**
- * 模块移除
- * @return {[type]} [description]
- */
- function remove() {
- //取消订阅
- unSubscribe();
- $("#menu .rasterContent").removeClass('active');
- status.isShowChild = false;
- }
- /**
- * 注册订阅
- * @type {Function}
- * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
- * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(layoutResize, 'menuListClick');
- // ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
- }
- /**
- * 取消订阅
- * @type {Function}
- * 取消订阅:ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
- */
- function unSubscribe() {
- }
- return ONEMAP.M.threeData = {
- init: init
- }
- });
|