Preface:How to get the coordinates of the current mouse in the Vue project? Here is a method to share. Result: Implementation steps:1. Import relevant documents import MousePosition from 'ol/control/MousePosition'; import {createStringXY} from 'ol/coordinate'; 2. Generate a map var layers = [ //Dark blue background 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. Add mouse events var mousePositionControl = new MousePosition({ coordinateFormat: createStringXY(6), //Get the location projection: 'EPSG:4326', className: 'custom-mouse-position', target: document.getElementById('mouse-position'), //Put the position data there undefinedHTML: ' ' }); this.map.addControl(mousePositionControl); 4. Add on the page <div id="map" class="map" ref="imageDom"> Position 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> This is the end of this article about vue+openlayer5 getting the coordinates of the current mouse. For more relevant vue+openlayer5 mouse coordinates content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Three uses and differences of MySQL not equal
>>: Introduction to the use of select optgroup tag in html
This article shares with you the installation and...
By adding the current scroll offset to the attrib...
Use anti-shake to make DIV disappear when the mou...
1: Installation command pip install docker-compos...
reduce method is an array iteration method. Unlik...
background All company websites need to support t...
Preface Recently, I accidentally discovered MySQL...
New Questions Come and go in a hurry. It has been...
Preface We all know that startups initially use m...
operating system: Win10 Home Edition Install Dock...
1. IE8's getElementById only supports id, not ...
Nginx log description Through access logs, you ca...
I often see some circular wave graphics on mobile...
Preface I watched web.dev's 2020 three-day li...
Table of contents Implementing state sharing base...