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<?>) overlay;
            ap.removePropertyChangeListener("dirty", listener);
        }

        if (overlay instanceof AbstractPainter) {
            AbstractPainter<?> ap = (AbstractPainter<?>) overlay;
            ap.addPropertyChangeListener("dirty", listener);
        }

        firePropertyChange("mapOverlay", old, getOverlayPainter());
        repaint();
    }