vue項(xiàng)目中openlayers繪制行政區(qū)劃
vue項(xiàng)目中openlayers畫(huà)行政區(qū)劃(區(qū)域范圍),供大家參考,具體內(nèi)容如下
原理
在地圖上畫(huà)需要的范圍,實(shí)際上就是在地圖上打上一圈點(diǎn),然后依次將這些點(diǎn)用線連接,就形成了范圍
引用相應(yīng)的ol模塊
import VectorLayer from ’ol/layer/Vector’import VectorSource from ’ol/source/Vector’import { Map, View, Feature } from ’ol’import { Style, Icon, Stroke } from ’ol/style’import { Point, LineString, Polygon } from ’ol/geom’
獲取范圍點(diǎn)
這里我將點(diǎn)放在json文件中,然后通過(guò)axios讀取json文件截圖:
axios.get(’static/常德市.json’).then((res) => { let arr = res.data.coordinates let polygonFeature = new Feature({ type: ’polygon’, geometry: new Polygon(arr[0]) }) polygonFeature.setStyle(new Style({ stroke: new Stroke({ width: 2, color: [255, 255, 0, 0.8] }), fill: new Fill({ color: [248, 172, 166, 0.2] }) // text: new Text({ // text: ’這是區(qū)域’ // }) })) let polygonLayer = new VectorLayer({ source: new VectorSource({ features: [polygonFeature] }) }) this.gmap.addLayer(polygonLayer) }) axios.get(’static/懷化市沅陵縣.json’).then((res) => { let arr = res.data.coordinates let polygonFeature = new Feature({ type: ’polygon’, geometry: new Polygon(arr[0]) }) polygonFeature.setStyle(new Style({ stroke: new Stroke({ width: 2, color: [255, 255, 0, 0.8] }), fill: new Fill({ color: [248, 172, 166, 0.2] }) // text: new Text({ // text: ’這是區(qū)域’ // }) })) let polygonLayer = new VectorLayer({ source: new VectorSource({ features: [polygonFeature] }) }) this.gmap.addLayer(polygonLayer) })
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Python中Anaconda3 安裝gdal庫(kù)的方法2. PHP AOP教程案例3. python用zip壓縮與解壓縮4. python公司內(nèi)項(xiàng)目對(duì)接釘釘審批流程的實(shí)現(xiàn)5. Notepad++如何配置python?配置python操作流程詳解6. Python 簡(jiǎn)介7. Python操作Excel工作簿的示例代碼(*.xlsx)8. JAVA如何轉(zhuǎn)換樹(shù)結(jié)構(gòu)數(shù)據(jù)代碼實(shí)例9. Python importlib模塊重載使用方法詳解10. Python自動(dòng)化之定位方法大殺器xpath
