Vue+openlayer5 method to get the coordinates of the current mouse slide

Vue+openlayer5 method to get the coordinates of the current mouse slide

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: '&nbsp'
      });
      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:
  • Detailed explanation of Vue's coordinate picker function example
  • vue-openlayers realizes the map coordinates pop-up box effect
  • Vue uses Gaode map to locate points according to coordinates
  • Vue method to get element width, height, distance from left, right, top, etc. as well as XY coordinate axis
  • Vue+Openlayers realizes real-time coordinate point display

<<:  Three uses and differences of MySQL not equal

>>:  Introduction to the use of select optgroup tag in html

Recommend

Vue component library ElementUI realizes the paging effect of table list

ElementUI implements the table list paging effect...

Set the width of the table to be fixed so that it does not change with the text

After setting the table width in the page to width...

Complete steps to set up automatic updates in CentOS 8

The best thing you can do for your data and compu...

Javascript operation mechanism Event Loop

Table of contents 1. Four concepts 1. JavaScript ...

The process of building and configuring the Git environment in Docker

Configure Git environment in Docker At work, I en...

How to isolate users in docker containers

In the previous article "Understanding UID a...

How to achieve 3D dynamic text effect with three.js

Preface Hello everyone, this is the CSS wizard - ...

MySQL trigger trigger add, delete, modify and query operation example

This article uses examples to describe the add, d...

Detailed tutorial on using Docker to build Gitlab based on CentOS8 system

Table of contents 1. Install Docker 2. Install Gi...

A brief analysis of the function calling process under the ARM architecture

Table of contents 1. Background knowledge 1. Intr...

3 ways to correctly modify the maximum number of connections in MySQL

We all know that after the MySQL database is inst...

Complete steps of centos cloning linux virtual machine sharing

Preface When a Linux is fully set up, you can use...