将d3地理图块中的缩放限制为“最大" [英] Limit zoom to a 'maximum' in d3 geo tiles
问题描述
当您使用某些图块集(例如.tiles.mapbox.com/v3/mapbox.natural-earth-2/
)时,应将d3地理图块的缩放限制为最大,否则这些图块不存在,无法找到,并最终显示难看的找不到" ' 背景图像.
When you use certain tile-sets (e.g. .tiles.mapbox.com/v3/mapbox.natural-earth-2/
) the zoom on d3 geo tiles should be limited to a maximum, otherwise those tiles do not exist, cannot be found, and end up displaying an ugly 'cannot be found' background image.
我创建了小提琴(由用户Lex )向您展示我的意思.尝试单击一个小国家来复制该问题.该缩放级别不存在图块.以下两个解决方案是可以接受的.
I have created a fiddle (courtesy of user Lex) to show you exactly what I mean. Try clicking on a small country to replicate the issue. No tiles exist at that zoom level. The following two solutions would be acceptable.
- 我将如何限制缩放功能
clicked
计算缩放到边界框? - 如何修改脚本,以使功能
clicked
继续放大到可用的最详细的图块?
- How would I set about limiting the zoom in function
clicked
that calculates the zoom-to-bounding-box? - How would I amend the script such that function
clicked
continues to zoom into the most detailed tile available?
推荐答案
一种简单的方法是通过设置最大缩放比例来限制缩放.
One easy approach to this is to limit the zoom by setting a maximum scaling factor.
例如在clicked
中,您可以添加以下行:
For instance in clicked
you could add a line like this:
scale = Math.min(1 << 14, scale);
(基于您之前的[1 << 11, 1 << 14]
规模范围)
(based your previous scale extent of [1 << 11, 1 << 14]
)
这是更新的小提琴: https://jsfiddle.net/5Lf0w3sm/17/
这篇关于将d3地理图块中的缩放限制为“最大"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!