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
In order to prevent non-compliant data from enter...
I won't say much nonsense, let's just loo...
Autotrash is a command line program that automate...
The definition and inheritance of classes in JS a...
1. Environment and preparation 1. Ubuntu 14.04 2....
One port changes In version 3.2.0, the namenode p...
Many friends who have just started to make web pag...
Table of contents Preface 1. What is selenium? 2....
Comprehensive understanding of html.css overflow ...
Rownum is a unique way of writing in Oracle. In O...
Table of contents Preface About webSocket operati...
Exploiting a newly discovered sudo vulnerability ...
1. When the width of the adjacent floating layer o...
This article mainly introduces: using Vue to impl...
Previously, my boss asked me to make a program th...