Skip to content

Commit 9df6e1d

Browse files
Follow the selection of the wagon on the main page
1 parent be39fc9 commit 9df6e1d

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

Source/RunActivity/Viewer3D/Cameras.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,12 @@ protected override void OnActivate(bool sameCamera)
10791079
}
10801080
else if (isVisibleTrainCarViewerOrWebpage && carPosition >= 0)
10811081
{
1082-
SetCameraCar(trainCars[carPosition]);
1083-
oldCarPosition = carPosition;
1082+
if (carPosition < trainCars.Count)
1083+
{
1084+
// sometimes when decoupling cars the carPosition is out-of-range
1085+
SetCameraCar(trainCars[carPosition]);
1086+
oldCarPosition = carPosition;
1087+
}
10841088
}
10851089
else
10861090
SetCameraCar(GetCameraCars().First());

Source/RunActivity/Viewer3D/WebServices/TrainCarOperationsWebpage.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,13 @@ private void fillStatusArrowLeft(int carPosition)
428428
{
429429
string filename;
430430

431+
if (Viewer.TrainCarOperationsWindow.CarIdClicked) {
432+
// on the train operations window wagon has been clicked
433+
// wagon on webpage gets selected also
434+
TrainCarSelected = true;
435+
TrainCarSelectedPosition = Viewer.TrainCarOperationsWindow.SelectedCarPosition;
436+
}
437+
431438
if (TrainCarSelected && (carPosition == TrainCarSelectedPosition))
432439
{
433440
filename = "TrainOperationsArrowRight32.png";

Source/RunActivity/Viewer3D/WebServices/Web/TrainCarOperations/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ function handleMessage(json) {
130130
let id = "button:" + row + ":" + column;
131131
let button = document.getElementById(id);
132132
button.innerHTML = "<img src='" + json.Operations[i].Filename + "' />";
133+
if (json.Operations[i].Filename.includes("Arrow")) {
134+
if (!isInView(button)) {
135+
console.log("scrollTo");
136+
button.scrollIntoView({ behavior: "smooth" });
137+
}
138+
}
133139
button.disabled = !json.Operations[i].Enabled;
134140
button.style.cursor = json.Operations[i].Enabled ? "pointer" : "";
135141
}
@@ -157,6 +163,27 @@ function sleep(time) {
157163
return new Promise((resolve) => setTimeout(resolve, time));
158164
}
159165

166+
function isInView(el) {
167+
168+
var rect = el.getBoundingClientRect(),
169+
vWidth = window.innerWidth || document.documentElement.clientWidth,
170+
vHeight = window.innerHeight || document.documentElement.clientHeight,
171+
efp = function (x, y) { return document.elementFromPoint(x, y) };
172+
173+
// Return false if it's not in the viewport
174+
if (rect.right < 0 || rect.bottom < 0
175+
|| rect.left > vWidth || rect.top > vHeight)
176+
return false;
177+
178+
// Return true if any of its four corners are visible
179+
return (
180+
el.contains(efp(rect.left, rect.top))
181+
|| el.contains(efp(rect.right, rect.top))
182+
|| el.contains(efp(rect.right, rect.bottom))
183+
|| el.contains(efp(rect.left, rect.bottom))
184+
);
185+
}
186+
160187
//
161188
// main
162189
//

0 commit comments

Comments
 (0)