Skip to content

Commit

Permalink
support for new and old metric plan
Browse files Browse the repository at this point in the history
  • Loading branch information
Algorush committed Feb 28, 2024
1 parent a86207d commit 19eff85
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/aframe-streetmix-parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
17 changes: 14 additions & 3 deletions src/tested/streetmix-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 19eff85

Please sign in to comment.