openlayer 添加绘制 “点、线、面” ,并输出arcgis “FeatureServer”服务保存格式。

import "ol/ol.css";
import Map from "ol/Map";
import View from "ol/View";
import VectorSource from "ol/source/Vector";
import VectorLayer from "ol/layer/Vector";
import { GeoJSON } from "ol/format";
import { Draw, Modify, Select } from "ol/interaction";
      let  self = this;
     // 矢量图层源
      this.divisionVectorSource = new VectorSource({
        wrapX: false,
      });
      // 矢量图层
      this.divisionVectorLayer = new VectorLayer({
        source: this.divisionVectorSource,
      });
      this.map.addLayer(this.divisionVectorLayer);

      this.draw = new Draw({
        source: this.divisionVectorSource,
        type: "LineString",
      });
      // Point,Polygon
      this.map.addInteraction(this.draw);

      // 绘制完成
      this.draw.on("drawend", (e) => {
        self.map.removeInteraction(this.draw);
        self.draw = null;
       self.outputJson();
      });
outputJson() {
      let features;
      if (this.BDTemporaryLayer) {
        features = this.BDvectorSource.getFeatures();
      } else if (this.vectorLayer) {
        features = this.vectorSource.getFeatures();
      }
      let jsonObj = new GeoJSON();
      let writeFeatures = jsonObj.writeFeatures(features);

      if (features.length === 0) {
        this.$message.error("请绘制完成后提交!");
        return;
      }
      let coordinates, geometry, center, extents;
      switch (this.drawType) {
        case "Polygon":
          coordinates = features[0].getGeometry().getCoordinates();
          center = getCenter(features[0].getGeometry().getExtent()); //获取边界区域的中心位
          geometry = {
            rings: coordinates,
            spatialReference: { wkid: 4326, latestWkid: 4326 },
          };
          break;
        case "Point":
          coordinates =
            JSON.parse(writeFeatures).features[0].geometry.coordinates;
          geometry = {
            x: coordinates[0],
            y: coordinates[1],
            spatialReference: { wkid: 4326, latestWkid: 4326 },
          };
          center = coordinates;
          break;
        case "LineString":
          coordinates =
            JSON.parse(writeFeatures).features[0].geometry.coordinates;
          center = coordinates[0];
          geometry = {
            paths: [coordinates],
            spatialReference: { wkid: 4326, latestWkid: 4326 },
          };
          break;
      }

      this.hxttPolygonFeatures[0].geometry = geometry;

      this.hxttPolygonFeatures[0].attributes = {
        TASK_ID: "", //   任务id
      };
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

未来-更美好

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值