【mars3d】graphicLayer.addGraphic(添加数组注意事项

175 篇文章 2 订阅
158 篇文章 0 订阅

  graphicLayer.addGraphic(添加数组发现有问题,排查思路擦参考

代码:

const marsOnload = (map: any) => {
  const graphicLayer = new szmap3d.layer.GraphicLayer({
    hasEdit: true,
  });

  const getGraphic = (lng, lat) =>
    new szmap3d.graphic.Regular({
      position: Cesium.Cartesian3.fromDegrees(lng, lat),
      color: Cesium.Color.RED,
      fill: true,
      hasMoveEdit: false,
      style: {
        border: 4, // 多边形边数量
        radius: 500, // 半径
        outline: true,
        outlineWidth: 2,
        outlineColor: "rgba(0, 120, 255, 0.5)",
      },
    });
  const graphics = [
    getGraphic(113, 30),
    getGraphic(114, 30),
    getGraphic(113.5, 30),
    getGraphic(114, 25),
  ];
  map.addLayer(graphicLayer);

  graphicLayer.addGraphic(graphics);
  graphicLayer.flyTo();
};

发现怎么也加不上数据,仔细修改了代码后,发现graphicLayer没有加到map上,

更改了graphicLayer的位置,在New新的矢量之前,先把要添加的图层加到map上之后再操作

代码:

const marsOnload = (map: any) => {
  const graphicLayer = new szmap3d.layer.GraphicLayer({
    hasEdit: true,
  });
  map.addLayer(graphicLayer);

  const getGraphic = (lng, lat) =>
    new szmap3d.graphic.Regular({
      position: Cesium.Cartesian3.fromDegrees(lng, lat),
      fill: true,
      style: {
        border: 3, // 多边形边数量
        radius: 5000,
        startAngle: 0, // 开始角度(正东方向为0,顺时针到360度)
        color: Cesium.Color.RED,
        opacity: 0.5,
        outline: true,
        outlineWidth: 3,
        outlineColor: "#ffffff",
        label: {
          text: "我是火星科技",
          font_size: 18,
          color: "#ffffff",
          distanceDisplayCondition: true,
          distanceDisplayCondition_far: 500000,
          distanceDisplayCondition_near: 0,
        },
      },
    });

  const graphics = [
    getGraphic(113, 30),
    getGraphic(114, 30),
    getGraphic(113.5, 30),
    getGraphic(114, 25),
  ];
  graphicLayer.addGraphic(graphics);
  graphicLayer.flyTo();
};

效果:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值