OpenLayers工具栏(vue中使用)

效果如下
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这只是一小部分效果图片,因为动态图片超出大小,只能放静态图片。

完整代码部分

<template>
  <!-- 绘制、编辑、输出GeoJson数据 -->
  <div ref="map" id="map">
    <div class="btns">
      <button @click="drawFeature">绘制</button>
      <button @click="editorFeature" v-text="editorBtnText"></button>
      <button @click="outputJson">输出Json</button>
      <button @click="measure('distence')"></button>
      <button @click="measure('area')"></button>
      <button @click="measure('angle')"></button>
      <button @click="fullscreen" v-html="textarr"></button>
      <button @click="single">坐标</button>
      <button @click="clear">清除</button>
    </div>
  </div>
</template>

<script>
import "ol/ol.css";
import Map from "ol/Map";
import View from "ol/View";
import {
      Vector as VectorSource, OSM } from "ol/source";
import {
      Tile as TileLayer, Vector as VectorLayer } from "ol/layer";
import {
      GeoJSON } from "ol/format";
// 交互 Select在选择功能时触发。Modify用于修改功能几何的交互。Draw绘制功能几何的交互。
import {
      Draw, Modify, Select } from "ol/interaction";

import Overlay from "ol/Overlay";
// 线条几何形状。
import {
      LineString } from "ol/geom";
// 具有几何和其他属性属性属性的地理特征的矢量对象,类似于像 GeoJSON 这样的矢量文件格式中的特征。
import Feature from "ol/Feature";
// 使用返回的键或
import {
      unByKey } from "ol/Observable";
// 获取几何形状的球形长度和面积
import {
      getLength, getArea } from "ol/sphere";
import Style from "ol/style/Style";
import Stroke from "ol/style/Stroke";
import Fill from "ol/style/Fill";
import Circle from "ol/style/Circle";
// import Icon from "ol/style/Icon";
// import { transform } from "ol/proj";
// import Point from "ol/geom/Point";
export default {
     
  data() {
     
    return {
     
      map: null,
      vectorLayer: null,
      vectorSource: null,
      draw: null,
      select: null,
      modify: null,
      editorBtnText: "编辑",

      textarr: "全屏",
      measureType: "diatence",
      tipDiv: null,
      pointermoveEvent: null, // 地图pointermove事件
      sketchFeature: null, // 绘制的要素
      geometryListener: null, // 要素几何change事件
      measureResult: "0", // 测量结果
    };
  },
  mounted() {
     
    // 底图
    var baseLayer = new TileLayer({
     
      source: new OSM(),
    });
    // 矢量图层源
    this.vectorSource = new VectorSource({
     
      wrapX: false,
    });
    // 矢量图层
    this.vectorLayer = new VectorLayer({
     
      source: this.vectorSource,
    });

    this.map = new Map({
     
      layers: [baseLayer, this.vectorLayer],
      target: "map",
      view: new View({
     
        projection: "EPSG:4326",
        center: [104.06531800244139, 30.65852484539117],
        zoom: 10,
      }),
    });
  },
  methods: {
     
    drawFeature() {
     
      this.draw = new Draw({
     
        source: this.vectorSource,
        // 用此实例绘制的几何形状类型。
        type: "Polygon",
      });
      // addInteraction  将给定的交互添加到地图中
      this.map.addInteraction(this.draw);
      // 绘制完成
      this.draw.on("drawend", () => {
     
        //  removeInteraction 从地图中删除给定的交互。
        this.map.removeInteraction(this.draw);
        this.draw = null;
      });
    
  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值