Vue+Openlayer batch setting flash point implementation code (based on postrender mechanism)

Vue+Openlayer batch setting flash point implementation code (based on postrender mechanism)

Effect picture:

Implementation code:

<template>
  <div id="map" style="width: 100vw; height: 100vh" />
</template>
<script>
import "ol/ol.css";
import TileLayer from "ol/layer/Tile";
import VectorLayer from "ol/layer/Vector";
import VectorSource from "ol/source/Vector";
import XYZ from "ol/source/XYZ";
import { Map, View, Feature } from "ol";
import { Style, Circle, Stroke } from "ol/style";
import { Point } from "ol/geom";
import { getVectorContext } from "ol/render";
 
// Boundary json data export default {
  data() {
    return {
      map: {},
      coordinates: [
        { x: "106.918082", y: "31.441314" }, //Chongqing{ x: "86.36158200334317", y: "41.42448570787448" }, //Xinjiang{ x: "89.71757707811526", y: "31.02619817424643" }, //Tibet{ x: "116.31694544853109", y: "39.868508850821115" }, //Beijing{ x: "103.07940932026341", y: "30.438580338450862" }, //Chengdu],
      speed: 0.3,
    };
  },
  mounted() {
    this.initMap();
    this.addDynamicPoints(this.coordinates);
  },
  methods: {
    /**
     * Initialize the map */
    initMap() {
      this.map = new Map({
        target: "map",
        layers:
          new TileLayer({
            source: new XYZ({
              url: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",
            }),
          }),
        ],
        view: new View({
          projection: "EPSG:4326",
          center: [108.522097, 37.272848],
          zoom: 4.7,
        }),
      });
    },
    /**
     * Add flashing points in batches */
    addDynamicPoints(coordinates) {
      // Set up the layer let pointLayer = new VectorLayer({ source: new VectorSource() });
      //Add layer this.map.addLayer(pointLayer);
      // Loop to add features
      let pointFeature = [];
      for (let i = 0; i < coordinates.length; i++) {
        // Create a feature. A feature is a point coordinate information const feature = new Feature({
          geometry: new Point([coordinates[i].x, coordinates[i].y]),
        });
        pointFeature.push(feature);
      }
      //Add the feature collection to the layer pointLayer.getSource().addFeatures(pointFeature);
      // The key point is here: listen to the postrender event and reset the circle style in it let radius = 0;
      pointLayer.on("postrender", (e) => {
        if (radius >= 20) radius = 0;
        let opacity = (20 - radius) * (1 / 20); // opacity let pointStyle = new Style({
          image: new Circle({
            radius: radius,
            stroke: new Stroke({
              color: "rgba(255,0,0" + opacity + ")",
              width: 3 - radius / 10, //Set width}),
          }),
        });
        // Get the vector feature context let vectorContext = getVectorContext(e);
        vectorContext.setStyle(pointStyle);
        pointFeature.forEach((feature) => {
          vectorContext.drawGeometry(feature.getGeometry());
        });
        radius = radius + this.speed; //Adjust the flashing speed //Request map rendering (at the next animation frame)
        this.map.render();
      });
    },
  },
};
</script>

References

This is the end of this article about the implementation code of Vue+Openlayer batch setting flashing points (based on postrender mechanism). For more relevant Vue Openlayer flashing point 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 achieves real-time positioning function
  • Method of dynamically loading geojson based on Vue+Openlayer
  • Using Openlayer in Vue to realize loading animation effect
  • 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
  • Tutorial on how to integrate openlayers with Vue to load geojson and implement a pop-up window
  • Vue+Openlayers custom track animation

<<:  Detailed explanation of Deepin using docker to install mysql database

>>:  Example analysis of mysql user rights management

Recommend

19 MySQL optimization methods in database management

After MySQL database optimization, not only can t...

Commonly used English fonts for web page creation

Arial Arial is a sans-serif TrueType font distribu...

How to allow external network access to mysql and modify mysql account password

The root account of mysql, I usually use localhos...

JavaScript removes unnecessary properties of an object

Table of contents Example Method 1: delete Method...

Upgrade MySQL 5.1 to 5.5.36 in CentOS

This article records the process of upgrading MyS...

Understanding the CSS transform-origin property

Preface I recently made a fireworks animation, wh...

Example of how to implement local fuzzy search function in front-end JavaScript

Table of contents 1. Project Prospects 2. Knowled...

How to install the graphical interface in Linux

1. Linux installation (root user operation) 1. In...

How to automatically backup mysql remotely under Linux

Preface: Basically, whether it is for our own use...

Detailed configuration of mysql8.x docker remote access

Table of contents Environmental conditions Errors...

How to use async and await in JS

Table of contents 1. async 2. await: 3. Comprehen...

Teach you how to install docker on windows 10 home edition

When I wrote the Redis book and the Spring Cloud ...

Complete steps to use samba to share folders in CentOS 7

Preface Samba is a free software that implements ...

Detailed explanation of redo log and undo log in MySQL

The most important logs in the MySQL log system a...