您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“怎么實(shí)現(xiàn)vue+openlayer5獲取當(dāng)前鼠標(biāo)滑過的坐標(biāo)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“怎么實(shí)現(xiàn)vue+openlayer5獲取當(dāng)前鼠標(biāo)滑過的坐標(biāo)”吧!
在vue項(xiàng)目中怎么獲取當(dāng)前鼠標(biāo)劃過的坐標(biāo)呢,這里來分享下方法。 實(shí)現(xiàn)效果:
1、引入相關(guān)文件
import MousePosition from 'ol/control/MousePosition'; import {createStringXY} from 'ol/coordinate';
2、生成地圖
var layers = [ //深藍(lán)色背景 new TileLayer({ source: new XYZ({ url: "https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}", }), }), ]; this.map = new Map({ layers: layers, target: "map", view: new View({ center: this.center, projection: this.projection, zoom: this.centerSize, maxZoom: 17, minZoom: 5, extent: [ 73.32783475401652, 3.33795, 135.16017906160056, 53.83501005646246, ], }), });
3、加入鼠標(biāo)事件
var mousePositionControl = new MousePosition({ coordinateFormat: createStringXY(6),//獲取位置 projection: 'EPSG:4326', className: 'custom-mouse-position', target: document.getElementById('mouse-position'), //將位置數(shù)據(jù)放到那里 undefinedHTML: ' ' }); this.map.addControl(mousePositionControl);
4、頁面上加入
<div id="map" class="map" ref="imageDom"> 位置div <div id="mouse-position" style=" color: #fff; position: absolute; bottom:10px; right:10px; z-index: 10000000; width: 200px; line-height: 30px; background: rgba(0,0,0,0.5); "></div> </div>
到此,相信大家對(duì)“怎么實(shí)現(xiàn)vue+openlayer5獲取當(dāng)前鼠標(biāo)滑過的坐標(biāo)”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。