加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
wang 提交于 2023-09-04 23:28 . .
window.onload = () => {
let downloaded = false;
const el = document.querySelector("[gps-new-camera]");
el.addEventListener("gps-camera-update-position", async(e) => {
if(!downloaded) {
const west = e.detail.position.longitude - 0.05,
east = e.detail.position.longitude + 0.05,
south = e.detail.position.latitude - 0.05;
north = e.detail.position.latitude + 0.05;
const response = await fetch(`https://hikar.org/webapp/map?bbox=${west},${south},${east},${north}&layers=poi&outProj=4326`);
const pois = await response.json();
pois.features.forEach ( feature => {
const compoundEntity = document.createElement("a-entity");
compoundEntity.setAttribute('gps-new-entity-place', {
latitude: feature.geometry.coordinates[1],
longitude: feature.geometry.coordinates[0]
});
const box = document.createElement("a-box");
box.setAttribute("scale", {
x: 20,
y: 20,
z: 20
});
box.setAttribute('material', { color: 'red' } );
box.setAttribute("position", {
x : 0,
y : 20,
z: 0
} );
const text = document.createElement("a-text");
const textScale = 100;
text.setAttribute("look-at", "[gps-new-camera]");
text.setAttribute("scale", {
x: textScale,
y: textScale,
z: textScale
});
text.setAttribute("value", feature.properties.name);
text.setAttribute("align", "center");
compoundEntity.appendChild(box);
compoundEntity.appendChild(text);
document.querySelector("a-scene").appendChild(compoundEntity);
});
}
downloaded = true;
});
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化