最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

本文實(shí)例為大家分享了Vue+penlayers實(shí)現(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, // 當(dāng)前地圖寬
   imgy: 0, // 當(dāng)前地圖高
   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") {
    // 獲取坐標(biāo)點(diǎn)
    const points = geo.getCoordinates();
    console.warn(points, "繪制結(jié)束,點(diǎn)坐標(biāo)")
    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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue select選擇框數(shù)據(jù)變化監(jiān)聽方法

    vue select選擇框數(shù)據(jù)變化監(jiān)聽方法

    今天小編就為大家分享一篇vue select選擇框數(shù)據(jù)變化監(jiān)聽方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • vue項(xiàng)目npm?run?build打包dist文件及打包后空白解決辦法

    vue項(xiàng)目npm?run?build打包dist文件及打包后空白解決辦法

    npm run build 這個(gè)命令會(huì)執(zhí)行Vue CLI中預(yù)定義的打包配置,并將打包后的文件存放在"dist"文件夾中,這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目npm?run?build打包dist文件及打包后空白的解決辦法,需要的朋友可以參考下
    2023-10-10
  • 解決vue 綁定對象內(nèi)點(diǎn)擊事件失效問題

    解決vue 綁定對象內(nèi)點(diǎn)擊事件失效問題

    今天小編就為大家分享一篇解決vue 綁定對象內(nèi)點(diǎn)擊事件失效問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • vue打包部署到springboot的實(shí)現(xiàn)示例

    vue打包部署到springboot的實(shí)現(xiàn)示例

    項(xiàng)目開發(fā)中,一般我們都會(huì)使用SpringBoot+Vue進(jìn)行前后端開發(fā),本文主要介紹了vue打包部署到springboot的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-07-07
  • Vue-router優(yōu)化import引入過多導(dǎo)致index文件臃腫問題

    Vue-router優(yōu)化import引入過多導(dǎo)致index文件臃腫問題

    這篇文章主要為大家介紹了Vue-router優(yōu)化import引入過多導(dǎo)致index文件臃腫問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • vite打包出現(xiàn)?"default"?is?not?exported?by?"node_modules/...問題解決辦法

    vite打包出現(xiàn)?"default"?is?not?exported?by?"

    這篇文章主要給大家介紹了關(guān)于vite打包出現(xiàn)?"default"?is?not?exported?by?"node_modules/...問題的解決辦法,文中通過代碼將解決的辦法介紹的非常詳細(xì),對同樣遇到這個(gè)問題的朋友具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2024-06-06
  • Vue自定義el-table表格表頭高度的多種實(shí)現(xiàn)方法

    Vue自定義el-table表格表頭高度的多種實(shí)現(xiàn)方法

    在Vue項(xiàng)目中,使用Element?UI的el-table組件可以輕松創(chuàng)建功能豐富的表格,然而,默認(rèn)情況下,el-table的表頭高度是固定的,本文將詳細(xì)介紹如何自定義el-table表頭的高度,提供多種實(shí)現(xiàn)方法,需要的朋友可以參考下
    2024-10-10
  • Vue中為什么要引入render函數(shù)的實(shí)現(xiàn)

    Vue中為什么要引入render函數(shù)的實(shí)現(xiàn)

    本文主要介紹了Vue中為什么要引入render函數(shù)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • element 穿梭框性能優(yōu)化的實(shí)現(xiàn)

    element 穿梭框性能優(yōu)化的實(shí)現(xiàn)

    本文主要介紹了element 穿梭框性能優(yōu)化,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • vue列表單項(xiàng)展開收縮功能之this.$refs的詳解

    vue列表單項(xiàng)展開收縮功能之this.$refs的詳解

    這篇文章主要介紹了vue列表單項(xiàng)展開收縮功能之this.$refs的詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05

最新評論

依兰县| 广西| 射洪县| 南汇区| 抚州市| 枣强县| 白朗县| 阿坝县| 尚志市| 忻州市| 云梦县| 固原市| 郴州市| 三都| 扶绥县| 黎城县| 漯河市| 门源| 洞口县| 北辰区| 赤峰市| 蓝山县| 万州区| 三都| 广宗县| 五大连池市| 民县| 皮山县| 澜沧| 饶河县| 大兴区| 集贤县| 基隆市| 屏东县| 剑河县| 通山县| 株洲县| 永和县| 永福县| 乌审旗| 孝感市|