Implementation code of using select to select elements in Vue+Openlayer

Implementation code of using select to select elements in Vue+Openlayer

Effect picture:

Implementation code:

<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: "Alarm 1",
            },
            geometry:
              type: "Point",
              coordinates: [91.48879670091165, 37.83814884701121],
            },
          },
          {
            type: "Feature",
            properties:
              title: "Alarm 2",
            },
            geometry:
              type: "Point",
              coordinates: [99.19515576149941, 26.713646654711134],
            },
          },
          {
            type: "Feature",
            properties:
              title: "Alarm 3",
            },
            geometry:
              type: "Point",
              coordinates: [123.74363825288785, 44.363694825734726],
            },
          },
        ],
      },
      select: {},
    };
  },
  mounted() {
    this.initMap();
  },
  methods: {
    // Initialize the map 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, //Click to select});
      this.map.addInteraction(this.select);
      this.select.on("select", (e) => {
        let coordinate = e.mapBrowserEvent.coordinate; //Get the selected coordinates let properties = e.selected[0].getProperties(); //Get all properties of the current feature });
 
      // Set the style of the mouse over the vector element this.map.on("pointermove", (e) => {
        const isHover = this.map.hasFeatureAtPixel(e.pixel);
        this.map.getTargetElement().style.cursor = isHover ? "pointer" : "";
      });
    },
  },
};
</script>

This is the end of this article about the implementation code of using select elements in Vue+Openlayer. For more relevant Vue Openlayer selection elements 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:
  • Vue+openlayers draws provincial and municipal boundaries
  • Openlayers draws administrative divisions in the Vue project
  • vue-openlayers realizes the map coordinates pop-up box effect
  • Vue+Openlayers custom track animation
  • Vue uses openlayers to implement moving point animation

<<:  Detailed explanation of three ways to connect Docker containers to each other

>>:  Detailed explanation of MySQL replication principles and practical applications

Recommend

The final solution to Chrome's minimum font size limit of 12px

I believe that many users who make websites will ...

MySQL service and database management

Table of contents 1. Start and stop service instr...

Detailed explanation of Vue mixin

Table of contents Local Mixin Global Mixins Summa...

Solutions to problems using addRoutes in Vue projects

Table of contents Preface 1. 404 Page 1. Causes 2...

Detailed explanation of pipeline and valve in tomcat pipeline mode

Preface In a relatively complex large system, if ...

Pay attention to the use of HTML tags in web page creation

HTML has attempted to move away from presentation...

Detailed tutorial on installing harbor private warehouse using docker compose

Overview What is harbor? The English word means: ...

MySQL InnoDB row_id boundary overflow verification method steps

background I talked to my classmates about a boun...

Upgrade Docker version of MySQL 5.7 to MySQL 8.0.13, data migration

Table of contents 1. Back up the old MySQL5.7 dat...

Summary of four situations of joint query between two tables in Mysql

Generally speaking, in order to get more complete...

js to realize simple shopping cart function

This article example shares the specific code of ...

onfocus="this.blur()" is hated by blind webmasters

When talking about the screen reading software op...

MySQL 8.0.18 installation and configuration graphic tutorial

Learning objectives: Learn to use Windows system ...