-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #503 from 3DStreet/streetplan-support
Streetplan support
- Loading branch information
Showing
13 changed files
with
1,039 additions
and
34 deletions.
There are no files selected for viewing
Submodule assets
updated
10 files
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* global AFRAME, THREE, XMLHttpRequest */ | ||
var streetplanUtils = require('../streetplan/streetplan-utils.js'); | ||
var exampleJSON = require('../streetplan/exampleJSON.json'); | ||
|
||
AFRAME.registerComponent('streetplan-loader', { | ||
dependencies: ['street'], | ||
schema: { | ||
streetplanStreetURL: { type: 'string' }, | ||
streetplanAPIURL: { type: 'string' }, | ||
streetplanEncJSON: { type: 'string' }, | ||
showBuildings: { default: true }, | ||
name: { default: '' } | ||
}, | ||
streetplanResponseParse: function (streetplanResponseObject) { | ||
const el = this.el; | ||
const data = this.data; | ||
const streetplanProject = streetplanResponseObject.project; | ||
|
||
// convert Streetplan structure to Streetmix-like structure | ||
const streetData = streetplanUtils.convertStreetStruct(streetplanProject); | ||
|
||
const streetplanSegments = streetData.segments; | ||
|
||
const streetplanName = streetData.name; | ||
// streetplan alternative name | ||
const streetplanAltName = streetData.altName; | ||
|
||
console.log('streetplanName', streetplanName); | ||
// el.setAttribute('streetplan-loader', 'name', streetplanName); | ||
|
||
let currentSceneTitle; | ||
const sceneEl = this.el.sceneEl; | ||
if (sceneEl && sceneEl.getAttribute('metadata')) { | ||
currentSceneTitle = sceneEl.getAttribute('metadata').sceneTitle; | ||
} | ||
if (!currentSceneTitle) { // only set title from streetplan if none exists | ||
sceneEl.setAttribute('metadata', 'sceneTitle', streetplanName); | ||
console.log('therefore setting metadata sceneTitle as streetplanName', streetplanName); | ||
} | ||
|
||
el.setAttribute('data-layer-name', 'StreetPlan • ' + streetplanName); | ||
|
||
if (data.showBuildings) { | ||
el.setAttribute('street', 'right', streetData.rightBuildingVariant); | ||
el.setAttribute('street', 'left', streetData.leftBuildingVariant); | ||
} | ||
el.setAttribute('street', 'type', 'streetmixSegmentsMetric'); | ||
// set JSON attribute last or it messes things up | ||
el.setAttribute('street', 'JSON', JSON.stringify({ streetmixSegmentsMetric: streetplanSegments })); | ||
el.emit('streetplan-loader-street-loaded'); | ||
}, | ||
update: function (oldData) { // fired at start and at each subsequent change of any schema value | ||
// This method may fire a few times when viewing a streetmix street in 3dstreet: | ||
// First to find the proper path, once to actually load the street, and then subsequent updates such as street name | ||
const that = this; | ||
const data = this.data; | ||
const el = this.el; | ||
|
||
// /* ***** debugging ***** */ | ||
// setTimeout(()=> { | ||
// this.streetplanResponseParse(exampleJSON); | ||
// }, 1000); | ||
// return; | ||
|
||
// load from URL encoded Streetplan JSON | ||
if (data.streetplanEncJSON) { | ||
const streetplanJSON = decodeURIComponent(encodedString); | ||
this.streetplanResponseParse(JSON.parse(streetplanJSON)); | ||
return; | ||
} | ||
|
||
// if the loader has run once already, and upon update neither URL has changed, do not take action | ||
if ((oldData.streetplanStreetURL === data.streetplanStreetURL) && (oldData.streetplanAPIURL === data.streetplanAPIURL)) { | ||
// console.log('[streetmix-loader]', 'Neither streetplanStreetURL nor streetplanAPIURL have changed in this component data update, not reloading street.') | ||
return; | ||
} | ||
|
||
var request = new XMLHttpRequest(); | ||
console.log('[streetplan-loader]', 'GET ' + data.streetplanAPIURL); | ||
|
||
request.open('GET', data.streetplanAPIURL, true); | ||
request.onload = function () { | ||
if (this.status >= 200 && this.status < 400) { | ||
// Connection success | ||
const streetplanResponseObject = JSON.parse(this.response); | ||
that.streetplanResponseParse(streetplanResponseObject); | ||
} else { | ||
// We reached our target server, but it returned an error | ||
console.log('[streetplan-loader]', 'Loading Error: We reached the target server, but it returned an error'); | ||
} | ||
}; | ||
request.onerror = function () { | ||
// There was a connection error of some sort | ||
console.log('[streetplan-loader]', 'Loading Error: There was a connection error of some sort'); | ||
}; | ||
request.send(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const segmentVariants = { | ||
/* sidewalk segments */ | ||
sidewalk: ['empty', 'sparse', 'normal', 'dense'], | ||
'sidewalk-wayfinding': ['large'], | ||
'sidewalk-bench': ['left', 'right', 'center'], | ||
'sidewalk-bike-rack': ['left|sidewalk-parallel', 'right|sidewalk-parallel', 'left|sidewalk', 'right|sidewalk'], | ||
'sidewalk-tree': ['big', 'palm-tree'], | ||
/* lights and utilities */ | ||
utilities: ['left', 'right'], | ||
'sidewalk-lamp': ['right|modern', 'both|modern', 'left|modern', 'right|traditional', 'both|traditional', 'left|traditional', 'right|pride', 'both|pride', 'left|pride'], | ||
// furniture segments | ||
parklet: ['left', 'right'], | ||
'outdoor-dining': ['empty|sidewalk', 'empty|road'], | ||
bikeshare: ['left|road', 'right|road', 'left|sidewalk', 'right|sidewalk'], | ||
// bike and scooter segments | ||
'bike-lane': ['inbound|green|sidewalk', 'inbound|green|road', 'outbound|green|sidewalk', 'outbound|green|road', 'inbound|regular|sidewalk', 'inbound|regular|road', 'outbound|regular|sidewalk', 'outbound|regular|road', 'inbound|red|sidewalk', 'inbound|red|road', 'outbound|red|sidewalk', 'outbound|red|road'], | ||
scooter: ['inbound|regular', 'inbound|green', 'inbound|red', 'outbound|regular', 'outbound|green', 'outbound|red'], | ||
// road segments | ||
'bus-lane': ['inbound|colored|typical', 'outbound|colored|typical', 'inbound|regular|typical', 'outbound|regular|typical', 'inbound|red|typical', 'outbound|red|typical'], | ||
'drive-lane': ['inbound|car', 'outbound|car', 'inbound|truck', 'outbound|truck', 'outbound|av', 'inbound|av', 'outbound|pedestrian', 'inbound|pedestrian', 'inbound|sharrow', 'outbound|sharrow'], | ||
'turn-lane': ['inbound|left', 'inbound|right', 'inbound|left-right-straight', 'inbound|shared', 'inbound|both', 'inbound|left-straight', 'inbound|right-straight', 'inbound|straight', 'outbound|left', 'outbound|right', 'outbound|left-right-straight', 'outbound|shared', 'outbound|both', 'outbound|left-straight', 'outbound|right-straight', 'outbound|straight'], | ||
'parking-lane': ['sideways|right', 'sideways|left', 'inbound|right', 'inbound|left', 'outbound|left', 'outbound|right', 'angled-front-left|left', 'angled-front-right|left', 'angled-rear-left|left', 'angled-rear-right|left', 'angled-front-left|right', 'angled-front-right|right', 'angled-rear-left|right', 'angled-rear-right|right'], | ||
'food-truck': ['left', 'right'], | ||
'flex-zone': ['taxi|inbound|right', 'taxi|inbound|left', 'taxi|outbound|right', 'taxi|outbound|left', 'rideshare|outbound|right', 'rideshare|outbound|right', 'rideshare|inbound|right', 'rideshare|inbound|left'], | ||
// rail vehicles | ||
streetcar: ['inbound|regular', 'inbound|colored', 'inbound|grass', 'outbound|regular', 'outbound|colored', 'outbound|grass'], | ||
'light-rail': ['inbound|regular', 'inbound|colored', 'inbound|grass', 'outbound|regular', 'outbound|colored', 'outbound|grass'], | ||
// stations | ||
'brt-station': ['center'], | ||
'transit-shelter': ['left|street-level', 'right|street-level', 'right|light-rail', 'left|light-rail'], | ||
// divider and temporary | ||
divider: ['buffer', 'flowers', 'planting-strip', 'planter-box', 'palm-tree', 'big-tree', 'bush', 'dome', 'bollard', 'striped-buffer'], | ||
temporary: ['barricade', 'traffic-cone', 'jersey-barrier-plastic', 'jersey-barrier-concrete'], | ||
// magic segment | ||
'magic-carpet': ['aladdin'] | ||
}; | ||
|
||
module.exports.segmentVariants = segmentVariants; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.