日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > vue >内容正文

vue

Vue+Openlayer使用Draw实现交互式绘制多边形并获取面积

發(fā)布時(shí)間:2025/3/19 vue 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Vue+Openlayer使用Draw实现交互式绘制多边形并获取面积 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

場(chǎng)景

Vue+Openlayer使用Draw實(shí)現(xiàn)交互式繪制線段:

Vue+Openlayer使用Draw實(shí)現(xiàn)交互式繪制線段_BADAO_LIUMANG_QIZHI的博客-CSDN博客

在上面的基礎(chǔ)上實(shí)現(xiàn)的交互式繪制線段,還可以實(shí)現(xiàn)繪制多邊形并直接計(jì)算出面積。

注:

博客:
BADAO_LIUMANG_QIZHI的博客_霸道流氓氣質(zhì)_CSDN博客
關(guān)注公眾號(hào)
霸道的程序猿
獲取編程相關(guān)電子書、教程推送與免費(fèi)下載。

實(shí)現(xiàn)

1、導(dǎo)入基本模塊

//導(dǎo)入基本模塊 import "ol/ol.css"; import Map from "ol/Map"; import View from "ol/View"; import { Fill,Style,Stroke} from "ol/style"; //導(dǎo)入相關(guān)模塊 import { Tile as TileLayer , Vector as VectorLayer } from 'ol/layer' import { TileWMS ,Vector as VectorSource } from 'ol/source' import { Select, Draw } from 'ol/interaction' import { getArea } from "ol/sphere";

2、與前面博客相比,繪圖工具傳遞的類型為Polygon

this.onAddInteraction('Polygon')

3、繪制結(jié)束時(shí)觸發(fā)的事件中獲取所繪制面積

??????? //繪制結(jié)束時(shí)觸發(fā)的事件this.draw.on('drawend', function(e) {const geometry = e.feature.getGeometry()var area = getArea(geometry);console.log("area="+area)var output;if (area > 10000) {output = (Math.round(area / 1000000 * 100) / 100) +' ' + 'km<sup>2</sup>';} else {output = (Math.round(area * 100) / 100) +' ' + 'm<sup>2</sup>';}console.log("output="+output)let pointArr = geometry.getCoordinates()self.coordinate.push(pointArr)console.log("self.coordinate="+self.coordinate);self.removeDraw()})

這里在繪制結(jié)束事的回調(diào)方法中直接獲取geometry,然后調(diào)用ol自帶的getArea方法,計(jì)算出面積

計(jì)算面積在線演示地址

ol-measure - CodeSandbox

4、完整示例代碼

? <template><div id="app"><div id="map" class="map"></div></div> </template><script> //導(dǎo)入基本模塊 import "ol/ol.css"; import Map from "ol/Map"; import View from "ol/View"; import { Fill,Style,Stroke} from "ol/style"; //導(dǎo)入相關(guān)模塊 import { Tile as TileLayer , Vector as VectorLayer } from 'ol/layer' import { TileWMS ,Vector as VectorSource } from 'ol/source' import { Select, Draw } from 'ol/interaction' import { getArea } from "ol/sphere"; export default {name: "olMapTileWMSDrawPolygon",data() {return {map: null, // map地圖layer:null, //地圖圖層lineLayer:null, //線圖層draw: null,lineSource:null,coordinate: [],};},mounted() {this.initMap();},methods: {// 繪圖工具onAddInteraction(type) {let self = this//勾繪矢量圖形的類this.draw = new Draw({//source代表勾繪的要素屬于的數(shù)據(jù)集source: self.lineSource,//type 表示勾繪的要素包含的 geometry 類型type: type})//繪制結(jié)束時(shí)觸發(fā)的事件this.draw.on('drawend', function(e) {const geometry = e.feature.getGeometry()var area = getArea(geometry);console.log("area="+area)var output;if (area > 10000) {output = (Math.round(area / 1000000 * 100) / 100) +' ' + 'km<sup>2</sup>';} else {output = (Math.round(area * 100) / 100) +' ' + 'm<sup>2</sup>';}console.log("output="+output)let pointArr = geometry.getCoordinates()self.coordinate.push(pointArr)console.log("self.coordinate="+self.coordinate);self.removeDraw()})self.map.addInteraction(this.draw)},//刪除交互removeDraw() {this.map.removeInteraction(this.draw)},initMap() {//地圖圖層this.layer = new TileLayer({source: new TileWMS({//不能設(shè)置為0,否則地圖不展示。ratio: 1,url: "http://localhost:8000/geoserver/nyc/wms",params: {LAYERS: "nyc:nyc_roads",STYLES: "",VERSION: "1.1.1",tiled: true},serverType: "geoserver",}),});//線的圖層this.lineSource = new VectorSource({ wrapX: false });this.lineLayer = new VectorLayer({source: this.lineSource,});this.map = new Map({//地圖容器IDtarget: "map",//引入地圖layers: [this.layer,this.lineLayer],view: new View({//地圖中心點(diǎn)center: [987777.93778, 213834.81024],zoom: 14,minZoom:6, // 地圖縮放最小級(jí)別maxZoom:19,}),});// 獲取點(diǎn)擊地圖的坐標(biāo)(選中樣式)let selectedStyle = new Style({fill: new Fill({color: 'rgba(1, 210, 241, 0.2)'}),stroke: new Stroke({color: 'yellow',width: 4})})// 選擇線的工具類this.selectTool = new Select({multi: true,hitTolerance: 10, // 誤差style: selectedStyle // 選中要素的樣式})//添加交互this.map.addInteraction(this.selectTool)//調(diào)用繪圖工具并傳遞類型為線,其他類型有Point,LineString,Polygon,Circlethis.onAddInteraction('Polygon')},}, }; </script><style scoped> .map {width: 100%;height: 800px; } </style>?

總結(jié)

以上是生活随笔為你收集整理的Vue+Openlayer使用Draw实现交互式绘制多边形并获取面积的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久精品9 | 91午夜在线| 国产伊人久久 | 99自拍网| 色播导航 | 欧美h视频在线观看 | 黑人操中国女人视频 | 爽妇网国产精品 | 爱福利视频广场 | 亚洲精品久久久久av无码 | 日本中文字幕在线看 | 国产精品视频一区二区三区在3 | av电影在线不卡 | 亚洲精品乱码久久久久久蜜桃不卡 | 超碰97在线资源站 | 日本囗交做爰视频 | 天堂在线精品视频 | 中国黄色三级视频 | 91视频色版| 偷拍一区二区三区 | 亚洲精品免费网站 | 国产黄色片网站 | 久热一区| 成人国产精品久久久 | 亚洲视频手机在线观看 | 91精彩刺激对白 | 国产最新视频在线 | 日韩中文在线播放 | 国产日韩精品一区 | 91精产国品| 777毛片| 四虎成人免费视频 | 丁香花高清在线 | 日本成人片网站 | 一级a毛片 | 国产伦精品一区二区三区免费视频 | 成人av资源站| 丁香六月激情 | 亚洲视频免费 | 久久婷婷精品 | 日韩视频在线观看一区二区三区 | 亚洲欧洲在线播放 | 日韩视频网| 日韩区一区二 | 美女网站黄页 | 一区二区三区视频在线免费观看 | 免费成人美女女 | 日本免费在线观看 | 亚洲天堂伦理 | 久久亚洲AV无码精品 | 欧美日韩不卡一区 | 日美毛片 | 高中男男gay互囗交观看 | 激情在线观看视频 | 午夜你懂的 | 国内视频精品 | 草草影院ccyycom | 131美女爱做视频 | 国产精品伦一区二区三级古装电影 | 7777av| 另类小说色综合 | 久久久久无码精品国产 | 性视频播放免费视频 | 久久久久久久久久久久Av | 亚洲a级片 | 六月激情婷婷 | 国产一区精品视频 | 久草a在线 | 日韩在线影视 | 精品亚洲一区二区 | www.色就是色 | 高潮毛片7777777毛片 | 成人av资源站 | 中文字幕人成乱码熟女香港 | 毛片a片免费观看 | 日本精品一区在线观看 | 开心激情播播 | 中文字幕乱码人妻无码久久95 | 精品国产青草久久久久96 | jizzjizz免费 | 国产在线资源 | 黄色的网站免费看 | 自拍偷拍亚洲一区 | 伊人精品视频 | 毛片基地在线播放 | 亚洲天天av | 日日撸夜夜撸 | 国产91网 | 国语对白91 | 日韩人妻精品一区二区 | 亚洲激情久久久 | 精品人妻久久久久久888不卡 | 黄色av网站在线免费观看 | 中文字幕手机在线视频 | www.超碰97 | 99精品久久99久久久久 | 伊人免费在线观看高清版 | 不良视频在线观看 | 国产第一页av|