ar.js - 如何将自定义图标添加到地名 AR.JS
问题描述
PNG image
我们如何在库中将 Place 图标替换为 a AR.js
?我已经阅读了这篇文章,我认为我们可以使用 aPNG image
来显示为地点图标,但我们不能用地名来做到这一点。
根据文章,这就是我们显示地点名称并使用其默认图标的方式。
// add place name
const text = document.createElement('a-link');
text.setAttribute('gps-entity-place', `latitude: ${latitude}; longitude: ${longitude};`);
text.setAttribute('title', place.name);
text.setAttribute('href', 'http://www.example.com/');
text.setAttribute('scale', '13 13 13');
text.addEventListener('loaded', () => {
window.dispatchEvent(new CustomEvent('gps-entity-place-loaded'))
});
这就是我们使用自定义图像的方式。
const icon = document.createElement('a-image');
icon.setAttribute('gps-entity-place', `latitude: ${latitude}; longitude: ${longitude};`);
icon.setAttribute('name', place.name);
icon.setAttribute('src', '../assets/map-marker.png');
解决方案
属性 gps-entity-place 是只读的。这意味着您不能使用 setAttribute 来修改它。
所以我之前的回答并没有完全回答这个问题。深入研究 AFrame 文档,我发现可以使用新实体生成 gps-projected-entity-place。但是,它需要在这里完成:https ://ar-js-org.github.io/AR.js-Docs/location-based-tutorial/#introducing-javascript-with-arjs
这意味着你应该这样做:
text.setAttribute('gps-projected-entity-place', { latitude: ${latitude}, longitude: ${longitude} });
推荐阅读
- android - 视图卡在 InputConnection 的 `commitText` 方法上
- python-3.x - 当 None 被传递时,如何将默认值应用于 python 数据类字段?
- ubuntu-18.04 - 如何在ubuntu 18.04系统上自托管网站并使用lampp服务器?
- swift - 如何将 int 转换为 tableview 单元格中的索引路径?
- azure - 逻辑应用程序 - 在 HTML 表中注入 HTML 标记
- microsoft-graph-api - 如何联系 MS Graph 的技术支持?
- regex - 如何在scala中应用正则表达式来匹配以精确给定单词开头的字符串?
- nginx - 在 GCP GKE 上使用 Nginx Ingress 处理 CONNECT 请求
- sql - 重复使用相同查询时的最佳实践
- css - 为什么一个网页在我的笔记本电脑上看起来离线响应,而当我使用 Filezilla 上传它时它不再响应?