Entity更新坐标不闪烁需采用setCallbackPositions方法赋值

183 篇文章 2 订阅
165 篇文章 0 订阅

问题描述:

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水位变化不闪烁,目前不太清楚。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值