问题描述:
1.new mars3d.graphic.PolygonEntity({在更新点位高度模拟水面上身的时候,会存在闪烁
2.当把addDemoGraphic4添加到图层后,addDemoGraphic1水位变化不闪烁,把addDemoGraphic4注释后,addDemoGraphic1闪烁。
//可以直接在此附代码内容
import * as mars3d from "mars3d"
export let map // mars3d.Map三维地图对象
export let graphicLayer // 矢量图层对象
export let graphicLayer1 // 矢量图层对象
export const eventTarget = new mars3d.BaseClass()
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
scene: {
center: { lat: 31.622151, lng: 117.274595, alt: 28451, heading: 2, pitch: -49 }
}
}
/**
* 初始化地图业务,生命周期钩子函数(必须)
* 框架在地图初始化完成后自动调用该函数
* @param {mars3d.Map} mapInstance 地图对象
* @returns {void} 无
*/
export function onMounted(mapInstance) {
map = mapInstance // 记录map
// 创建矢量数据图层
graphicLayer = new mars3d.layer.GraphicLayer()
map.addLayer(graphicLayer)
graphicLayer1 = new mars3d.layer.GraphicLayer()
map.addLayer(graphicLayer1)
// 在layer上绑定监听事件
graphicLayer.on(mars3d.EventType.click, function (event) {
console.log("监听layer,单击了矢量对象", event)
})
// 加一些演示数据
addDemoGraphic1(graphicLayer)
addDemoGraphic4(graphicLayer)
}
/**
* 释放当前地图业务的生命周期函数
* @returns {void} 无
*/
export function onUnmounted() {
map = null
graphicLayer.remove()
graphicLayer = null
}
function addDemoGraphic1(graphicLayer) {
const graphic = new mars3d.graphic.PolygonEntity({
positions: [
[117.271662, 31.870639, 21.49],
[117.290605, 31.871517, 19.47],
[117.302056, 31.858145, 16.27],
[117.299439, 31.847545, 14.77],
[117.267705, 31.8491, 22.11]
],
style: {
color: "#3388ff",
opacity: 0.5
},
attr: { remark: "示例1" }
})
graphicLayer.addGraphic(graphic) // 还可以另外一种写法: graphic.addTo(graphicLayer)
let a = 10
setInterval(() => {
a = a + 10;
graphic.positions = [
[117.271662, 31.870639, a],
[117.290605, 31.871517, 19.47],
[117.302056, 31.858145, 16.27],
[117.299439, 31.847545, 14.77],
[117.267705, 31.8491, 22.11]
]
}, 200)
}
function addDemoGraphic4(graphicLayer) {
const graphic = new mars3d.graphic.PolygonEntity({
positions: [
[117.183593, 31.856606, 32.1],
[117.197665, 31.86613, 33.9],
[117.213155, 31.854726, 28.6],
[117.203837, 31.842409, 30.4],
[117.186741, 31.845103, 45.5]
],
style: {
color: "#00ff00",
diffHeight: 2000.0,
closeTop: false,
closeBottom: false,
opacity: 0.5,
}
})
graphicLayer.addGraphic(graphic) // 还可以另外一种写法: graphic.addTo(graphicLayer)
}
解决方案:
1.
entity如果不闪烁,需要将坐标改为属性机制的,可以用setCallbackPositions方法赋值。
let a = 10
setInterval(() => {
a = a + 10
graphic.setCallbackPositions([
[117.271662, 31.870639, a],
[117.290605, 31.871517, 19.47],
[117.302056, 31.858145, 16.27],
[117.299439, 31.847545, 14.77],
[117.267705, 31.8491, 22.11]
])
}, 200)
2.至于为什么当把addDemoGraphic4添加到图层后,addDemoGraphic1水位变化不闪烁,目前不太清楚。