如何获取 THREE.JS 对象在地图上的坐标
使用此示例将对象加载到地图后 (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上你无法做到这一点,除非在实例化新对象
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 objectuserData
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 bethis.scene.children[2]
but it’s much better to assign to it a name and then look for it through that withthis.scene.getObjectByName