Skip to content

Commit 8d7867a

Browse files
committed
Update MyTripToCanada journey messages with user-specific identifiers and replace airplane icon with balloon
Signed-off-by: makbn <[email protected]>
1 parent 7471aa9 commit 8d7867a

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

jlmap-vaadin-demo/src/main/java/io/github/makbn/vaadin/demo/views/MyTripToCanada.java

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public class MyTripToCanada extends VerticalLayout {
6363
.iconAnchor(new JLPoint(24, 24))
6464
.build();
6565

66-
private final JLIcon RED_AIRPLANE_ICON = JLIcon.builder()
67-
.iconUrl("https://cdn-icons-png.flaticon.com/512/1077/1077903.png")
66+
private final JLIcon BALLOON = JLIcon.builder()
67+
.iconUrl("https://cdn-icons-png.flaticon.com/512/1926/1926313.png")
6868
.iconSize(new JLPoint(64, 64))
6969
.iconAnchor(new JLPoint(24, 24))
7070
.build();
@@ -227,7 +227,7 @@ private void startJourney() {
227227
log.info("Starting journey animation");
228228
resetJourney();
229229

230-
addMessage("🎬", "Journey begins! Buckle up for an adventure!", "#9C27B0");
230+
addMessage("🎬", "Journey begins! Buckle up for an adventure!", "Driver");
231231
log.info("About to animate first segment: Sari to Tehran");
232232

233233
// Step 1: Car from Sari to Tehran (3 seconds)
@@ -241,12 +241,12 @@ private void startJourney() {
241241
"Sari, Iran",
242242
"Tehran, Iran",
243243
() -> {
244-
addMessage("🚗", "Departed from beautiful Sari! Driving through scenic routes to Tehran...", "#FF5722");
244+
addMessage("🚗", "Departed from beautiful Sari! Driving through scenic routes to Tehran...", "Driver");
245245
// Step 2: Briefcase and passport (1.5 seconds)
246-
addMessage("🏙️", "Arrived in Tehran! Time to pack my bags and grab my passport!", "#FF9800");
246+
addMessage("🏙️", "Arrived in Tehran! Time to pack my bags and grab my passport!", "Driver");
247247
showTransition(TEHRAN, BRIEFCASE_ICON, 1500, () -> {
248248
// Step 3: Airplane Tehran to Doha (4 seconds)
249-
addMessage("✈️", "Taking off from Tehran! Soaring through the clouds to Doha...", "#2196F3");
249+
addMessage("✈️", "Taking off from Tehran! Soaring through the clouds to Doha...", "Qatar Airways");
250250
animateSegment(
251251
TEHRAN,
252252
DOHA,
@@ -258,10 +258,10 @@ private void startJourney() {
258258
"Doha, Qatar",
259259
() -> {
260260
// Step 4: Transit in Doha (1.5 seconds)
261-
addMessage("🛬", "Landed in Doha! Quick layover for coffee and passport check ☕", "#00BCD4");
261+
addMessage("🛬", "Landed in Doha! Quick layover for coffee and passport check ☕", "Doha Airport");
262262
showTransition(DOHA, PASSPORT_ICON, 1500, () -> {
263263
// Step 5: Airplane Doha to Montreal (5 seconds)
264-
addMessage("🌍", "Crossing the Atlantic! Long flight ahead but Canada awaits! 🇨🇦", "#2196F3");
264+
addMessage("🌍", "Crossing the Atlantic! Long flight ahead but Canada awaits! 🇨🇦", "Qatar Airways");
265265
animateSegment(
266266
DOHA,
267267
MONTREAL,
@@ -273,24 +273,24 @@ private void startJourney() {
273273
"Montreal, Canada",
274274
() -> {
275275
// Step 6: Customs in Montreal (1.5 seconds)
276-
addMessage("🍁", "Bonjour Montreal! Going through customs and immigration...", "#4CAF50");
276+
addMessage("🍁", "Bonjour Montreal! Going through customs and immigration...", "YUL Airport");
277277
showTransition(MONTREAL, DOCUMENT_ICON, 1500, () -> {
278278
// Step 7: Domestic flight to Calgary (4 seconds)
279-
addMessage("🛫", "Domestic flight time! Heading west to the Rockies!", "#E91E63");
279+
addMessage("🛫", "Domestic flight time! Heading west to the Rockies!", "Air Canada");
280280
animateSegment(
281281
MONTREAL,
282282
CALGARY,
283-
RED_AIRPLANE_ICON,
283+
BALLOON,
284284
"#E91E63",
285-
4000,
285+
8000,
286286
6,
287287
"Montreal, Canada",
288288
"Calgary, Canada",
289289
() -> {
290290
// Step 8: Arrived in Calgary
291-
addMessage("🏠", "FINALLY HOME in Calgary! What an amazing journey! 🎉", "#4CAF50");
291+
addMessage("🏠", "FINALLY HOME in Calgary! What an amazing journey! 🎉", "YYC Airport");
292292
showTransition(CALGARY, HOUSE_ICON, 2000, () -> {
293-
addMessage("🎊", "Journey complete! Time to rest and enjoy the Rockies! 🏔️", "#9C27B0");
293+
addMessage("🎊", "Journey complete! Time to mow your lawn and shovel the snow! 🏔️", "HOA manager");
294294
Notification.show("🎉 Welcome to Calgary, Canada! Journey Complete!",
295295
5000,
296296
Notification.Position.TOP_CENTER);
@@ -459,18 +459,47 @@ private JLLatLng[] createCurvedPath(JLLatLng start, JLLatLng end, int points) {
459459

460460
for (int i = 0; i < points; i++) {
461461
double t = (double) i / (points - 1);
462+
463+
// Bezier point
462464
double lat = Math.pow(1 - t, 2) * start.getLat() +
463465
2 * (1 - t) * t * control.getLat() +
464466
Math.pow(t, 2) * end.getLat();
465467
double lng = Math.pow(1 - t, 2) * start.getLng() +
466468
2 * (1 - t) * t * control.getLng() +
467469
Math.pow(t, 2) * end.getLng();
468-
path[i] = new JLLatLng(lat, lng);
470+
471+
// Bezier derivative (tangent vector)
472+
double dLat = 2 * (1 - t) * (control.getLat() - start.getLat()) +
473+
2 * t * (end.getLat() - control.getLat());
474+
double dLng = 2 * (1 - t) * (control.getLng() - start.getLng()) +
475+
2 * t * (end.getLng() - control.getLng());
476+
477+
// Perpendicular vector (normal)
478+
double normalLat = -dLng;
479+
double normalLng = dLat;
480+
481+
// Normalize the normal vector
482+
double length = Math.sqrt(normalLat * normalLat + normalLng * normalLng);
483+
if (length != 0) {
484+
normalLat /= length;
485+
normalLng /= length;
486+
}
487+
double distance = start.distanceTo(end) / 100000; // Adjust for map scale
488+
// Add a sinusoidal offset for wiggle
489+
double wiggleAmplitude = 0.2 * Math.log(distance); // Adjust amplitude
490+
double wiggleFrequency = 1.5 * Math.log(distance); // Number of wiggles along the path
491+
double wiggle = Math.sin(t * Math.PI * wiggleFrequency) * wiggleAmplitude;
492+
493+
double finalLat = lat + normalLat * wiggle;
494+
double finalLng = lng + normalLng * wiggle;
495+
496+
path[i] = new JLLatLng(finalLat, finalLng);
469497
}
470498

471499
return path;
472500
}
473501

502+
474503
private void resetJourney() {
475504
if (currentMarker != null) {
476505
currentMarker.remove();
@@ -485,12 +514,12 @@ private void resetJourney() {
485514
mapView.getControlLayer().flyTo(SARI, 4);
486515
}
487516

488-
private void addMessage(String icon, String message, String color) {
517+
private void addMessage(String icon, String message, String username) {
489518
UI.getCurrent().access(() -> {
490519
MessageListItem item = new MessageListItem(
491520
icon + " " + message,
492521
Instant.now(),
493-
"Journey Bot"
522+
username
494523
);
495524

496525
messages.add(item);

0 commit comments

Comments
 (0)