vue項(xiàng)目中openlayers繪制行政區(qū)劃
vue項(xiàng)目中openlayers畫行政區(qū)劃(區(qū)域范圍),供大家參考,具體內(nèi)容如下
原理
在地圖上畫需要的范圍,實(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. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向2. Python importlib動(dòng)態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼3. android studio 打包自動(dòng)生成版本號(hào)與日期,apk輸入路徑詳解4. 利用promise及參數(shù)解構(gòu)封裝ajax請(qǐng)求的方法5. 淺談python出錯(cuò)時(shí)traceback的解讀6. 在Android中使用WebSocket實(shí)現(xiàn)消息通信的方法詳解7. .NET中l(wèi)ambda表達(dá)式合并問(wèn)題及解決方法8. Nginx+php配置文件及原理解析9. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解10. JSP數(shù)據(jù)交互實(shí)現(xiàn)過(guò)程解析
