jQuery 函数返回谷歌地图缩放级别
正如 http://laudontech.com/GISBlog/?p=28 所引用的,我知道谷歌地图缩放级别的比例(以米为单位):
缩放级别 0 1:20088000.56607700 米
缩放级别 1 1:10044000.28303850 米
缩放级别 2 1:5022000.14151925 米
缩放级别 3 1:2511000.07075963 米
缩放级别 4 1:1255500.03537981 米
缩放级别 5 1:627750.01768991 米
缩放级别 6 1:313875.00884495 米
缩放级别 7 1:156937.50442248 米
缩放级别 8 1:78468.75221124 米
缩放级别 9 1:39234.37610562 米
缩放级别 10 1:19617.18805281 米
缩放级别 11 1:9808.59402640 米
缩放级别 12 1:4909.29701320 米
缩放级别 13 1:2452.14850660 米
缩放级别 14 1:1226.07425330 米
缩放级别 15 1:613.03712665 米
缩放级别 16 1:306.51856332 米
缩放级别 17 1:153.25928166 米
缩放级别 18 1:76.62964083 米
缩放级别 19 1:38.31482042 米
我想使用这些信息来创建一个像这样的函数:
function getZoomLevel(meters) {
//take input in whole meters
//return best match for zoom level as integer
}
我考虑过执行嵌套的 if else 大于/小于条件,但是没有更简化的方法吗?
as referenced at http://laudontech.com/GISBlog/?p=28, I know the scale in meters for google map zoom levels:
Zoom level 0 1:20088000.56607700 meters
Zoom level 1 1:10044000.28303850 meters
Zoom level 2 1:5022000.14151925 meters
Zoom level 3 1:2511000.07075963 meters
Zoom level 4 1:1255500.03537981 meters
Zoom level 5 1:627750.01768991 meters
Zoom level 6 1:313875.00884495 meters
Zoom level 7 1:156937.50442248 meters
Zoom level 8 1:78468.75221124 meters
Zoom level 9 1:39234.37610562 meters
Zoom level 10 1:19617.18805281 meters
Zoom level 11 1:9808.59402640 meters
Zoom level 12 1:4909.29701320 meters
Zoom level 13 1:2452.14850660 meters
Zoom level 14 1:1226.07425330 meters
Zoom level 15 1:613.03712665 meters
Zoom level 16 1:306.51856332 meters
Zoom level 17 1:153.25928166 meters
Zoom level 18 1:76.62964083 meters
Zoom level 19 1:38.31482042 meters
I want to use this information to create a function like so:
function getZoomLevel(meters) {
//take input in whole meters
//return best match for zoom level as integer
}
I've thought about doing nested if else greater/less then conditions, but isn't there a more streamlined approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
缩放级别的每次减小都意味着米数加倍,因此您不必存储每个单独的值。
您可以尝试这样做:
一旦米超过当前级别,它就会返回下一个较小的缩放级别。
或更好:
Each decrease of the zoom level means doubling the meters, so you don't have to store each individual value.
You could try this:
it returns the next smaller zoom level as soon as meters is exceeding the current level.
or better:
如果您将缩放级别存储在数组中,例如,
则迭代以获得最佳拟合。因为已知缩放级别数组正在递减,所以搜索将是
O(n)
。If you stored the zoom levels in an array, e.g.
Then iterate for a best fit. Because it is known that the zoom level array is decreasing, the search will be
O(n)
.