Vue+Openlayer中使用select選擇要素的實(shí)現(xiàn)代碼
效果圖:
實(shí)現(xiàn)代碼:
<template> <div id="map" ref="map" style="width: 100vw; height: 100vh"></div> </template> <script> import "ol/ol.css"; import { Map, View } from "ol"; import { OSM, Vector as VectorSource } from "ol/source"; import { Vector as VectorLayer, Tile as TileLayer } from "ol/layer"; import GeoJSON from "ol/format/GeoJSON"; import Select from "ol/interaction/Select"; import { altKeyOnly, click, pointerMove } from "ol/events/condition"; export default { name: "gif", data() { return { map: {}, layer: {}, geojsonData: { type: "FeatureCollection", features: [ { type: "Feature", properties: { title: "警報(bào)1", }, geometry: { type: "Point", coordinates: [91.48879670091165, 37.83814884701121], }, }, { type: "Feature", properties: { title: "警報(bào)2", }, geometry: { type: "Point", coordinates: [99.19515576149941, 26.713646654711134], }, }, { type: "Feature", properties: { title: "警報(bào)3", }, geometry: { type: "Point", coordinates: [123.74363825288785, 44.363694825734726], }, }, ], }, select: {}, }; }, mounted() { this.initMap(); }, methods: { // 初始化地圖 initMap() { this.layer = new VectorLayer({ source: new VectorSource({ features: new GeoJSON().readFeatures(this.geojsonData), }), }); this.map = new Map({ target: "map", layers: [ new TileLayer({ source: new OSM(), }), this.layer, ], view: new View({ projection: "EPSG:4326", center: [104.912777, 34.730746], zoom: 4.5, }), }); this.select = new Select({ condition: click, //單擊選擇 }); this.map.addInteraction(this.select); this.select.on("select", (e) => { let coordinate = e.mapBrowserEvent.coordinate; //獲取選擇的坐標(biāo) let properties = e.selected[0].getProperties(); //獲取當(dāng)前要素的所有屬性 }); // 設(shè)置鼠標(biāo)劃過矢量要素的樣式 this.map.on("pointermove", (e) => { const isHover = this.map.hasFeatureAtPixel(e.pixel); this.map.getTargetElement().style.cursor = isHover ? "pointer" : ""; }); }, }, }; </script>
到此這篇關(guān)于Vue+Openlayer中使用select選擇要素的實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)Vue Openlayer選擇要素內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
koa2+vue實(shí)現(xiàn)登陸及登錄狀態(tài)判斷
這篇文章主要介紹了koa2+vue實(shí)現(xiàn)登陸及登錄狀態(tài)判斷,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-08-08useEffect理解React、Vue設(shè)計(jì)理念的不同
這篇文章主要為大家介紹了useEffect理解React、Vue設(shè)計(jì)理念的不同詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09對(duì)vuex中g(shù)etters計(jì)算過濾操作詳解
今天小編就為大家分享一篇對(duì)vuex中g(shù)etters計(jì)算過濾操作詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11Vue實(shí)現(xiàn)用戶沒有登陸時(shí),訪問后自動(dòng)跳轉(zhuǎn)登錄頁面的實(shí)現(xiàn)思路
這篇文章主要介紹了Vue實(shí)現(xiàn)用戶沒有登陸時(shí),訪問后自動(dòng)跳轉(zhuǎn)登錄頁面,定義路由的時(shí)候配置屬性,這里使用needLogin標(biāo)記訪問頁面是否需要登錄,本文通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02vue導(dǎo)出excel和echart圖形分別在不同工作表的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了如何使用vue實(shí)現(xiàn)導(dǎo)出excel和echart圖形分別在不同工作表,文中有詳細(xì)的代碼示例供大家參考,對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2023-10-10Jenkins?Sidebar?Link插件實(shí)現(xiàn)添加側(cè)邊欄功能詳解
這篇文章主要介紹了vue框架實(shí)現(xiàn)添加側(cè)邊欄,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12Vue中渲染系統(tǒng)模塊的實(shí)現(xiàn)詳解
想要實(shí)現(xiàn)一個(gè)簡潔版的Mini-Vue框架,應(yīng)該包含三個(gè)模塊:分別是:渲染系統(tǒng)模塊、可響應(yīng)式系統(tǒng)模塊、應(yīng)用程序入庫模塊,本文主要介紹的是渲染系統(tǒng)模塊的實(shí)現(xiàn),需要的可以參考一下2023-07-07vue項(xiàng)目報(bào)錯(cuò)Extra?semicolon?(semi)問題及解決
這篇文章主要介紹了vue項(xiàng)目報(bào)錯(cuò)Extra?semicolon?(semi)問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10