From 19eff852d2a41f5725b992e6391c11e42276db5f Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Wed, 28 Feb 2024 14:58:01 -0300 Subject: [PATCH] support for new and old metric plan --- src/aframe-streetmix-parsers.js | 3 +-- src/index.js | 9 ++++++--- src/tested/streetmix-utils.js | 17 ++++++++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/aframe-streetmix-parsers.js b/src/aframe-streetmix-parsers.js index 204ed00a5..662fdfd0c 100644 --- a/src/aframe-streetmix-parsers.js +++ b/src/aframe-streetmix-parsers.js @@ -769,8 +769,7 @@ function processSegments (segments, showStriping, length, globalAnimated, showVe var segmentParentEl = document.createElement('a-entity'); segmentParentEl.classList.add('segment-parent-' + i); - var segmentWidthInFeet = segments[i].width; - var segmentWidthInMeters = segmentWidthInFeet * 0.3048; + var segmentWidthInMeters = segments[i].width; // console.log('Type: ' + segments[i].type + '; Width: ' + segmentWidthInFeet + 'ft / ' + segmentWidthInMeters + 'm'); cumulativeWidthInMeters = cumulativeWidthInMeters + segmentWidthInMeters; diff --git a/src/index.js b/src/index.js index 595b8714d..08d08e564 100644 --- a/src/index.js +++ b/src/index.js @@ -100,7 +100,10 @@ AFRAME.registerComponent('streetmix-loader', { if (this.status >= 200 && this.status < 400) { // Connection success const streetmixResponseObject = JSON.parse(this.response); - const streetmixSegments = streetmixResponseObject.data.street.segments; + // convert units of measurement if necessary + const streetData = streetmixUtils.convertStreetValues(streetmixResponseObject.data.street); + const streetmixSegments = streetData.segments; + const streetmixName = streetmixResponseObject.name; console.log('streetmixName', streetmixName); el.setAttribute('streetmix-loader', 'name', streetmixName); @@ -117,8 +120,8 @@ AFRAME.registerComponent('streetmix-loader', { el.setAttribute('data-layer-name', 'Streetmix • ' + streetmixName); if (data.showBuildings) { - el.setAttribute('street', 'right', streetmixResponseObject.data.street.rightBuildingVariant); - el.setAttribute('street', 'left', streetmixResponseObject.data.street.leftBuildingVariant); + el.setAttribute('street', 'right', streetData.rightBuildingVariant); + el.setAttribute('street', 'left', streetData.leftBuildingVariant); } el.setAttribute('street', 'type', 'streetmixSegmentsFeet'); // set JSON attribute last or it messes things up diff --git a/src/tested/streetmix-utils.js b/src/tested/streetmix-utils.js index 35f6ab29d..47753186f 100644 --- a/src/tested/streetmix-utils.js +++ b/src/tested/streetmix-utils.js @@ -51,10 +51,21 @@ module.exports.streetmixAPIToUser = streetmixAPIToUser; function calcStreetWidth (segments) { // eslint-disable-line no-unused-vars var cumulativeWidthInMeters = 0; segments.forEach((currentSegment) => { - const segmentWidthInFeet = currentSegment.width; - const segmentWidthInMeters = segmentWidthInFeet * 0.3048; - cumulativeWidthInMeters = cumulativeWidthInMeters + segmentWidthInMeters; + cumulativeWidthInMeters = cumulativeWidthInMeters + currentSegment.width; }); return cumulativeWidthInMeters; } module.exports.calcStreetWidth = calcStreetWidth; + +// convert all feet values to meters for schemaVersion < 30 +function convertStreetValues (streetData) { + if (streetData.schemaVersion < 30) { + // convert width from feet to meters + streetData.segments.forEach((segmentData) => { + segmentData.width *= 0.3048; + }) + if (streetData.width) streetData.width *= 0.3048; + } + return streetData; +} +module.exports.convertStreetValues = convertStreetValues;