-
Notifications
You must be signed in to change notification settings - Fork 34
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
Street geo #516
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 29b8354
change example of google-tiles with new component
Algorush 8620c64
add updating array maps data and lat/long
Algorush 8599504
rename creating functions, add naming description
Algorush 967edc1
add elevation attribute
Algorush ce66562
remove testing height value
Algorush 3ae843a
change elevation in example
Algorush f289691
convert indentation to spaces
Algorush f19b4c7
remove unused function
Algorush 6fa70db
add documentation
Algorush f54207c
change variable name
Algorush 22f426e
add note about map libs
Algorush 2f1bbe7
add browser chai test for street-geo component
Algorush 84c2233
pput chai expect function in global window object
Algorush b9dd06f
move street-geo tests in a browserTests folder
Algorush 2999edc
rename node test files
Algorush f50c2df
run only tests with node.js ending
Algorush 5f1fbf0
use .test.js name convention for tests
Algorush 57711f3
add test for street-geo with mocha and jsdom
Algorush 1407151
add 2 setTimeout instead of wait for 1s
Algorush f9b4faf
remove aframe from package.json dependencies
Algorush 638df85
remove street-geo.test.js
Algorush 1648978
Merge branch 'main' into street-geo
kfarr 6501ff3
add readme to a-frame components dir
kfarr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,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) | ||
}; | ||
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;'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapTypes
could be defined ininit
not update