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

mySql SQL query operation on statistical quantity

I won't say much nonsense, let's just loo...

Detailed explanation of Js class construction and inheritance cases

The definition and inheritance of classes in JS a...

Steps for Docker to build its own local image repository

1. Environment and preparation 1. Ubuntu 14.04 2....

Common considerations for building a Hadoop 3.2.0 cluster

One port changes In version 3.2.0, the namenode p...

The difference between the four file extensions .html, .htm, .shtml and .shtm

Many friends who have just started to make web pag...

Introduction to deploying selenium crawler program under Linux system

Table of contents Preface 1. What is selenium? 2....

Comprehensive understanding of html.css overflow

Comprehensive understanding of html.css overflow ...

Detailed example of mysql similar to oracle rownum writing

Rownum is a unique way of writing in Oracle. In O...

How to use webSocket to update real-time weather in Vue

Table of contents Preface About webSocket operati...

Linux sudo vulnerability could lead to unauthorized privileged access

Exploiting a newly discovered sudo vulnerability ...

Vue implements tab navigation bar and supports left and right sliding function

This article mainly introduces: using Vue to impl...

svg+css or js to create tick animation effect

Previously, my boss asked me to make a program th...