admin管理员组文章数量:1314246
I can't understand how to get map viewport coordinates which will be right after user changes pitch and bearing
This is an example of my code - /
I use .getBounds()
method but it seems it works wrong.
After clicking on the map before user rotates it I get a right rectangle, after - something ridiculous.
Might I use coordinates wrong but it seems to me mapbox method doesn't work as expected.
I can't understand how to get map viewport coordinates which will be right after user changes pitch and bearing
This is an example of my code - https://jsfiddle/5uwdfhdp/6/
I use .getBounds()
method but it seems it works wrong.
After clicking on the map before user rotates it I get a right rectangle, after - something ridiculous.
Might I use coordinates wrong but it seems to me mapbox method doesn't work as expected.
Share Improve this question edited Dec 8, 2018 at 17:41 Cœur 38.8k26 gold badges205 silver badges277 bronze badges asked May 23, 2018 at 13:57 RantievRantiev 2,2633 gold badges38 silver badges59 bronze badges 01 Answer
Reset to default 7The problem is that when you build a rectangle with the orthogonal reflection of coordinates, you do not take into account the rotation and pitch. Try to get a geo-polygon through the pixel coordinates of the container:
const canvas = map.getCanvas()
const w = canvas.width
const h = canvas.height
const cUL = map.unproject ([0,0]).toArray()
const cUR = map.unproject ([w,0]).toArray()
const cLR = map.unproject ([w,h]).toArray()
const cLL = map.unproject ([0,h]).toArray()
const coordinates = [cUL,cUR,cLR,cLL,cUL]
const polygon = turf.polygon([coordinates])
https://jsfiddle/7vzyrx9d/
https://github./mapbox/mapbox-gl-js/issues/2375
版权声明:本文标题:javascript - How to get mapbox-gl map viewport edges coordinates considering pitch and bearing? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741965658a2407530.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论