简体   繁体   English

Shift MapBox 500px

[英]Shift MapBox 500px

I am currently working on a project which requires MapBox to be used. 我目前正在从事一个需要使用MapBox的项目。 We have a persistent sidebar which is laid over the top of the map in HTML. 我们有一个永久性的边栏,它以HTML格式放置在地图的顶部。 The sidebar is 500px wide. 边栏为500像素宽。

Everything works fine, except that when we center the map at a given co-ordinate pair, there is 500 pixels' worth of the map hidden. 一切工作正常,不同之处在于,当我们将地图以给定的坐标对为中心时,隐藏了500像素的地图。 Essentially, I am looking for a function / formula that can be used to convert the latitude position used for centering to accommodate an extra 500 pixels, at a given zoom level. 本质上,我正在寻找一个函数/公式,该函数/公式可用于转换给定缩放级别下用于居中的纬度位置,以容纳额外的500个像素。

Could anyone tell me of such an algorithm (ideally in JavaScript, but could easily be converted)? 谁能告诉我这样的算法(理想情况下是JavaScript,但可以轻松转换)? We have looked into the use node-sphericalmercator , but this doesn't quite achieve what we need. 我们已经研究了使用node-sphericalmercator的方法 ,但这并不能完全满足我们的需求。

使用L.fitBounds()padding选项对Leaflet进行此操作,或者,如果不能使用范围,请使用latLngToPoint进行转换,移动点,然后再转换回去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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