vue使用天地圖、openlayers實(shí)現(xiàn)多個(gè)底圖疊加顯示效果
實(shí)現(xiàn)效果:
需求:根據(jù)返回的經(jīng)緯度列表通過(guò)天地圖、openlayers實(shí)現(xiàn)底圖添加(航道圖層、線圖層、水深圖層)
tk:自己申請(qǐng)的密鑰
安裝opelayers
cnpm i -S ol #或者 npm install ol
<script> // openlayers地圖 import "ol/ol.css"; import { Icon, Style, Stroke } from "ol/style"; import 'ol/ol.css' import Map from "ol/Map"; import View from "ol/View"; import TileLayer from "ol/layer/Tile"; import XYZ from "ol/source/XYZ"; import { get as getProjection } from "ol/proj.js"; import { getBottomLeft, getTopRight } from 'ol/extent.js' import { Vector as SourceVec } from 'ol/source'; import { Vector as LayerVec } from 'ol/layer'; import Overlay from "ol/Overlay";//彈窗 import {Point} from "ol/geom"; import {Feature} from "ol"; import { defaults as defaultControls } from "ol/control";//默認(rèn)縮放 import {FullScreen,ScaleLine} from "ol/control";//全屏,比例尺控件 import TileGrid from 'ol/tilegrid/TileGrid'; import { LineString, Polygon } from 'ol/geom.js' import { setTimeout } from 'timers'; import {Polyline} from "ol/format"; // import { vectorContext } from "ol/render"; import { getVectorContext } from "ol/render"; import {defaults as defaultInteractions} from 'ol/interaction';//旋轉(zhuǎn) export default { data(){ tk:"密鑰", center:{ longitude:"", latitude:"" }, map:null, }, methods:{ initMap() { let defaultsMap = { tileUrl1:"圖層地址1", tileUrl2:"圖層地址2", tileUrl3:"圖層地址3", origin: [-400, 400], zoom: 5, resolutions: [ //根據(jù)項(xiàng)目需要設(shè)置 ], fullExtent: [ //根據(jù)項(xiàng)目需要設(shè)置 ], inters: [1000, 100], center: [this.center.longitude, this.center.latitude], projection: getProjection("EPSG:4326") }; // let projection = getProjection('EPSG:4326'); // 底圖天地圖注記 cta——道路+中文注記 let baseLayer = new TileLayer({ title: "天地圖", source: new XYZ({ url:"http://t4.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=" +this.tk }), zIndex: 2 }); //天地圖路網(wǎng) let roadLayer = new TileLayer({ title: "天地圖路網(wǎng)", source: new XYZ({ projection: defaultsMap.projection, url:"http://t4.tianditu.com/DataServer?T=vec_c&x={x}&y={y}&l={z}&tk=" +this.tk }), zIndex: 1 }); // 加載地圖層mapservice let tileGrid = new TileGrid({ tileSize: 256, origin: defaultsMap.origin, extent: defaultsMap.fullExtent, resolutions: defaultsMap.resolutions }); // 航道圖層 let cjinobeaconMap = new TileLayer({ source: new XYZ({ tileGrid: tileGrid, projection: defaultsMap.projection, url: defaultsMap.tileUrl1 }), zIndex: 9 }); // 線圖層 let framesMap = new TileLayer({ source: new XYZ({ tileGrid: tileGrid, projection: defaultsMap.projection, url: defaultsMap.tileUrl2 }), zIndex: 10 }); // 水深圖層 let soundgMap = new TileLayer({ source: new XYZ({ tileGrid: tileGrid, projection: defaultsMap.projection, url: defaultsMap.tileUrl3 }), zIndex: 11 }); // 加載地圖 this.map = new Map({ target: "trajecttoryMap", controls: defaultControls().extend([ new FullScreen(), new ScaleLine({ units: "metric" }) // new ZoomSlider() ]), interactions: defaultInteractions({ pinchRotate: false // 移動(dòng)端禁止地圖旋轉(zhuǎn) }), loadTilesWhileAnimating: true, layers: [baseLayer, roadLayer, cjinobeaconMap, framesMap, soundgMap], //overlays: [this.overlay], // 把彈窗加入地圖 view: new View({ projection: defaultsMap.projection, center: defaultsMap.center, extent: defaultsMap.fullExtent, // resolutions: defaultsMap.resolutions, zoom: 14, minZoom: 7, maxZoom:17 }) }); }, }, mounted(){ this.initMap(); } } </script>
到此這篇關(guān)于vue使用天地圖、openlayers實(shí)現(xiàn)多個(gè)底圖疊加顯示的文章就介紹到這了,更多相關(guān)vue天地圖openlayers內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue3中使用reactive定義的變量響應(yīng)式丟失問(wèn)題解決方案
這篇文章主要介紹了vue3中使用reactive定義的變量響應(yīng)式丟失問(wèn)題的具體例子和解決方案,文章通過(guò)代碼示例給大家講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-06-06vue?實(shí)現(xiàn)滑動(dòng)塊解鎖示例詳解
這篇文章主要為大家介紹了vue?實(shí)現(xiàn)滑動(dòng)塊解鎖示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08關(guān)于Vue中的計(jì)算屬性和監(jiān)聽(tīng)屬性詳解
這篇文章主要介紹了關(guān)于Vue中的計(jì)算屬性和監(jiān)聽(tīng)屬性詳解,Vue.js模板內(nèi)的表達(dá)式非常便利,但是設(shè)計(jì)它們的初衷是用于簡(jiǎn)單運(yùn)算的,在模板內(nèi)放入過(guò)長(zhǎng)的或復(fù)雜的邏輯時(shí),會(huì)讓模板過(guò)重且難以維護(hù),需要的朋友可以參考下2023-05-05關(guān)于vue雙向綁定帶來(lái)的問(wèn)題及解決
這篇文章主要介紹了關(guān)于vue雙向綁定帶來(lái)的問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09Vue實(shí)現(xiàn)天氣預(yù)報(bào)小應(yīng)用
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)天氣預(yù)報(bào)小應(yīng)用,查詢一些城市的天氣情況,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08Vue登錄后添加動(dòng)態(tài)路由并跳轉(zhuǎn)的實(shí)踐分享
這篇文章講給大家詳細(xì)介紹一下Vue如何實(shí)現(xiàn)登錄后添加動(dòng)態(tài)路由并跳轉(zhuǎn),文章通過(guò)代碼示例介紹的非常詳細(xì),對(duì)我們的學(xué)習(xí)或工作有一定的的幫助,需要的朋友可以參考下2023-07-07