mars3d点线面的绘制和重置

<template>
  <div id="app">
    地图
    <button @click="drawPoint()">点</button>
    <button @click="drawLine()">线</button>
    <button @click="drawPolygon()">面</button>
    <button @click="clearFeatures()">重置</button>

    <div id="mars3dContainer" class="mars3d-container"></div>
  </div>
</template>
 
<script>
import * as mars3d from "mars3d";
export default {
  name: "App",
  methods: {
    init() {
      var mapOptions = {
        basemaps: [{ name: "天地图", type: "tdt", layer: "img_d", show: true }],
      };
      // 创建三维地球场景
      const map = new mars3d.Map("mars3dContainer", mapOptions);
      this.map = map;
      return map;
    },
    drawPolygon(clampToGround) {
      this.map.graphicLayer.startDraw({
        type: "polygon",
        style: {
          color: clampToGround ? "#ffff00" : "#3388ff",
          opacity: 0.5,
          outline: true,
          outlineColor: "#ffffff",
          outlineWidth: 2.0,
          clampToGround: clampToGround,
        },
      });
    },
    drawPoint(clampToGround) {
      this.map.graphicLayer.startDraw({
        type: "point",
        style: {
          color: clampToGround ? "#ffff00" : "#3388ff",
          opacity: 0.5,
          outline: true,
          outlineColor: "#ffffff",
          outlineWidth: 2.0,
          clampToGround: clampToGround,
        },
      });
    },
    drawLine(clampToGround) {
      this.map.graphicLayer.startDraw({
        type: "polyline",
        style: {
          color: clampToGround ? "#ffff00" : "#3388ff",
          opacity: 0.5,
          outline: true,
          outlineColor: "#ffffff",
          outlineWidth: 2.0,
          clampToGround: clampToGround,
        },
      });
    },
    clearFeatures() {
      this.map.graphicLayer.clear();
    },
  },
  mounted() {
    this.init();
  },
};
</script>

<style>
#mars3dContainer {
  height: 800px;
}
</style>
<template>
  <div id="app">
    地图
    <button @click="layerEvents()">点</button>
    <button @click="save()">保存</button>
    <button @click="get()">读取</button>
    <div id="mars3dContainer" class="mars3d-container"></div>
  </div>
</template>
 
<script>
export default {
  name: "App",
  methods: {
    init() {
      var mapOptions = {
        basemaps: [{ name: "天地图", type: "tdt", layer: "img_d", show: true }],
      };

      var map = new mars3d.Map("mars3dContainer", mapOptions);

      this.map = map;
    },

    layerEvents() {
      console.log("asdf");
      // 图层绑定事件
      const graphicLayer = new mars3d.layer.GraphicLayer();
      this.map.addLayer(graphicLayer);
      const graphic = new mars3d.graphic.PointEntity({
        position: [116.244399, 30.920459, 573.6],
        style: {
          color: "#ff0000",
          pixelSize: 10,
          outlineColor: "#ffffff",
          outlineWidth: 2,
          label: {
            text: "我是原始点",
            font_size: 18,
            color: "#ffffff",
            pixelOffsetY: -10,
            distanceDisplayCondition: true,
            distanceDisplayCondition_far: 500000,
            distanceDisplayCondition_near: 0,
          },
        },
      });
      graphicLayer.addGraphic(graphic);
      // graphicLayer.on(mars3d.EventType.click, (e) => {
      //   console.log("我是图层的单击事件,获取的矢量数据", e.graphic)
      // })
    },
    save() {
      const graphic = new mars3d.graphic.PointEntity({
        position: [116.244399, 30.920459, 573.6],
        style: {
          color: "#ff0000",
          pixelSize: 10,
          outlineColor: "#ffffff",
          outlineWidth: 2,
          label: {
            text: "我是原始点",
            font_size: 18,
            color: "#ffffff",
            pixelOffsetY: -10,
            distanceDisplayCondition: true,
            distanceDisplayCondition_far: 500000,
            distanceDisplayCondition_near: 0,
          },
        },
      });
      localStorage.setItem("geojson", JSON.stringify(graphic));
    },
    get() {
      const geojson = JSON.parse(localStorage.getItem("geojson"));
      console.log("geojson", geojson);
      console.log("asdf");
      // 图层绑定事件
      const graphicLayer = new mars3d.layer.GraphicLayer();
      this.map.addLayer(graphicLayer);
      const graphic = new mars3d.graphic.PointEntity(geojson);
      graphicLayer.addGraphic(graphic);
    },
  },
  mounted() {
    this.init();
  },
};
</script>
 
<style>
#mars3dContainer {
  height: 1000px;
}
</style>

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Cesium.js的点线面绘制是一种通过Cesium.js库在Web浏览器中绘制各种地理要素的方法。这种绘制可以实现对点、线和面的可视化,使得用户能够以直观的方式理解和分析地理数据。 对于点的绘制,Cesium.js提供了一个基于经纬度坐标系的点对象。我们可以通过给定的经纬度坐标和其他属性来创建一个点,并将其渲染在地球上。这使得我们能够在地球表面上标识出感兴趣的点,比如城市、景点等。 对于线的绘制,Cesium.js提供了一个基于经纬度坐标系的线对象。我们可以通过给定的经纬度坐标数组来创建一条线,并将其渲染在地球上。这使得我们能够连接多个点,展示线性要素,如道路、河流、路径等。 对于面的绘制,Cesium.js提供了一个基于经纬度坐标系的面对象。我们可以通过给定的经纬度坐标数组来创建一个面,并将其渲染在地球上。这使得我们能够展示区域性要素,如国家、湖泊、山脉等。 在基于Cesium.js的点线面绘制中,我们可以根据实际需要对象进行样式和交互的定制。我们可以设置点的颜色、大小和样式,线的颜色、粗细和样式,以及面的颜色、透明度和纹理。此外,我们还可以添加响应用户交互的功能,比如点击、悬停等。 综上所述,基于Cesium.js的点线面绘制提供了一种直观、灵活和交互性强的方式,使我们能够以更好的方式展示和分析地理数据。它在地理信息系统、虚拟地球等领域具有广泛的应用前景。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值