Google Maps API V3:绑定世界以适应区域并禁用地图重复 [英] Google Maps API V3: Bound world to fit area and disable map repeat

查看:89
本文介绍了Google Maps API V3:绑定世界以适应区域并禁用地图重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置中心:new google.maps.LatLng(0,0)将设置世界的中心。和 zoom:1 使得整个世界的默认缩放。



问题是,给定尺寸为616px×310px地图如何修改/调整地图的大小,以便它恰好适合给定的大小。例如,只有一个世界的实例被显示,地图的底部将成为非洲的底部。所以随后世界地图不会重复。准确地说我们的地图是这样绑定的:





这就是我到目前为止:

解决方案

全世界的图片在给定的缩放级别。
对于缩放级别1,它是512像素,对于缩放级别2 1024,3 = 2048,4 = 4096等等...

为了适应整个世界而没有重复它,你需要有一个地图div比这个缩放级别的整个世界的图片小,否则它将无法正常工作。



对于缩放级别1地图将需要512以适合理想,而不是更换。



https://output.jsbin.com/vabago
是一个示例,显示给定缩放级别的世界宽度并将其记录到控制台。它也调整了地图的大小,以适应整个世界,当你放大时(通常是一件愚蠢的事情,但在这里它只是表明它是如何工作的)。


$ b

HTH


Setting the center: new google.maps.LatLng(0,0) will set the center of the world. And zoom: 1 makes the default zoom to whole world.

Question is, given the size 616px by 310px of the map how can we modify/resize the map so it fits the given size nicely. For example only one instance of world gets shown and bottom of the map will be the bottom of Africa. So subsequently world map will not repeat. To be precise making our map bound like this:

This is what I have got so far:

解决方案

The 'picture' of the whole world has a constant size at a given zoom level. For zoom level 1 it's 512 pixels, for zoom level 2 1024, 3 = 2048 , 4 = 4096 etc ...

To fit the whole world without repeating it you need to have a map div that is smaller than the picture of the whole world at this zoom level, otherwise it won't work.

For zoom level 1 the map would need to 512 to fit ideally and less not to wrap.

https://output.jsbin.com/vabago is a sample that shows the world width at given zoom levels and logs it to the console. It also resizes the map to fit the whole world when you zoom in (a silly thing to do usually, but here it just shows how this works).

HTH

这篇关于Google Maps API V3:绑定世界以适应区域并禁用地图重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆