import L from 'leaflet';
import 'leaflet/dist/leaflet.css';
import "leaflet-side-by-side";
import config from "./config";let userconfig = {};
//左侧地图
const map = L.map("Map", {
attributionControl: false
}).setView(config.mapInitParams.center, config.mapInitParams.zoom);
//创建底图切换数据源
const baseLayer1 = L.tileLayer(config.baseMaps[0].Url,);//OSM街道图
const baseLayer2 = L.tileLayer(config.baseMaps[1].Url);//ArcGIS影像图
map.addLayer(baseLayer1);//左侧默认卷帘图层
map.addLayer(baseLayer2);//右侧默认卷帘图层
userconfig.leftLayers = [baseLayer1];
userconfig.rightLayers = [baseLayer2];
//卷帘地图效果
userconfig.sideBySide = L.control
.sideBySide(userconfig.leftLayers, userconfig.rightLayers)
.addTo(map);
//左侧下拉框改变事件
document.getElementById("selectLeftV").onchange =function(){
sideBySideChange();
}
//右侧下拉框改变事件
document.getElementById("selectRightV").onchange =function(){
sideBySideChange();
}
function sideBySideChange(){
//这个插件的左右两侧底图不能一样,否则同时只能显示一个,算是一个bug?
var leftvalue = document.getElementById("selectLeftV").value;
var rightvalue = document.getElementById("selectRightV").value;
var LeftLayer = leftvalue === "0" ? baseLayer1 : baseLayer2;
var RightLayer = rightvalue === "0" ? baseLayer2 : baseLayer1;
addLRLayers(LeftLayer,RightLayer);
userconfig.sideBySide.setLeftLayers(userconfig.leftLayers);
userconfig.sideBySide.setRightLayers(userconfig.rightLayers);
}
详细解决方案
leaflet 卷帘效果实现
热度:95 发布时间:2023-10-17 07:50:24.0
相关解决方案
- leaflet 调整 esri
- vue+leaflet 删除地图全部markers
- vue+leaflet(npm包管理)实战
- leaflet 笔记
- leaflet 添加geoserver + postgis database 发布的矢量瓦片
- react + leaflet + 天地图瓦片
- leaflet 卷帘效果实现
- leaflet 常用插件
- leaflet 插件地址大全
- leaflet api
- leaflet 添加聚合marker点
- leaflet 笔记1 marker点高亮显示
- leaflet 渲染GeoJson(中国)数据
- leaflet 控制扇形的旋转角度
- leaflet 渲染省份
- leaflet 自定义divIcon及自定义icon
- leaflet 加载geosever发布的wms 服务
- leaflet 加载高德地图
- leaflet 插件使用
- leaflet 入门基本使用
- Leaflet-学习
- 【vue@leaflet】热力图
- leaflet circle
- leaflet:入门基础(三)之加载数据
- Geoserver 发布矢量瓦片 leaflet 调用不显示
- leaflet marker单击事件函数、双击事件函数 冲突
- leaflet:入门基础(五)之结束篇