欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue+penlayers實現(xiàn)多邊形繪制及展示

 更新時間:2020年12月24日 10:17:41   作者:小小并不小  
這篇文章主要為大家詳細介紹了Vue+penlayers實現(xiàn)多邊形繪制及展示,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Vue+penlayers實現(xiàn)多邊形繪制展示代碼,供大家參考,具體內(nèi)容如下

<!--
 * @Description: 繪制多邊形
 * @Author: Dragon
 * @Date: 2020-12-17 16:02:06
 * @LastEditTime: 2020-12-18 17:20:33
 * @LastEditors: Dragon
-->

<template>
 <div>
  <div class="query-wrap">
   <el-button type="primary" @click="drawStart('Polygon')">
    {{ isDraw ? "繪制區(qū)域" : "重新繪制" }}
   </el-button>
  </div>
  <div id="map"></div>
 </div>
</template>

<script>
import "ol/ol.css";
import { Map, View } from "ol";
import { Image as ImageLayer, Vector as VectorLayer } from "ol/layer";
import { ImageStatic, Vector as VectorSource } from "ol/source";
import { getCenter } from "ol/extent";
import { Projection } from "ol/proj";

import Draw from "ol/interaction/Draw";
import { Style, Fill, Stroke } from "ol/style";

import { GeoJSON } from "ol/format";
import staticMap from "@/assets/map.png";

export default {
 data() {
  return {
   map: null, // 地圖
   imgx: 0, // 當前地圖寬
   imgy: 0, // 當前地圖高
   isDraw: true, // 是否繪制
   draw: null,
   source: null,
   vector: null,
   styles: [
    new Style({
     stroke: new Stroke({
      color: "rgba(255,0,0,0.6)",
      width: 2,
     }),
     fill: new Fill({
      color: "rgba(255,0,0,0.3)",
     }),
    }),
   ],
   geojsonObject: {
     'type': 'FeatureCollection',
     'features': [
      {
       'type': 'Feature',
       'geometry': {
        'type': 'Polygon',
        'coordinates': [
         [
          [97.16862961519749, 322.26517247174047],
          [117.3211820327625, 481.9353954724479],
          [1.056456546810466, 489.6863771715114],
          [13.458027265312012, 320.71497613192776],
          [97.16862961519749, 322.26517247174047]
                   ]
        ],
       },
      },
     ],
    },
  };
 },
 methods: {
  // 初始化地圖
  initMap() {
   let extent = [0, 0, this.imgx, this.imgy];
   let projection = new Projection({
    code: "xkcd-image",
    units: "pixels",
    extent: extent,
   });
   let $this = this;
   this.map = new Map({
    target: "map",
    layers: [
     new ImageLayer({ // 展示地圖層
      source: new ImageStatic({
       url: staticMap,
       projection: projection,
       imageExtent: extent,
      }),
     }),
     new VectorLayer({
      source: new VectorSource({
       features: new GeoJSON().readFeatures($this.geojsonObject),
      }),
      style: $this.styles,
     }),
    ],
    view: new View({
     projection: projection,
     center: getCenter(extent),
     zoom: 2,
     maxZoom: 18,
    }),
   });

   this.source = new VectorSource({ wrapX: false })
   this.vector = new VectorLayer({
    source: this.source,
    style: this.styles
   })
   this.map.addLayer(this.vector)
  },
  
  // 開始繪制多邊形
  drawStart(type) {
   let that = this;
   if(this.isDraw) {
    this.isDraw = false
    this.draw = new Draw({
     source: this.source,
     type: type,
    });
    this.map.addInteraction(this.draw);
    this.draw.on("drawend", function (evt) {
     that.drawingEnd(evt);
    });
   } else {
    this.source.clear()
    this.map.removeInteraction(this.draw);
    this.isDraw = true
   }
   
  },

  // 構(gòu)建多邊形結(jié)束
  drawingEnd(evt) {
   let that = this
   const geo = evt.feature.getGeometry();
   const t = geo.getType();
   if (t === "Polygon") {
    // 獲取坐標點
    const points = geo.getCoordinates();
    console.warn(points, "繪制結(jié)束,點坐標")
    this.map.removeInteraction(this.draw); // 移除繪制
   }
  },
 },
 mounted() {
  let that = this;
  let img = new Image();
  setTimeout(function() {
   img.src = staticMap;
   img.onload = function (res) {
    that.imgx = res.target.width;
    that.imgy = res.target.height;
    that.initMap();
   };
  }, 500)
  
 },
};
</script>

<style>
#map {
 width: 100%;
 height: calc(100vh - 50px);
}
</style>

效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 解決vue熱替換失效的根本原因

    解決vue熱替換失效的根本原因

    今天小編就為大家分享一篇解決vue熱替換失效的根本原因,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • Vue.js輪播圖走馬燈代碼實例(全)

    Vue.js輪播圖走馬燈代碼實例(全)

    這篇文章主要介紹了Vue.js輪播圖走馬燈,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-05-05
  • vue3封裝Notification組件的完整步驟記錄

    vue3封裝Notification組件的完整步驟記錄

    在我們使用vue的開發(fā)過程中總會遇到這樣的場景,封裝自己的業(yè)務(wù)組件,下面這篇文章主要給大家介紹了關(guān)于vue3封裝Notification組件的完整步驟,本文通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-03-03
  • 詳解讓sublime text3支持Vue語法高亮顯示的示例

    詳解讓sublime text3支持Vue語法高亮顯示的示例

    本篇文章主要介紹了讓sublime text3支持Vue語法高亮顯示的示例,非常具有實用價值,需要的朋友可以參考下
    2017-09-09
  • Vue中使用v-print打印出現(xiàn)空白頁問題及解決

    Vue中使用v-print打印出現(xiàn)空白頁問題及解決

    這篇文章主要介紹了Vue中使用v-print打印出現(xiàn)空白頁問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Vuex利用state保存新聞數(shù)據(jù)實例

    Vuex利用state保存新聞數(shù)據(jù)實例

    本篇文章主要介紹了Vuex利用state保存新聞數(shù)據(jù)實例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • Vue3父子通訊方式及Vue3插槽的使用方法詳解

    Vue3父子通訊方式及Vue3插槽的使用方法詳解

    這篇文章主要介紹了Vue3父子通訊方式及Vue3插槽的使用方法詳解,需要的朋友可以參考下
    2023-01-01
  • Vue router配置與使用分析講解

    Vue router配置與使用分析講解

    第一次寫Vue項目,要用到router.js,看了一下官方文檔,還是很懵逼,不知道怎么配置,又去看視頻查資料,最后終于搞定了。話不多說,先上代碼,我再講一些要注意的細節(jié)
    2022-12-12
  • 基于ElementUI實現(xiàn)v-tooltip指令的示例代碼

    基于ElementUI實現(xiàn)v-tooltip指令的示例代碼

    文本溢出隱藏并使用tooltip 提示的需求,相信在平時的開發(fā)中會經(jīng)常遇到,常規(guī)做法一般是使用 elementui 的 el-tooltip 組件,在每次組件更新的時候去獲取元素的寬度/高度判斷是否被隱藏,本文給大家介紹了基于ElementUI實現(xiàn)v-tooltip指令,需要的朋友可以參考下
    2024-09-09
  • vue使用iframe嵌入網(wǎng)頁的示例代碼

    vue使用iframe嵌入網(wǎng)頁的示例代碼

    本篇文章主要介紹了vue使用iframe嵌入網(wǎng)頁的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03

最新評論