Vue+Leaflet-side-by-side插件实现拉帘对比效果
生活随笔
收集整理的這篇文章主要介紹了
Vue+Leaflet-side-by-side插件实现拉帘对比效果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景
Vue+Leaflet實現加載OSM顯示地圖:
Vue+Leaflet實現加載OSM顯示地圖_BADAO_LIUMANG_QIZHI的博客-CSDN博客
Vue+Leaflet實現加載Stamen顯示地圖:
Vue+Leaflet實現加載Stamen顯示地圖_BADAO_LIUMANG_QIZHI的博客-CSDN博客
在上面加載顯示兩種地圖顯示的基礎上,怎樣實現兩邊對著查看,實現卷簾效果 。
官網插件說明:
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的博客_霸道流氓氣質_CSDN博客-C#,SpringBoot,架構之路領域博主
關注公眾號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。
實現
1、安裝leaflet-side-by-side插件
npm install leaflet-side-by-side --save2、新建地圖并添加兩個圖層
?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: '© <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> — ' +'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: '© <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> — ' +'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>?總結
以上是生活随笔為你收集整理的Vue+Leaflet-side-by-side插件实现拉帘对比效果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vue+Leaflet实现加载Stame
- 下一篇: Leaflet中自定义marker的ic