code: public void setOverlayPainter(Painter<? super JXMapViewer> overlay)
      {
          Painter<? super JXMapViewer> old = getOverlayPainter();
          this.overlay = overlay;
  
          PropertyChangeListener listener = new PropertyChangeListener()
          {
              @Override
              public void propertyChange(PropertyChangeEvent evt)
              {
                  if (evt.getNewValue().equals(Boolean.TRUE))
                  {
                      repaint();
                  }
              }
          };
  
          if (old instanceof AbstractPainter)
          {
              AbstractPainter<?> ap = (AbstractPainter<?>) old;
              ap.removePropertyChangeListener("dirty", listener);
          }
  
          if (overlay instanceof AbstractPainter)
          {
              AbstractPainter<?> ap = (AbstractPainter<?>) overlay;
              ap.addPropertyChangeListener("dirty", listener);
          }
  
          firePropertyChange("mapOverlay", old, getOverlayPainter());
          repaint();
      }
docs: Sets the map overlay. This is a {@code Painter<JXMapViewer>} which will paint on top of the map. It can be used to draw waypoints,
  lines, or static overlays like text messages.
  @param overlay the map overlay to use