Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Street geo #516

Merged
merged 24 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8762bbf
add v1 street-geo component
Algorush May 15, 2024
29b8354
change example of google-tiles with new component
Algorush May 15, 2024
8620c64
add updating array maps data and lat/long
Algorush May 16, 2024
8599504
rename creating functions, add naming description
Algorush May 16, 2024
967edc1
add elevation attribute
Algorush May 17, 2024
ce66562
remove testing height value
Algorush May 17, 2024
3ae843a
change elevation in example
Algorush May 17, 2024
f289691
convert indentation to spaces
Algorush May 17, 2024
f19b4c7
remove unused function
Algorush May 17, 2024
6fa70db
add documentation
Algorush May 17, 2024
f54207c
change variable name
Algorush May 17, 2024
22f426e
add note about map libs
Algorush May 18, 2024
2f1bbe7
add browser chai test for street-geo component
Algorush May 18, 2024
84c2233
pput chai expect function in global window object
Algorush May 18, 2024
b9dd06f
move street-geo tests in a browserTests folder
Algorush May 18, 2024
2999edc
rename node test files
Algorush May 18, 2024
f50c2df
run only tests with node.js ending
Algorush May 18, 2024
5f1fbf0
use .test.js name convention for tests
Algorush May 20, 2024
57711f3
add test for street-geo with mocha and jsdom
Algorush May 20, 2024
1407151
add 2 setTimeout instead of wait for 1s
Algorush May 21, 2024
f9b4faf
remove aframe from package.json dependencies
Algorush May 21, 2024
638df85
remove street-geo.test.js
Algorush May 21, 2024
1648978
Merge branch 'main' into street-geo
kfarr May 21, 2024
6501ff3
add readme to a-frame components dir
kfarr May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions examples/google-tiles/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,11 @@
<a-entity id="rightHand" hand-controls="hand: right" blink-controls="cameraRig: #cameraRig; teleportOrigin: #camera; rotateOnTeleport:false;"></a-entity>
<a-entity id="screenshot" class="no-pause" screentock visible="false"></a-entity>
</a-entity>
<a-entity id="reference-layers" data-layer-name="Reference Layers" data-layer-show-children>
<a-entity
id="tileset"
loader-3dtiles="
url: https://tile.googleapis.com/v1/3dtiles/root.json;
lat: 37.77522354250163;
long: -122.41931773049723;
height: -16.5;
googleApiKey: AIzaSyAQshwLVKTpwTfPJxFEkEzOdP_cgmixTCQ;
geoTransform: WGS84Cartesian;
maximumSSE: 48;
maximumMem: 400;
cameraEl: #camera">
</a-entity>

<a-entity id="reference-layers" data-layer-name="Reference Layers" data-layer-show-children street-geo="
latitude: 37.77522354250163;
longitude: -122.41931773049723;
maps: google3d
" >
</a-entity>

<a-entity id="environment" data-layer-name="Environment" street-environment="preset: day;"></a-entity>
Expand Down
100 changes: 100 additions & 0 deletions src/components/street-geo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* global AFRAME, THREE */
const MAPBOX_ACCESS_TOKEN_VALUE = 'pk.eyJ1Ijoia2llcmFuZmFyciIsImEiOiJjazB0NWh2YncwOW9rM25sd2p0YTlxemk2In0.mLl4sNGDFbz_QXk0GIK02Q';
const GOOGLE_API_KEY = 'AIzaSyAQshwLVKTpwTfPJxFEkEzOdP_cgmixTCQ';


AFRAME.registerComponent('street-geo', {
schema: {
longitude: { type: 'number', default: 0 },
latitude: { type: 'number', default: 0 },
elevation: { type: 'number', default: 0 },
maps: { type: 'array', default: [] }
},

update: function (oldData) {
const data = this.data;
const el = this.el;
const mapTypes = {
// <mapName> : <function that creates and return map element>
'mapbox2d': this.createMapbox2dElement.bind(this),
'google3d': this.createGoogle3dElement.bind(this)
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapTypes could be defined in init not update

const updatedData = AFRAME.utils.diff(data, oldData);

for (const mapType in mapTypes) {
const createElementFunction = mapTypes[mapType];
// create Map element and save a link to it in this[mapType]
if (data.maps.includes(mapType) && !this[mapType]) {
this[mapType] = createElementFunction();
} else if (data.maps.includes(mapType) && (updatedData.longitude || updatedData.latitude)) {
// call update map function with name: <mapType>Update
this[mapType + 'Update'].bind(this)();
} else if (this[mapType] && !data.maps.includes(mapType)) {
// remove element from DOM and from this object
this.el.removeChild(this[mapType]);
this[mapType] = null;
}
}
},
createMapbox2dElement: function () {
const data = this.data;
const el = this.el;

const mapbox2dElement = document.createElement('a-entity');
mapbox2dElement.setAttribute('data-layer-name', 'Mapbox Satellite Streets');
mapbox2dElement.setAttribute('geometry', 'primitive: plane; width: 512; height: 512;');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a mix of spaces and tabs in the file, be sure to replace all tabs by spaces.

mapbox2dElement.setAttribute('material', 'color: #ffffff; shader: flat; side: both; transparent: true;');
//mapbox2dElement.setAttribute('position', '-7 -1 -2');
mapbox2dElement.setAttribute('rotation', '-90 -4.25 0');
mapbox2dElement.setAttribute('anisotropy', '');
mapbox2dElement.setAttribute('mapbox', {
accessToken: MAPBOX_ACCESS_TOKEN_VALUE,
center: `${data.longitude}, ${data.latitude}`,
zoom: 15,
style: 'mapbox://styles/mapbox/satellite-streets-v11',
pxToWorldRatio: 4
});
mapbox2dElement.classList.add('autocreated');
el.appendChild(mapbox2dElement);
return mapbox2dElement;
},
createGoogle3dElement: function () {
const data = this.data;
const el = this.el;

const google3dElement = document.createElement('a-entity');
google3dElement.setAttribute('data-layer-name', 'Google 3D Tiles');
google3dElement.setAttribute('loader-3dtiles', {
url: 'https://tile.googleapis.com/v1/3dtiles/root.json',
long: data.longitude,
lat: data.latitude,
height: -16.5,
googleApiKey: GOOGLE_API_KEY,
geoTransform: 'WGS84Cartesian',
maximumSSE: 48,
maximumMem: 400,
cameraEl: '#camera'
});
google3dElement.classList.add('autocreated');
el.appendChild(google3dElement);
return google3dElement;
},
google3dUpdate: function () {
const data = this.data;
this.google3d.setAttribute('loader-3dtiles', {
lat: data.latitude,
long: data.longitude
});
},
mapbox2dUpdate: function () {
const data = this.data;
this.mapbox2d.setAttribute('mapbox', {
center: `${data.longitude}, ${data.latitude}`
});

},
removeChildMaps: function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be used.

const children = this.el.querySelectorAll('.autocreated');
children.forEach(child => child.parentNode.removeChild(child));
}
});
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require('./components/create-from-json');
require('./components/screentock.js');
require('aframe-atlas-uvs-component');
require('./components/streetplan-loader');
require('./components/street-geo.js');

AFRAME.registerComponent('street', {
schema: {
Expand Down
Loading