From 06eeb9b59644971d93e6dd9207ac447864e527b9 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期二, 03 六月 2025 17:38:08 +0800 Subject: [PATCH] 动态溯源(待完成) --- src/utils/map/3dLayer.js | 168 ++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 127 insertions(+), 41 deletions(-) diff --git a/src/utils/map/3dLayer.js b/src/utils/map/3dLayer.js index af6ff34..6a7c0c8 100644 --- a/src/utils/map/3dLayer.js +++ b/src/utils/map/3dLayer.js @@ -30,6 +30,17 @@ const fDatas = _factorDatas; const factor = _factor; drawMesh(fDatas, factor); + + if (_polFactorDatasList.length > 0) { + _polCylinderList.forEach((p) => { + object3Dlayer.remove(p); + }); + _polCylinderList = []; + _polFactorDatasList.forEach((e, i) => { + drawHighLight3DLayer(e, _polFactorList[i]); + }); + } + // console.log(map.getZoom()); } var _maxHeight = 1000, @@ -90,15 +101,13 @@ /** * 缁樺浘 */ -function drawMesh(fDatas, factor, center, merge) { +function drawMesh(fDatas, factor, merge) { const lnglats_GD = fDatas.lnglats_GD; const coors = fDatas.coors_GD; const heights = factor.heights; const colors = factor.colors; - const bColor = factor.bottomColor; - if (center) { - map.setZoomAndCenter(16, center); - } + // const bColor = factor.bottomColor; + const bColors = factor.bottomColors; // eslint-disable-next-line no-undef var cylinder = new AMap.Object3D.Mesh(); @@ -107,12 +116,20 @@ var geometry = cylinder.geometry; - const scale = _getScale(_minH, _maxH); + var minH = heights[0]; + var maxH = heights[0]; + for (let i = 0; i < heights.length; i++) { + const h = heights[i]; + minH = Math.min(minH, h); + maxH = Math.max(maxH, h); + } + + const scale = _getScale(minH, maxH); for (let i = 0; i < coors.length; i++) { var r = lnglats_GD[i]; var lastP = lnglats_GD[i - 1]; var p = coors[i]; - var h = (heights[i] - _minH) * scale + _minHeight; + var h = (heights[i] - minH) * scale + _minHeight; if (heights[i] == -1) { h = -1; } @@ -135,10 +152,8 @@ } } - // var bColor = bColor - var tColor = colors[i]; - geometry.vertexColors.push.apply(geometry.vertexColors, bColor); //搴曢儴椤剁偣棰滆壊 - geometry.vertexColors.push.apply(geometry.vertexColors, tColor); //椤堕儴椤剁偣棰滆壊 + geometry.vertexColors.push.apply(geometry.vertexColors, bColors[i]); //搴曢儴椤剁偣棰滆壊 + geometry.vertexColors.push.apply(geometry.vertexColors, colors[i]); //椤堕儴椤剁偣棰滆壊 } // 7.鏍规嵁鍚堝苟閫夐」閲嶇疆鎴栨柊澧炲綋鍓嶇紦瀛樻暟鎹� @@ -169,16 +184,100 @@ _cylinder = cylinder; } +/** + * 缁樺埗楂樹寒鐨勬薄鏌撳尯鍩�3D绔嬮潰 + */ +var _polCylinderList = []; +var _polFactorDatasList = [], + //褰撳墠閫変腑鐨勭洃娴嬪洜瀛愭暟鎹� + _polFactorList = []; +function drawHighLight3DLayer(fDatas, factor) { + const offsetH = 100; + + const lnglats_GD = fDatas.lnglats_GD; + const coors = fDatas.coors_GD; + const heights = factor.heights; + const colors = factor.colors; + const bColors = factor.bottomColors; + + // eslint-disable-next-line no-undef + var cylinder = new AMap.Object3D.Mesh(); + cylinder.backOrFront = 'both'; + cylinder.transparent = true; + + var geometry = cylinder.geometry; + + const scale = _getScale(_minH, _maxH); + for (let i = 0; i < coors.length; i++) { + var r = lnglats_GD[i]; + var lastP = lnglats_GD[i - 1]; + var p = coors[i]; + var h = (heights[i] - _minH) * scale + _minHeight; + if (heights[i] == -1) { + h = -1; + } + + geometry.vertices.push(p.x, p.y, 0 - h); //搴曢儴椤剁偣 + geometry.vertices.push(p.x, p.y, 0 - h - offsetH); //椤堕儴椤剁偣 + + if (i > 0) { + // eslint-disable-next-line no-undef + var distance = AMap.GeometryUtil.distance(r, lastP); + //涓や釜鏁版嵁鐐规渶灏忛棿闅旀椂闂翠负4s锛屽亣璁捐溅閫熸寜鐓�120km/h璁$畻锛�4s琛岄┒鏈�澶ц窛绂讳綔涓�132绫筹紝 + //璁惧畾瓒呰繃1鍒嗛挓鐨勬暟鎹粯鍒剁壒娈婄殑杩炵嚎 + if (distance <= 500 && h != -1) { + var bottomIndex = i * 2; + var topIndex = bottomIndex + 1; + var lastBottomIndex = bottomIndex - 2; + var lastTopIndex = bottomIndex - 1; + geometry.faces.push(bottomIndex, topIndex, lastTopIndex); + geometry.faces.push(bottomIndex, lastBottomIndex, lastTopIndex); + } + } + + const color = [1, 1, 1, 1]; + // const color = [1, 0, 0, 0.75]; + geometry.vertexColors.push.apply(geometry.vertexColors, color); //搴曢儴椤剁偣棰滆壊 + geometry.vertexColors.push.apply(geometry.vertexColors, color); //椤堕儴椤剁偣棰滆壊 + } + + // 7.鏍规嵁鍚堝苟閫夐」閲嶇疆鎴栨柊澧炲綋鍓嶇紦瀛樻暟鎹� + _polFactorDatasList.push(fDatas); + _polFactorList.push(factor); + // if (_polCylinderList.length > 0) { + // _polCylinderList.forEach((p) => { + // object3Dlayer.remove(p); + // }); + // } + object3Dlayer.add(cylinder); + + _polCylinderList.push(cylinder); +} + export default { + clear() { + map.off('zoomend', onMapZoom); + if (_cylinder != undefined) { + object3Dlayer.remove(_cylinder); + } + if (_polCylinderList.length > 0) { + _polCylinderList.forEach((p) => { + object3Dlayer.remove(p); + }); + _polCylinderList = []; + } + _polFactorDatasList = []; + _polFactorList = []; + }, + drawMesh: drawMesh, /** * 缁樺埗3D璧拌璺嚎鍥� * @param fDatas 瀹屾暣鐩戞祴鏁版嵁 * @param factor 褰撳墠灞曠ず鐨勭洃娴嬪洜瀛愬璞� * @param merge 鏄惁鍜屼箣鍓嶇粯鍒剁殑鍥惧舰鍚堝苟 - * @param setCenter 闀滃ご鏄惁鑷姩绉诲姩鑷冲浘褰腑蹇� */ - drawRoadMap(fDatas, factor, merge, setCenter) { + drawRoadMap(fDatas, factor, merge) { const lnglats_GD = fDatas.lnglats_GD; const heights = factor.heights; @@ -186,35 +285,20 @@ map.off('zoomend', onMapZoom); // 2.璁$畻缁樺浘楂樺害鐨勮竟鐣屽�� - if (merge != true) { - var minH = _minH < 0 ? heights[0] : _minH; - var maxH = _maxH < 0 ? heights[0] : _maxH; - for (let i = 0; i < heights.length; i++) { - const h = heights[i]; - minH = Math.min(minH, h); - maxH = Math.max(maxH, h); - } - _minH = minH; - _maxH = maxH; - } - - // 3.纭畾瀹氫綅鍧愭爣鐐� - var center; - if (setCenter && lnglats_GD.length > 0) { - var p = lnglats_GD[0]; - for (let i = 0; i < lnglats_GD.length; i++) { - const e = lnglats_GD[i]; - if (e[0] != 0) { - p = e; - break; - } - } - // eslint-disable-next-line no-undef - center = new AMap.LngLat(...p); - } + // if (merge != true) { + // var minH = _minH < 0 ? heights[0] : _minH; + // var maxH = _maxH < 0 ? heights[0] : _maxH; + // for (let i = 0; i < heights.length; i++) { + // const h = heights[i]; + // minH = Math.min(minH, h); + // maxH = Math.max(maxH, h); + // } + // _minH = minH; + // _maxH = maxH; + // } // 5.缁樺埗3D鍥惧舰 - this.drawMesh(fDatas, factor, center, merge); + this.drawMesh(fDatas, factor, merge); // 缂╂斁鍦板浘鍒板悎閫傜殑瑙嗛噹绾у埆 // map.setFitView() @@ -223,5 +307,7 @@ if (lnglats_GD.length > 0) { map.on('zoomend', onMapZoom); } - } + }, + + drawHighLight3DLayer }; -- Gitblit v1.9.3