如何从JSON数据文件创建新的A-FRAME对象/基元?

时间:2018-08-12 07:24:00

标签: json geocoding aframe ar.js

如何使用A-FRAME来使用Json文件中的数据并创建新的对象/基元以用作POIS?

**** EXEMPLO JSON:****(https://leafletjs.com/examples/geojson/sample-geojson.js

var lightRailStop = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "popupContent": "18th & California Light Rail Stop"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [-104.98999178409576, 39.74683938093904]
            }
        },{
            "type": "Feature",
            "properties": {
                "popupContent": "20th & Welton Light Rail Stop"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [-104.98689115047453, 39.747924136466565]
            }
        }
    ]
};

提取内容并使用每个数据创建一个新对象(a-box / a-entity)所需的javascript / html是什么,以便可以在a帧VR / AR中使用它? / p>

1 个答案:

答案 0 :(得分:0)

lightRailStop.features.forEach(stop => {
  let el = document.createElement('a-entity');
  el.setAttribute('text', 'value', stop.properties.popUpContent);
  el.object3D.position.set(parseFloat(stop.coordinates[0]), 1.6, parseFloat(stop.coordinates[1]));
  scene.appendChild(el);
});