在vue2中,使用openlayers在图层上构建一个圆圈

第一步:下载对应的openlayers.

import { Circle as CircleFeature } from "ol/geom";
import Feature from "ol/Feature";

var FenceSource = null;

FenceSource = new Vector({
    wrapX: false,
  });

FenceLayer.value = new VectorLayer({
    source: FenceSource,
    zIndex: 1,
    style: function (feature) {
      return FenceStyle(feature, "255, 0, 0");
    },
  });


function FenceStyle(f, r) {
  let fillColor, frameColor;
  if (f.get("fillColor") == undefined || f.get("fillColor") == "null") {
    fillColor = "rgba(" + r + ",0.1)";
  } else {
    fillColor = f.get("fillColor");
  }
  if (f.get("frameColor") == undefined || f.get("frameColor") == "null") {
    frameColor = "rgb(" + r + ")";
  } else {
    frameColor = f.get("frameColor");
  }

  return [
    new Style({
      fill: new Fill({
        color: fillColor,
      }),
      stroke: new Stroke({
        lineDash: [1, 2, 3, 4, 5, 6],
        color: frameColor,
        width: 2,
      }),
    }),
  ];
}

    initCircleFence(row) {
      let leaveFence = {
        geometry: {
          coordinates: [],
          type: "Polygon",
        },
        id: row.fenceInfo.idx,
        mark: row.fenceInfo.mark,
        properties: {
          fencetype: row.fenceInfo.fenceType,
          id: row.fenceInfo.idx,
          layerId: row.fenceInfo.layerId,
          name: row.fenceInfo.fenceName,
          fillColor: "rgba(128,128,128,0.1)",
          frameColor: "rgba(128,128,128,1)",
          type: "Fence",
        },
        type: "Feature",
      };

        const geometryData = leaveFence;
        const circleFeature = new Feature({
          geometry: new CircleFeature(
            _TransPixel(geometryData.geometry.coordinates[0][0]),
            this.drp * geometryData.geometry.coordinates[0][1]
          ),
        });
        circleFeature.setId(geometryData.id);
        circleFeature.properties = geometryData.properties;
        circleFeature.coorRadiu = geometryData.geometry.coordinates[0][1];
        circleFeature.dotOrigin = geometryData.geometry.coordinates[0][0];
        circleFeature.set("name", geometryData.properties.name);
        circleFeature.set("fillColor", geometryData.properties.fillColor);
        circleFeature.set("frameColor", geometryData.properties.frameColor);
        FenceSource.addFeature(circleFeature);
      
    },

最后的实现效果:

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值