Skip to content

Commit

Permalink
rename creating functions, add naming description
Browse files Browse the repository at this point in the history
  • Loading branch information
Algorush committed May 16, 2024
1 parent 8620c64 commit 8599504
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/components/street-geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ AFRAME.registerComponent('street-geo', {
elevation: { type: 'number', default: 0 },
maps: { type: 'array', default: [] }
},

init: function () {
/*
Function names for the given function types must have the following format:
create function: <mapType>Create,
update function: <mapType>Update,
*/
this.mapTypes = ['mapbox2d', 'google3d'];
},
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];
for (const mapType of this.mapTypes) {
// create map function with name: <mapType>Create
const createElementFunction = this[mapType + 'Create'].bind(this);
// create Map element and save a link to it in this[mapType]
if (data.maps.includes(mapType) && !this[mapType]) {
this[mapType] = createElementFunction();
Expand All @@ -36,7 +40,7 @@ AFRAME.registerComponent('street-geo', {
}
}
},
createMapbox2dElement: function () {
mapbox2dCreate: function () {
const data = this.data;
const el = this.el;

Expand All @@ -58,7 +62,7 @@ AFRAME.registerComponent('street-geo', {
el.appendChild(mapbox2dElement);
return mapbox2dElement;
},
createGoogle3dElement: function () {
google3dCreate: function () {
const data = this.data;
const el = this.el;

Expand Down

0 comments on commit 8599504

Please sign in to comment.