gpt4 book ai didi

javascript - 传单:是否可以自定义缩放级别?

转载 作者:行者123 更新时间:2023-12-04 00:00:23 26 4
gpt4 key购买 nike

是否可以在使用 Stamen Toner-lite tiles 的 Leaflet map 上设置中间(2.5、3.5、4.5 等)缩放级别? ?这是我到目前为止计算缩放级别的代码:

leafletmap.on('zoomstart', function (d){
targetZoom = leafletmap.getZoom(); //Grabs whatever current zoom level is
targetZoom = targetZoom +.5; //Adds .5
leafletmap.setZoom(targetZoom); //Sets new value to zoom level
console.log(targetZoom); //Consoles out new value
});

我尝试在代码中添加 .5,但得到 too much recursion错误,所以我猜它不是那么简单。非常感谢任何帮助或指导!

最佳答案

在 1.0.0 版本中,Leaflet 引入了分数缩放:

https://leafletjs.com/examples/zoom-levels/#fractional-zoom

Before this, the zoom level of the map could be only an integer number (0, 1, 2, and so on); but now you can use fractional numbers like 1.5 or 1.25.

...

If you set the value of zoomSnap to 0.5, the valid zoom levels of the map will be 0, 0.5, 1, 1.5, 2, and so on.

If you set a value of 0.1, the valid zoom levels of the map will be 0, 0.1, 0.2, 0.3, 0.4, and so on.

The following example uses a zoomSnap value of 0.25:

var map = L.map('map', {
zoomSnap: 0.25
});

As you can see, Leaflet will only load the tiles for zoom levels 0 or 1, and will scale them as needed.

Leaflet will snap the zoom level to the closest valid one. For example, if you have zoomSnap: 0.25 and you try to do map.setZoom(0.8), the zoom will snap back to 0.75. The same happens with map.fitBounds(bounds), or when ending a pinch-zoom gesture on a touchscreen.

关于javascript - 传单:是否可以自定义缩放级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28157914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com