Skip to content

Commit

Permalink
Merge branch 'main' into add-warning-notify-option
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr committed Mar 7, 2024
2 parents a427e74 + 8c18905 commit f26c628
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 39 deletions.
4 changes: 2 additions & 2 deletions dist/aframe-street-component.js

Large diffs are not rendered by default.

File renamed without changes.
131 changes: 131 additions & 0 deletions examples/streetmix-schema28.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"id": "f00489a7-da07-4650-8dd7-4b76c8f4a303",
"namespacedId": 125,
"name": "IMPERIAL - test",
"clientUpdatedAt": "2024-02-26T22:57:13.371Z",
"data": {
"street": {
"schemaVersion": 28,
"showAnalytics": true,
"width": 80,
"id": "f00489a7-da07-4650-8dd7-4b76c8f4a303",
"namespacedId": 125,
"units": 1,
"location": null,
"userUpdated": true,
"environment": "day",
"leftBuildingHeight": 4,
"rightBuildingHeight": 3,
"leftBuildingVariant": "narrow",
"rightBuildingVariant": "wide",
"segments": [
{
"id": "7DJl8eG7PRWnkQvF12H0T",
"type": "sidewalk",
"variantString": "dense",
"width": 6,
"elevation": 1
},
{
"id": "F_Bc6Zm9ZoeSrOmH6bJbC",
"type": "sidewalk-tree",
"variantString": "big",
"width": 2,
"elevation": 1
},
{
"id": "taLFdDgMRnKObq8POF4rf",
"type": "transit-shelter",
"variantString": "left|street-level",
"width": 9,
"elevation": 1
},
{
"id": "J2arhWnwirb1Nzxf2bQq3",
"type": "sidewalk-lamp",
"variantString": "right|modern",
"width": 2,
"elevation": 1
},
{
"id": "J_lxgZv3e9sYF7ZN8xPGD",
"type": "bus-lane",
"variantString": "inbound|shared|typical",
"width": 12,
"elevation": 0
},
{
"id": "HKQf1hCl-6XgHl7k6MDWe",
"type": "drive-lane",
"variantString": "inbound|car",
"width": 9,
"elevation": 0
},
{
"id": "1kv0BPfj0dAX5O_cpxCYF",
"type": "divider",
"variantString": "bush",
"width": 3,
"elevation": 1
},
{
"id": "P8emQHdCIw4dlqpB_nVZm",
"type": "turn-lane",
"variantString": "outbound|left-straight",
"width": 10,
"elevation": 0
},
{
"id": "S4rN1jN4NGZwJDUuwnfuO",
"type": "parking-lane",
"variantString": "outbound|right",
"width": 7,
"elevation": 0
},
{
"id": "wBcMfFxSVMdcAw9hp5PZe",
"type": "divider",
"variantString": "planter-box",
"width": 4,
"elevation": 0
},
{
"id": "OnVeHlASWeNUR3aYEG5-j",
"type": "bike-lane",
"variantString": "outbound|green|road",
"width": 6,
"elevation": 0
},
{
"id": "sF2rZGZgbGsOv8k464puJ",
"type": "sidewalk-lamp",
"variantString": "left|modern",
"width": 2,
"elevation": 1
},
{
"id": "KRErzlOeyQ1p_EnEEOAJ_",
"type": "sidewalk-tree",
"variantString": "big",
"width": 2,
"elevation": 1
},
{
"id": "oNcGQG9MtYoB3N_fjfqRj",
"type": "sidewalk",
"variantString": "normal",
"width": 6,
"elevation": 1
}
],
"editCount": 2
}
},
"createdAt": "2024-02-26T22:57:00.663Z",
"updatedAt": "2024-02-26T22:57:14.093Z",
"originalStreetId": null,
"creatorId": "kfarr",
"creator": {
"id": "kfarr"
}
}
131 changes: 131 additions & 0 deletions examples/streetmix-schema30.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"id": "e81a809f-ea83-4305-821a-d7f492b477a5",
"namespacedId": 127,
"name": null,
"clientUpdatedAt": "2024-02-21T16:58:07.098Z",
"data": {
"street": {
"schemaVersion": 30,
"showAnalytics": true,
"width": 24,
"id": "e81a809f-ea83-4305-821a-d7f492b477a5",
"namespacedId": 127,
"units": 0,
"location": null,
"userUpdated": false,
"skybox": "day",
"leftBuildingHeight": 4,
"rightBuildingHeight": 3,
"leftBuildingVariant": "narrow",
"rightBuildingVariant": "wide",
"segments": [
{
"id": "4VHYS597H_ZDBm1YGkW6I",
"type": "sidewalk",
"variantString": "dense",
"width": 1.5,
"elevation": 1
},
{
"id": "I9IExckD8iAZpiBrpRA3e",
"type": "sidewalk-tree",
"variantString": "big",
"width": 0.5,
"elevation": 1
},
{
"id": "SpEJIzR_rVMvHN_d66_T0",
"type": "outdoor-dining",
"variantString": "occupied|sidewalk",
"width": 2,
"elevation": 1
},
{
"id": "JK6XXk_VS9PLUQT9it4kV",
"type": "sidewalk-lamp",
"variantString": "both|modern",
"width": 0.5,
"elevation": 1
},
{
"id": "7j_mA-OBIaRDBkImeoqB9",
"type": "drive-lane",
"variantString": "inbound|car",
"width": 3,
"elevation": 0
},
{
"id": "cFcvE0xwauxXYxxuKovh8",
"type": "divider",
"variantString": "flowers",
"width": 0.9,
"elevation": 1
},
{
"id": "qQAQ2YJe68Bk-AJrLQsnL",
"type": "turn-lane",
"variantString": "inbound|left",
"width": 3,
"elevation": 0
},
{
"id": "RV2ES5oN-l5cX6HEcuO_4",
"type": "drive-lane",
"variantString": "inbound|car",
"width": 3,
"elevation": 0
},
{
"id": "hgkP5jfxdGrbnTg-T_0kG",
"type": "brt-lane",
"variantString": "inbound|regular",
"width": 3,
"elevation": 0
},
{
"id": "FZqcZStwnCLvSHQXN9nR_",
"type": "bike-lane",
"variantString": "twoway-left|green|road",
"width": 1.7,
"elevation": 0
},
{
"id": "dOchWivQ6-DhdUgPDHLKX",
"type": "sidewalk-lamp",
"variantString": "both|traditional",
"width": 0.5,
"elevation": 1
},
{
"id": "-XZJ2Yoj4HQzublfBd33L",
"type": "sidewalk-tree",
"variantString": "big",
"width": 0.5,
"elevation": 1
},
{
"id": "CU3l7mrUVCVmz98U7OS6l",
"type": "sidewalk-wayfinding",
"variantString": "large",
"width": 0.5,
"elevation": 1
},
{
"id": "Nc3gI1apBIzMde5kUhEfb",
"type": "sidewalk",
"variantString": "dense",
"width": 1.6,
"elevation": 1
}
],
"editCount": 379
}
},
"createdAt": "2024-02-14T23:21:25.449Z",
"updatedAt": "2024-02-21T16:58:07.614Z",
"originalStreetId": "19a9d2e7-3faa-4944-bdf9-87c401c5d42f",
"creatorId": "saikofish",
"creator": {
"id": "saikofish"
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "3dstreet",
"version": "0.4.9",
"version": "0.4.11-rc.0",
"description": "Web-based 3D visualization of streets using A-Frame and WebXR",
"main": "dist/aframe-street-component.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/aframe-streetmix-parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ function createBrtStationElement () {
// offset to center the street around global x position of 0
function createCenteredStreetElement (segments) {
const streetEl = document.createElement('a-entity');
const streetWidth = streetmixUtils.calcStreetWidth(segments);
const streetWidth = segments.reduce(
(streetWidth, segmentData) => streetWidth + segmentData.width, 0);
const offset = 0 - streetWidth / 2;
streetEl.setAttribute('position', offset + ' 0 0');
return streetEl;
Expand Down Expand Up @@ -769,8 +770,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
20 changes: 12 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require('aframe-atlas-uvs-component');
AFRAME.registerComponent('street', {
schema: {
JSON: { type: 'string' },
type: { default: 'streetmixSegmentsFeet' }, // alt: sharedRowMeters, streetmixJSONResponse
type: { default: 'streetmixSegmentsMetric' }, // alt: sharedRowMeters, streetmixJSONResponse
left: { default: '' },
right: { default: '' },
showGround: { default: true },
Expand Down Expand Up @@ -49,11 +49,12 @@ AFRAME.registerComponent('street', {
buildingParent.remove();
}

const streetEl = streetmixParsers.processSegments(streetmixSegments.streetmixSegmentsFeet, data.showStriping, data.length, data.globalAnimated, data.showVehicles);
const streetEl = streetmixParsers.processSegments(streetmixSegments.streetmixSegmentsMetric, data.showStriping, data.length, data.globalAnimated, data.showVehicles);
this.el.append(streetEl);

if (data.left || data.right) {
const streetWidth = streetmixUtils.calcStreetWidth(streetmixSegments.streetmixSegmentsFeet, data.autoStriping);
const streetWidth = streetmixSegments.streetmixSegmentsMetric.reduce(
(streetWidth, segmentData) => streetWidth + segmentData.width, 0);
const buildingsEl = streetmixParsers.processBuildings(data.left, data.right, streetWidth, data.showGround, data.length);
this.el.append(buildingsEl);
}
Expand Down Expand Up @@ -100,7 +101,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,12 +121,12 @@ 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');
el.setAttribute('street', 'type', 'streetmixSegmentsMetric');
// set JSON attribute last or it messes things up
el.setAttribute('street', 'JSON', JSON.stringify({ streetmixSegmentsFeet: streetmixSegments }));
el.setAttribute('street', 'JSON', JSON.stringify({ streetmixSegmentsMetric: streetmixSegments }));
el.emit('streetmix-loader-street-loaded');
} else {
// We reached our target server, but it returned an error
Expand Down
20 changes: 11 additions & 9 deletions src/tested/streetmix-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ function streetmixAPIToUser (APIURL) { // eslint-disable-line no-unused-vars
}
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;
});
return cumulativeWidthInMeters;
// 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.calcStreetWidth = calcStreetWidth;
module.exports.convertStreetValues = convertStreetValues;
3 changes: 0 additions & 3 deletions test/approvalTest/approval-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const processSegments = app.__get__('processSegments');
// const otherApp = rewire('../../src/tested/aframe-streetmix-parsers-tested');
// app.__set__('isSidewalk', otherApp.__get__('isSidewalk')); // rewire isSidewalk

const otherApp2 = rewire('../../src/tested/streetmix-utils');
app.__set__('calcStreetWidth', otherApp2.__get__('calcStreetWidth')); // rewire calcStreetWidth

const sampleInput = `
{"id":"03923530-96d7-11ea-8f6a-5fbe8747064d","namespacedId":44,"name":"Streetmix3D All Segment Cases Test","clientUpdatedAt":"2020-05-15T18:29:04.491Z","data":{"street":{"schemaVersion":22,"width":232,"id":"03923530-96d7-11ea-8f6a-5fbe8747064d","namespacedId":44,"units":2,"location":null,"userUpdated":true,"environment":"day","leftBuildingHeight":4,"rightBuildingHeight":3,"leftBuildingVariant":"narrow","rightBuildingVariant":"wide","segments":[{"type":"sidewalk","variantString":"dense","width":6,"randSeed":36223137},{"type":"sidewalk-tree","variantString":"big","width":2},{"type":"sidewalk-wayfinding","variantString":"large","width":4},{"type":"sidewalk-bench","variantString":"left","width":4},{"type":"sidewalk-bike-rack","variantString":"right|sidewalk-parallel","width":5},{"type":"bikeshare","variantString":"left|road","width":7},{"type":"transit-shelter","variantString":"left|street-level","width":9},{"type":"sidewalk-lamp","variantString":"right|modern","width":2},{"type":"bus-lane","variantString":"inbound|shared","width":12},{"type":"turn-lane","variantString":"inbound|left","width":10},{"type":"drive-lane","variantString":"inbound|sharrow","width":10,"randSeed":102670651},{"type":"turn-lane","variantString":"inbound|right","width":10},{"type":"divider","variantString":"bush","width":2},{"type":"drive-lane","variantString":"inbound|car","width":10,"randSeed":807672430},{"type":"turn-lane","variantString":"outbound|shared","width":10},{"type":"drive-lane","variantString":"outbound|car","width":10,"randSeed":365422905},{"type":"sidewalk-lamp","variantString":"both|pride","width":4},{"type":"divider","variantString":"bush","width":3},{"type":"sidewalk-lamp","variantString":"both|traditional","width":4},{"type":"streetcar","variantString":"inbound|grass","width":12},{"type":"light-rail","variantString":"outbound|colored","width":12},{"type":"bus-lane","variantString":"outbound|colored","width":12},{"type":"sidewalk-lamp","variantString":"left|pride","width":4},{"type":"divider","variantString":"bollard","width":2},{"type":"sidewalk-lamp","variantString":"right|pride","width":4},{"type":"turn-lane","variantString":"outbound|left","width":10},{"type":"turn-lane","variantString":"outbound|left-right-straight","width":10},{"type":"turn-lane","variantString":"outbound|right","width":10},{"type":"parking-lane","variantString":"outbound|right","width":7},{"type":"scooter","variantString":"outbound|regular","width":5},{"type":"sidewalk-lamp","variantString":"both|modern","width":4},{"type":"divider","variantString":"planter-box","width":4},{"type":"bike-lane","variantString":"inbound|red|road","width":6},{"type":"bike-lane","variantString":"outbound|green|road","width":6},{"type":"sidewalk-lamp","variantString":"left|modern","width":2},{"type":"sidewalk-tree","variantString":"palm-tree","width":2},{"type":"sidewalk","variantString":"normal","width":6,"randSeed":419985576}],"editCount":61}},"createdAt":"2020-05-15T18:08:01.084Z","updatedAt":"2020-05-15T18:29:05.292Z","originalStreetId":null,"creator":{"id":"kfarr"}}
`;
Expand Down
Loading

0 comments on commit f26c628

Please sign in to comment.