How Vue creates OpenLayers components
This article is about how Vue creates OpenLayers components. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. Install the OpenLayers library
Cnpm install ol
2. Vue creates OpenLayers component effect diagram
Code import "ol/ol.css"; import Map from "ol/Map"; import OSM from "ol/source/OSM"; import TileLayer from "ol/layer/Tile"; import View from "ol/View"; export default {mounted () {this.initMap () }, methods: {initMap () {new Map ({layers: [new TileLayer ({source: new OSM ()})], target: "map" View: new View ({center: [0,0], zoom: 2})}) Console.log ("init finished");}; .map {width: 100%; height: 400px } 3. OpenLayers uses local pictures as map effects: Code import "ol/ol.css"; import ImageLayer from "ol/layer/Image"; import Map from "ol/Map"; import Projection from "ol/proj/Projection"; import Static from "ol/source/ImageStatic" Import View from "ol/View"; import {getCenter} from "ol/extent"; let extent = [0,0,338,600]; let projection = new Projection ({code: "xkcd-image", units: "pixels", extent: extent}) Export default {data () {return {map: {}};}, mounted () {this.initMap () }, methods: {initMap () {this.map = new Map ({layers: [new ImageLayer ({source: new Static ({attributions:'©xkcd') Url: "http://localhost:8080/img/123.5cba1af6.jpg", projection: projection, imageExtent: extent})})], target:" map " View: new View ({projection: projection, center: getCenter (extent), zoom: 1, maxZoom: 4, minZoom: 1})}) }; .map {width: 100%; height: 400px;} Thank you for reading! This is the end of this article on "how Vue creates OpenLayers components". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!