vue openlayer5鼠标坐标 vue+openlayer5获取当前鼠标滑过的坐标实现方法
浩星 人气:0想了解vue+openlayer5获取当前鼠标滑过的坐标实现方法的相关内容吗,浩星在本文为您仔细讲解vue openlayer5鼠标坐标的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:vue,openlayer5鼠标坐标,vue,openlayer坐标,下面大家一起来学习吧。
前言:
在vue项目中怎么获取当前鼠标划过的坐标呢,这里来分享下方法。 实现效果:
实现步骤:
1、引入相关文件
import MousePosition from 'ol/control/MousePosition'; import {createStringXY} from 'ol/coordinate';
2、生成地图
var layers = [ //深蓝色背景 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、加入鼠标事件
var mousePositionControl = new MousePosition({ coordinateFormat: createStringXY(6),//获取位置 projection: 'EPSG:4326', className: 'custom-mouse-position', target: document.getElementById('mouse-position'), //将位置数据放到那里 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>
加载全部内容