代码拉取完成,页面将自动刷新
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;
});
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。