关于leaflet maxNativeZoom不生效的问题

有这样一种场景,比如我们项目中用到天地图的服务,天地图可获取到的最高层级是18级,而我们地图希望可以缩放到20级,这样在地图应用中,地图缩放到19到20级的时候,地图会显示空白。

我们希望19到20级的时候,地图仍然显示18级的影像,看官方API,tileLayer构造函数有这样的属性maxNativeZoom ,恰好能满足我们的问题;

当我们使用这样的代码,却发现依然不能生效:

javascript 复制代码
let map = $L.map('map', {
   maxZoom:22,
})
$L.tileLayer(layerItem.url,{
   maxNativeZoom:18,
})

想要让代码生效,需要同时设置tileLayer的maxNativeZoommaxZoom属性,否则tileLayer的maxzoom会被设置默认的18。

像这样,代码就可以正常运行了:

javascript 复制代码
let map = $L.map('map', {
   maxZoom:22,
})
$L.tileLayer(layerItem.url,{
   maxNativeZoom:18,
   maxZoom: 22
})
相关推荐
一个有理想的摸鱼选手4 小时前
(四)路书Agnet-综合天气距离交通节奏等多因素来编排旅行路线
前端·后端·gis
毕安格 - BimAngle2 天前
国家电网 GIM 格式模型一键输出 3D Tiles (for Cesium) 和 glTF/glb 更新时间:2026-08-18
3d·gis·cesium·gltf·glb·3d tiles·gim
xiaominlaopodaren4 天前
three.js最小地图运行时(一):视图状态
javascript·gis·three.js
xiaominlaopodaren6 天前
three.js地图数学基础(八):浮点精度
javascript·gis·three.js
xiaominlaopodaren7 天前
three.js地图数学基础(七):地图相机
javascript·gis·three.js
xiaominlaopodaren8 天前
three.js地图数学基础(六):齐次坐标与矩阵
javascript·gis·three.js
Being--8 天前
搭建OsgEarth验证GIS数据发布服务的Agent
gis·agent·osgearth·ai落地
xiaominlaopodaren10 天前
three.js地图数学基础(四):瓦片金字塔
javascript·gis·three.js
xiaominlaopodaren12 天前
three.js地图数学基础(三):实战墨卡托
javascript·gis·three.js
敲敲敲敲暴你脑袋12 天前
升级啦!纯前端打包下载离线地图
javascript·gis·canvas