Class MapPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class MapPanel extends JPanel
Custom JPanel that displays an interactive map using JXMapViewer, supporting the rendering of stops, routes, and real-time vehicle positions.
Author:
Riccardo Finocchiaro, Samuele Lombardi
See Also:
  • Constructor Details

  • Method Details

    • setClickWaypointBehaviour

      public void setClickWaypointBehaviour(WaypointBehaviour waypointBehaviour)
      Sets the behaviour for waypoint clicks, allowing custom actions when a waypoint is clicked.
      Parameters:
      waypointBehaviour - the WaypointBehaviour to set
    • repaintView

      public void repaintView()
      Repaints the map and all overlay painters, updating the display of stops, routes, and vehicle positions.
      See Also:
    • resetAction

      public void resetAction()
      Resets the map to its default state, clearing route overlays and restoring the stop view. Hides the reset button and resets the painter overlays.
      See Also:
    • renderStops

      public void renderStops(List<StopModel> stops)
      Renders the provided list of StopModel as waypoints on the map. Updates the overlay painter and saves the stops for future resets.
      Parameters:
      stops - the list of stops to display as waypoints
      See Also:
    • renderStopsRoute

      public void renderStopsRoute(List<StopModel> stops)
      Renders the provided list of StopModel as a route on the map, updating the route overlay and painter.
      Parameters:
      stops - the list of stops representing the route to display
      See Also:
    • renderVehiclePositions

      public void renderVehiclePositions(List<com.google.transit.realtime.GtfsRealtime.VehiclePosition> realtimePositions, List<StaticVehiclePosition> staticPositions)
      Renders the provided list of GtfsRealtime.VehiclePosition as real-time vehicle waypoints on the map.
      Parameters:
      realtimePositions - the list of vehicle positions to display
      staticPositions - the list of static vehicle positions to display if no
      See Also:
    • getCurrentRouteId

      public String getCurrentRouteId()
      Gets the current route ID.
      Returns:
      the current route ID
    • getCurrentStopPosition

      public org.jxmapviewer.viewer.GeoPosition getCurrentStopPosition()
      Gets the current stop position as a GeoPosition.
      Returns:
      the current stop position
    • setCurrentRouteId

      public void setCurrentRouteId(String routeId)
      Sets the current route ID and updates the map view accordingly.
      Parameters:
      routeId - the ID of the current route
    • getCurrentStopId

      public String getCurrentStopId()
      Gets the current stop ID.
      Returns:
      the current stop ID
    • setCurrentStopPosition

      public void setCurrentStopPosition(org.jxmapviewer.viewer.GeoPosition position)
      Sets the current stop position on the map.
      Parameters:
      position - the GeoPosition of the current stop
    • setCurrentStopId

      public void setCurrentStopId(String stopId)
      Sets the current stop ID and position, updating the map view accordingly.
      Parameters:
      stopId - the ID of the current stop
    • setCurrentStop

      public void setCurrentStop(String stopId, org.jxmapviewer.viewer.GeoPosition position)
      Sets the current stop ID and position, updating both the ID and position attributes.
      Parameters:
      stopId - the ID of the current stop
      position - the GeoPosition of the current stop
    • getMap

      public org.jxmapviewer.JXMapViewer getMap()
      Gets the underlying JXMapViewer instance used in this panel.
      Returns:
      the JXMapViewer instance
    • getStopPainter

      public StopPainter getStopPainter()
      Gets the StopPainter instance used for rendering stops on the map.
      Returns:
      the StopPainter instance
    • setMapPanelMapPosition

      public void setMapPanelMapPosition(org.jxmapviewer.viewer.GeoPosition geoPosition, int zoomLevel)
      Sets the map position and zoom level for the map panel.
      Parameters:
      geoPosition - the GeoPosition to set as the map center
      zoomLevel - the zoom level to set for the map
    • setZoom

      public void setZoom(int zoomLevel)
      Sets the zoom level for the map and notifies the zoom behaviour if set.
      Parameters:
      zoomLevel - the zoom level to set for the map
    • setLocalMapCache

      public void setLocalMapCache(File cacheDir)
      Sets the local cache directory for the map tile factory, allowing offline tile storage.
      Parameters:
      cacheDir - the directory to use for caching map tiles