色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:34日期:2022-10-16 15:24:18

本文實例為大家分享了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, // 當(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') { // 獲取坐標點 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>

效果圖:

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 精品视频免费在线 | 欧美在线一级片 | 性欧美高清极品xx | 亚洲人成网国产最新在线 | 特级a级毛片 | 免费一级视频在线播放 | 在线亚洲成人 | 国产网红自拍 | 欧美黄a| 久草视频手机在线观看 | 国产午夜精品久久理论片小说 | 国产精品久久久影院 | 91久久精品一区二区三区 | 亚洲 成人 欧美 自拍 | 精品国产一区二区三区四区vr | 久草精彩视频 | 免费毛片网站 | 综合视频在线 | 九九在线观看视频 | 欧美精品在线一区 | 欧美一级大片免费观看 | 一级毛片美国一级j毛片不卡 | 性生活视频网站 | 国产精品亚洲玖玖玖在线靠爱 | 欧美日韩视频一区二区三区 | 香蕉毛片a | 欧美精品在线视频 | 91在线一区二区三区 | 日本精品高清一区二区2021 | 免费va国产高清不卡大片 | 香港三级做爰大爽视频 | 久久免费激情视频 | 怡红院成人网 | 国产精品不卡无毒在线观看 | 亚洲一级毛片中文字幕 | 在线成年人网站 | 久草福利资源在线观看 | 久久这里只有精品免费播放 | 在线播放国产一区二区三区 | 国产一二三区视频 | 干综合网 |