Vue+Openlayer中使用select選擇要素
本文通過例項程式碼給大家介紹Vue+Openlayer中使用select選擇要素,程式碼簡單易懂,對大家的學習或工作具有一定的參考借鑑價值,需要的朋友參考下吧 |
效果圖:
實現程式碼:
<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: "警報1", }, geometry: { type: "Point", coordinates: [91.48879670091165, 37.83814884701121], }, }, { type: "Feature", properties: { title: "警報2", }, geometry: { type: "Point", coordinates: [99.19515576149941, 26.713646654711134], }, }, { type: "Feature", properties: { title: "警報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; //獲取選擇的座標 let properties = e.selected[0].getProperties(); //獲取當前要素的所有屬性 }); // 設定滑鼠劃過向量要素的樣式 this.map.on("pointermove", (e) => { const isHover = this.map.hasFeatureAtPixel(e.pixel); this.map.getTargetElement().style.cursor = isHover ? "pointer" : ""; }); }, }, }; </script>
到此這篇關於Vue+Openlayer中使用select選擇要素的實現程式碼的文章就介紹到這了
「其他文章」
- sql server如何刪除前1000行資料
- spring boot 不連線資料庫啟動
- 刪除字串中的所有相鄰重複項
- 超全面的Linux基礎知識的梳理
- 手把手教你 Socket 通訊(TCP/IP)
- Vue Openlayer中使用select選擇要素
- 對order by的理解
- 在docker中haproxy的安裝以及mysql的負載均衡配置
- JavaScript字串中URL的檢測並轉換為連結
- 只要有熱情和方法就能學好Linux
- Highcharts 環境配置介紹
- Centos7安裝與配置OpenVPN伺服器
- ECharts 互動元件概述
- docker初體驗:docker部署wordpress部落格系統
- 如何使用evilscan 掃描網路
- docker初體驗:docker 自己定製映象
- ECharts 樣式設定介紹
- 一名合格的運維工程師的歷練之路
- Python中非常有用的三個資料科學庫
- ssl證書是由什麼組成?ssl證書是什麼?