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:
|
<<: Detailed explanation of Deepin using docker to install mysql database
>>: Example analysis of mysql user rights management
After MySQL database optimization, not only can t...
Arial Arial is a sans-serif TrueType font distribu...
The root account of mysql, I usually use localhos...
Table of contents Example Method 1: delete Method...
This article records the process of upgrading MyS...
Preface I recently made a fireworks animation, wh...
Table of contents 1. Project Prospects 2. Knowled...
1. Linux installation (root user operation) 1. In...
system: VMTOOLs Download: Link: https://pan.baidu...
Preface: Basically, whether it is for our own use...
Table of contents Environmental conditions Errors...
Table of contents 1. async 2. await: 3. Comprehen...
When I wrote the Redis book and the Spring Cloud ...
Preface Samba is a free software that implements ...
The most important logs in the MySQL log system a...