defmodule AprsmeWeb.SymbolRenderer do @moduledoc """ Server-side APRS symbol rendering component. This module handles the rendering of APRS symbols using the hessu/aprs-symbols sprite files. It provides a centralized way to render symbols that can be used across all LiveView pages. """ use Phoenix.Component @doc """ Renders an APRS symbol with the correct sprite positioning. ## Examples <.symbol symbol_table="/" symbol_code="_" size={32} callsign="W1AW" /> <.symbol symbol_table="D" symbol_code="&" size={64} /> """ attr :symbol_table, :string, required: true, doc: "APRS symbol table identifier (/, \\, or overlay)" attr :symbol_code, :string, required: true, doc: "APRS symbol code character" attr :size, :integer, default: 32, doc: "Display size in pixels" attr :callsign, :string, default: nil, doc: "Optional callsign to display next to symbol" attr :class, :string, default: "", doc: "Additional CSS classes" attr :title, :string, default: nil, doc: "Optional title/tooltip text" def symbol(assigns) do # Get the sprite file and position for this symbol sprite_info = get_sprite_info(assigns.symbol_table, assigns.symbol_code) assigns = assign(assigns, sprite_file: sprite_info.sprite_file, background_position: sprite_info.background_position, background_size: sprite_info.background_size, symbol_title: assigns.title || "#{assigns.symbol_table}#{assigns.symbol_code}" ) ~H"""
<%= if @callsign do %>
{@callsign}
<% end %>
""" end @doc """ Gets sprite information for a given symbol table and code. Returns a map with sprite_file, background_position, and background_size. """ def get_sprite_info(symbol_table, symbol_code) do AprsmeWeb.AprsSymbol.get_sprite_info(symbol_table, symbol_code) end @doc """ Renders an APRS symbol for use in Leaflet markers. Returns HTML string that can be used as marker content. """ def render_marker_symbol(symbol_table, symbol_code, callsign \\ nil, size \\ 32) do AprsmeWeb.AprsSymbol.render_marker_html(symbol_table, symbol_code, callsign, size) end end