日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > vue >内容正文

vue

Vue+Leaflet-side-by-side插件实现拉帘对比效果

發(fā)布時(shí)間:2025/3/19 vue 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Vue+Leaflet-side-by-side插件实现拉帘对比效果 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

場(chǎng)景

Vue+Leaflet實(shí)現(xiàn)加載OSM顯示地圖:

Vue+Leaflet實(shí)現(xiàn)加載OSM顯示地圖_BADAO_LIUMANG_QIZHI的博客-CSDN博客

Vue+Leaflet實(shí)現(xiàn)加載Stamen顯示地圖:

Vue+Leaflet實(shí)現(xiàn)加載Stamen顯示地圖_BADAO_LIUMANG_QIZHI的博客-CSDN博客

在上面加載顯示兩種地圖顯示的基礎(chǔ)上,怎樣實(shí)現(xiàn)兩邊對(duì)著查看,實(shí)現(xiàn)卷簾效果 。

官網(wǎng)插件說(shuō)明:

Plugins - Leaflet - a JavaScript library for interactive maps

github地址:

GitHub - digidem/leaflet-side-by-side: A Leaflet control to add a split screen to compare two map overlays

注:

博客:
BADAO_LIUMANG_QIZHI的博客_霸道流氓氣質(zhì)_CSDN博客-C#,SpringBoot,架構(gòu)之路領(lǐng)域博主
關(guān)注公眾號(hào)
霸道的程序猿
獲取編程相關(guān)電子書、教程推送與免費(fèi)下載。

實(shí)現(xiàn)

1、安裝leaflet-side-by-side插件

npm install leaflet-side-by-side --save

2、新建地圖并添加兩個(gè)圖層

?this.map = L.map('map').setView([51.505, -0.09], 13);var osmLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '&copy; <a href="OpenStreetMap<\/a'" DESIGNTIMESP=9853>OpenStreetMap<\/a'" DESIGNTIMESP=9840>http://osm.org/copyright">OpenStreetMap<\/a> contributors'}).addTo( this.map);var stamenLayer = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png', {attribution:'Map tiles by <a href="Stamen'" DESIGNTIMESP=9858>Stamen'" DESIGNTIMESP=9845>http://stamen.com">Stamen Design<\/a>, ' +'<a href="CC'" DESIGNTIMESP=9860>CC'" DESIGNTIMESP=9847>http://creativecommons.org/licenses/by/3.0">CC BY 3.0<\/a> &mdash; ' +'Map data {attribution.OpenStreetMap}',minZoom: 1,maxZoom: 16}).addTo(this.map)?

3、地圖添加到插件,插件添加到地圖

L.control.sideBySide(stamenLayer, osmLayer).addTo(this.map);

4、完整代碼

? <template><div id="map" class="map"></div> </template><script> import 'leaflet/dist/leaflet.css' import L from 'leaflet' import 'leaflet-side-by-side' export default {name: "leafletSideBySide",data() {return {map:null,};},mounted() {this.initMap();},methods: {initMap() {this.map = L.map('map').setView([51.505, -0.09], 13);var osmLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '&copy; <a href="OpenStreetMap<\/a'" DESIGNTIMESP=9890>http://osm.org/copyright">OpenStreetMap<\/a> contributors'}).addTo( this.map);var stamenLayer = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png', {attribution:'Map tiles by <a href="Stamen'" DESIGNTIMESP=9895>http://stamen.com">Stamen Design<\/a>, ' +'<a href="CC'" DESIGNTIMESP=9897>http://creativecommons.org/licenses/by/3.0">CC BY 3.0<\/a> &mdash; ' +'Map data {attribution.OpenStreetMap}',minZoom: 1,maxZoom: 16}).addTo(this.map)L.control.sideBySide(stamenLayer, osmLayer).addTo(this.map);},}, }; </script><style scoped> .map {width: 100%;height: 400px; } </style>?

總結(jié)

以上是生活随笔為你收集整理的Vue+Leaflet-side-by-side插件实现拉帘对比效果的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。