简体   繁体   中英

Limit zoom to a 'maximum' in d3 geo tiles

When you use certain tile-sets (eg .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.

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.

  1. How would I set about limiting the zoom in function clicked that calculates the zoom-to-bounding-box?
  2. 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.

For instance in clicked you could add a line like this:

scale = Math.min(1 << 14, scale);

(based your previous scale extent of [1 << 11, 1 << 14] )

Here's the updated fiddle: https://jsfiddle.net/5Lf0w3sm/17/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM