如何获取 THREE.JS 对象在地图上的坐标

发布于 2025-01-13 21:21:50 字数 206 浏览 1 评论 0原文

使用此示例将对象加载到地图后 (https: //docs.mapbox.com/mapbox-gl-js/example/add-3d-model/),如何检索对象的坐标?我想在物体移动时设置中心。

After loaded an object to a map using this example (https://docs.mapbox.com/mapbox-gl-js/example/add-3d-model/), how can you retrieve the object's coordinate back? I want to set the centre when the object moves.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他夏了夏天 2025-01-20 21:21:50

基本上你无法做到这一点,除非在实例化新对象 userData 时以及将其添加到场景之前将 modelAsMercatorCooperative 指定为新对象中的变量。
要在代码的任何其他部分找到它,您需要循环 this.scene.children 并在该集合中找到该对象,考虑到还添加了 2 个灯光,它将是 < code>this.scene.children[2] 但最好为其分配一个名称,然后使用 this.scene.getObjectByName 通过该名称查找它

Basically you cannot do it, unless you assign modelAsMercatorCoordinate as a variable in the new object userData when it’s instantiated and before it’s added into the scene.
To find it in any other part of the code, you’ll need to loop over this.scene.children and find the object in that collection, considering there are also 2 lights added, it will be this.scene.children[2] but it’s much better to assign to it a name and then look for it through that with this.scene.getObjectByName

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文