PrefaceOpenlayer has its own extension plug-in ol-ext, which we use here to implement graphics operations: drag, rotate, zoom, stretch, move, etc., as well as its event monitoring. After all, after drawing, we need to save the data to the backend and store it in the database. Related Materials1. ol-ext official address: entrance 2. ol-ext corresponding data address: entry 3.ol-ext source code gitee address: entry 4. Openlayers latest official website: entrance 5. Openlayers official website API: entry Achieve resultsRotate, drag Figure 1: Implementation effect Figure 2: Rotation effect Figure 3: Left and right movement effect Implementation steps1. Introduce openlayers into vue npm i ol --save Attachment: npm downloads the specified version command, you can take it if you need it npm install --save-dev [email protected] 2. Introduce the openlayers extension package ol-ext into vue npm install ol-ext --save Attachment: npm downloads the specified version command, you can take it if you need it npm install --save [email protected] 3. Create a map container <template> <div id="map" class="map"></div> </template> 4. Introduce specific configuration in js, according to your specific changes, I put my own here ol related: import "ol/ol.css"; import View from "ol/View"; import Map from "ol/Map"; import TileLayer from "ol/layer/Tile"; import Overlay from "ol/Overlay"; import XYZ from "ol/source/XYZ"; import { Vector as SourceVec ,Cluster,Vector as VectorSource } from "ol/source"; import { Feature } from "ol"; import { Vector as LayerVec , Vector as VectorLayer } from "ol/layer"; import { Point, LineString, Polygon } from "ol/geom"; import { Style, Icon, Fill, Stroke, Text, Circle as CircleStyle, } from "ol/style"; import { OSM, TileArcGISRest } from "ol/source"; ol-ext related: import ExtTransform from 'ol-ext/interaction/Transform' 5. Implement the map method: data() { return { map: null, center: [116.39702518856394, 39.918590567855425], //The longitude and latitude of the Forbidden City in Beijing centerSize: 11.5, projection: "EPSG:4326", } } mounted() { this.initMap() } methods: { //Initialize the map initMap() { // Render the map var layers = [ //Dark blue background// new TileLayer({ // source: new XYZ({ // url: // "https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}", // }), // }), // Initialize background // new TileLayer({ // source: new OSM(), // }) new TileLayer({ title: "Street Map", source: new XYZ({ url: "http://localhost:8888/haoxing-map/sosomaps/roadmap/{z}/{x}/{y}.jpg", //zwh local use}), }), ]; this.map = new Map({ layers: layers, target: "map", view: new View({ center: this.center, projection: this.projection, zoom: this.centerSize, maxZoom: 17, minZoom: 8, }), }); }, 6. Add polygon data to the map mounted() { this.initMap() this.createPolygon() }, methods: { //Create a polygon createPolygon() { //Add a layer and set the point range const polygon = new Feature({ geometry: new Polygon([ [ [116.39314093500519,40.0217660530101], [116.47762344990831,39.921746523871924], [116.33244947314951,39.89892653421418], [116.30623076162784,40.00185925352143], ] ]), }) //Set style polygon.setStyle(new Style({ stroke: new Stroke({ width: 4, color: [255, 0, 0, 1], }), })) //Add the graphics to the map this.map.addLayer(new VectorLayer({ source: new VectorSource({ features: [polygon], }), })) }, } 7. Add specific operation methods and effects to the map mounted() { this.initMap() this.createPolygon() this.onEdit() }, //Operation event onEdit() { const transform = new ExtTransform({ enableRotatedTransform: false, hitTolerance: 2, translate: true, // drag stretch: false, // stretch scale: true, // scale rotate: true, // rotate translateFeature: false, noFlip: true, // layers: [], }) this.map.addInteraction(transform) //Start event transform.on(['rotatestart','translatestart'], function(e){ // Rotation let startangle = e.feature.get('angle')||0; // Translation console.log(1111); console.log(startangle); }); //Rotation transform.on('rotating', function (e) { console.log(2222); console.log("rotate: "+((e.angle*180/Math.PI -180)%360+180).toFixed(2)); console.log(e); }); //Move transform.on('translating', function (e){ console.log(3333); console.log(e.delta); console.log(e); }); //Drag event transform.on('scaling', function (e){ console.log(4444); console.log(e.scale); console.log(e); }); //Event end transform.on(['rotateend', 'translateend', 'scaleend'], function (e) { console.log(5555); }); }, This is the end of this article about Vue+Openlayer to achieve the dragging and rotation deformation effects of graphics. For more related Vue Openlayer 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 MySQL DEFINER usage
>>: Linux Operation and Maintenance Basic System Disk Management Tutorial
Copy the following code to the code area of Drea...
The operating environment of this tutorial: Windo...
MySQL is the most commonly used database. You mus...
This article example shares the specific code of ...
Table of contents Introduction Creating an Array ...
This article summarizes some common MySQL optimiz...
In most cases, MySQL does not support Chinese whe...
1. getBoundingClientRect() Analysis The getBoundi...
1. Case Take all employees who are not the head o...
2.1 Semanticization makes your web pages better u...
This article example shares the specific code of ...
Preface In the last issue, we explained LinearLay...
Specify in CSS style file #class td /*Set the tab...
Today we will introduce several ways to use CSS t...
Table of contents Preface Scope 1. What is scope?...