/** * rMaps applet definitions β€” Location Pin + Route Summary. */ import type { AppletDefinition, AppletLiveData } from "../../shared/applet-types"; const locationPin: AppletDefinition = { id: "location-pin", label: "Location Pin", icon: "πŸ“", accentColor: "#1d4ed8", ports: [ { name: "location-in", type: "json", direction: "input" }, { name: "coords-out", type: "json", direction: "output" }, ], renderCompact(data: AppletLiveData): string { const { snapshot } = data; const label = (snapshot.label as string) || "Location"; const lat = (snapshot.lat as number) || 0; const lng = (snapshot.lng as number) || 0; const hasCoords = lat !== 0 || lng !== 0; return `
πŸ“
${label}
${hasCoords ? `
${lat.toFixed(4)}, ${lng.toFixed(4)}
` : `
No coordinates
` }
`; }, onInputReceived(portName, value, ctx) { if (portName === "location-in" && value && typeof value === "object") { const loc = value as Record; ctx.emitOutput("coords-out", { lat: loc.lat, lng: loc.lng }); } }, }; const routeSummary: AppletDefinition = { id: "route-summary", label: "Route Summary", icon: "πŸ—ΊοΈ", accentColor: "#1d4ed8", ports: [ { name: "route-in", type: "json", direction: "input" }, { name: "distance-out", type: "number", direction: "output" }, ], renderCompact(data: AppletLiveData): string { const { snapshot } = data; const from = (snapshot.from as string) || "Start"; const to = (snapshot.to as string) || "End"; const distance = (snapshot.distance as string) || "β€”"; const duration = (snapshot.duration as string) || "β€”"; return `
From ${from}
To ${to}
${distance} ${duration}
`; }, onInputReceived(portName, value, ctx) { if (portName === "route-in" && value && typeof value === "object") { const route = value as Record; ctx.emitOutput("distance-out", Number(route.distanceKm) || 0); } }, }; export const mapsApplets: AppletDefinition[] = [locationPin, routeSummary];