I am trying to use a variable with a base value, this variable is used multiple times in my code. Later when a button is clicked I want to use another value. So when the value of this variable changes things have to change as well, sort of binding.
The problem I am facing is that the variable is changing but the other methods I am using and such don't change with it because they are already used (i want them to run again when this happens). So what is the best method for this?
When something is not clear please ask for more info:) Thanks in advance guys!
var gebouwen = {
"zoneBounds": [[20,25], [30,35]],
"minZoom": 2,
"maxZoom": 5,
"bounds1": -20,
"bounds2": -20,
"bounds3": 55,
"bounds4": 65,
"boundsmap": [[0,0], [35, 45]],
"imageBuilding": 'img/building2.png'
};
var gebouw1 = {
"zoneBounds": [[30,35], [40,45]],
"minZoom": 2,
"maxZoom": 3,
"bounds1": -10,
"bounds2": -10,
"bounds3": 55,
"bounds4": 85,
"boundsmap": [[0,0], [45, 75]],
"imageBuilding": 'img/plattegrond.png'
};
var gebouw2 = {
"zoneBounds": [[30,35], [40,45]],
"minZoom": 2,
"maxZoom": 3,
"bounds1": -10,
"bounds2": -10,
"bounds3": 55,
"bounds4": 85,
"boundsmap": [[0,0], [35, 45]],
"imageBuilding": 'img/building2.png'
};
So these are the variables i use. gebouwen is the main one and if i click a button gebouwen wil equal gebouw1 and if i press the other button gebouwen will be equal to gebouw2 (gebouw = building).
<div id="building_page">
<button id="building_1" >building 1</button>
<button id="building_2" >building 2</button>
</div>
This is the HTML
var buttonBuilding1 = document.getElementById("building_1");
var buttonBuilding2 = document.getElementById("building_2");
buttonBuilding1.addEventListener("click", function() {
tabbar.style.display = "flex";
mapPage.style.display = "block";
buildingPage.style.display = "none";
gebouwen = gebouw1;
})
buttonBuilding2.addEventListener("click", function() {
tabbar.style.display = "flex";
mapPage.style.display = "block";
buildingPage.style.display = "none";
gebouwen = gebouw2;
})
for example, I use gebouwen in this variable. But when this is set and the button is clicked I want it to change as well.