Skip to content

Commit

Permalink
Merge pull request #868 from 3DStreet/scene-id-fix
Browse files Browse the repository at this point in the history
keep scene id when loading URL
  • Loading branch information
kfarr authored Sep 27, 2024
2 parents 53d2a32 + 869b055 commit b4791bb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 39 deletions.
10 changes: 0 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,6 @@
</script>
<script>

// document.getElementById('inputfile')
// .addEventListener('change', STREET.utils.fileJSON);

// function buttonScreenshotTock() {
// const screenshotEl = document.getElementById('screenshot');
// screenshotEl.play(); // double check playing in case we're in editor mode
// screenshotEl.setAttribute('screentock', 'type', 'jpg');
// screenshotEl.setAttribute('screentock', 'takeScreenshot', true);
// }

function startEditor() {
var sceneEl = document.querySelector('a-scene');
sceneEl.components.inspector.openInspector();
Expand Down
9 changes: 0 additions & 9 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,6 @@
</script>
<script>

// document.getElementById('inputfile')
// .addEventListener('change', STREET.utils.fileJSON);

// function buttonScreenshotTock() {
// const screenshotEl = document.getElementById('screenshot');
// screenshotEl.play(); // double check playing in case we're in editor mode
// screenshotEl.setAttribute('screentock', 'type', 'jpg');
// screenshotEl.setAttribute('screentock', 'takeScreenshot', true);
// }

function startEditor() {
var sceneEl = document.querySelector('a-scene');
Expand Down
2 changes: 1 addition & 1 deletion src/editor/lib/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function fileJSON(event) {
let reader = new FileReader();

reader.onload = function () {
STREET.utils.createElementsFromJSON(reader.result);
STREET.utils.createElementsFromJSON(reader.result, true);
};

reader.readAsText(event.target.files[0]);
Expand Down
27 changes: 11 additions & 16 deletions src/json-utils_1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,13 @@ AFRAME.registerComponent('set-loader-from-hash', {
},
fetchJSON: function (requestURL) {
const request = new XMLHttpRequest();

// Prepend the base URL to the requestURL
if (window.location.href.includes('localhost')) {
const baseURL = 'https://dev-3dstreet.web.app';
requestURL = baseURL + requestURL;
}

request.open('GET', requestURL, true);
request.onload = function () {
if (this.status >= 200 && this.status < 400) {
Expand All @@ -586,7 +593,7 @@ AFRAME.registerComponent('set-loader-from-hash', {
'[set-loader-from-hash]',
'200 response received and JSON parsed, now createElementsFromJSON'
);
STREET.utils.createElementsFromJSON(jsonData);
STREET.utils.createElementsFromJSON(jsonData, false);
const sceneId = getUUIDFromPath(requestURL);
if (sceneId) {
console.log('sceneId from fetchJSON from url hash loader', sceneId);
Expand Down Expand Up @@ -660,7 +667,7 @@ function getValidJSON(stringJSON) {
.replace(/[\u0000-\u0019]+/g, ''); // eslint-disable-line no-control-regex
}

function createElementsFromJSON(streetJSON) {
function createElementsFromJSON(streetJSON, clearUrlHash) {
let streetObject = {};
if (typeof streetJSON === 'string') {
const validJSONString = getValidJSON(streetJSON);
Expand All @@ -671,7 +678,7 @@ function createElementsFromJSON(streetJSON) {

// clear scene data, create new blank scene.
// clearMetadata = true, clearUrlHash = true, addDefaultStreet = false
STREET.utils.newScene(true, true, false);
STREET.utils.newScene(true, clearUrlHash, false);

const sceneTitle = streetObject.title;
if (sceneTitle) {
Expand All @@ -682,20 +689,8 @@ function createElementsFromJSON(streetJSON) {
const streetContainerEl = document.getElementById('street-container');

createEntities(streetObject.data, streetContainerEl);
STREET.notify.successMessage('Scene loaded from JSON');
STREET.notify.successMessage('Scene loaded');
AFRAME.scenes[0].emit('newScene');
}

STREET.utils.createElementsFromJSON = createElementsFromJSON;

// handle viewer widget click to open 3dstreet json scene
function fileJSON() {
const reader = new FileReader();
reader.onload = function () {
createElementsFromJSON(reader.result);
};
reader.readAsText(this.files[0]);
}

// temporarily place the UI function in utils, which is used in index.html.
STREET.utils.fileJSON = fileJSON;
3 changes: 0 additions & 3 deletions streetplan.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@
</script>
<script>

document.getElementById('inputfile')
.addEventListener('change', STREET.utils.fileJSON);

function buttonScreenshotTock() {
const screenshotEl = document.getElementById('screenshot');
screenshotEl.play(); // double check playing in case we're in editor mode
Expand Down

0 comments on commit b4791bb

Please sign in to comment.