关于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
})
相关推荐
xiaominlaopodaren1 天前
three.js最小地图运行时(一):视图状态
javascript·gis·three.js
xiaominlaopodaren3 天前
three.js地图数学基础(八):浮点精度
javascript·gis·three.js
xiaominlaopodaren4 天前
three.js地图数学基础(七):地图相机
javascript·gis·three.js
xiaominlaopodaren5 天前
three.js地图数学基础(六):齐次坐标与矩阵
javascript·gis·three.js
Being--5 天前
搭建OsgEarth验证GIS数据发布服务的Agent
gis·agent·osgearth·ai落地
xiaominlaopodaren7 天前
three.js地图数学基础(四):瓦片金字塔
javascript·gis·three.js
xiaominlaopodaren8 天前
three.js地图数学基础(三):实战墨卡托
javascript·gis·three.js
敲敲敲敲暴你脑袋9 天前
升级啦!纯前端打包下载离线地图
javascript·gis·canvas
xiaominlaopodaren9 天前
three.js地图数学基础(二):Web Mercator
javascript·gis·three.js
共享笔记12 天前
行政区边界数据哪里找?省市区县街道 GeoJSON、SHP、KML、DXF 下载与使用指南
信息可视化·gis·边界数据下载·行政区边界