I am using the spy library of the tikz package in order to magnify a part of an image. However, since my image is multicolored, I would like to use a double line to improve the contrast marking the magnified area. Here is a MWE illustrating my problem:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{spy, shapes.geometric}
\begin{document}
\begin{tikzpicture}[
spy using outlines={ellipse, size=5.5cm, height=3cm, connect spies, every spy on node/.append style={double, line width=1pt}}
]
\node[anchor=south west, inner sep=0pt] (image) at (0,0)
{\includegraphics[width=.6\textwidth]{example-image-a}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\coordinate (target point) at (0.4,0.3);
\coordinate (magnified result) at (0.7,-0.5);
\spy[red, magnification=3, spy connection path={
\draw[red, double, line width=1pt] (tikzspyonnode) -- (tikzspyinnode);
}] on (target point) in node [double distance = 2pt, line width=2pt, fill=white] at (magnified result);
\end{scope}
\end{tikzpicture}
\end{document}
Here is the output that this code produces:
As you can see, the connection line appears on top of the ovals, which makes it look messy.
I would like to have the connection line under the ovals. So I modified my code as follows:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{spy, shapes.geometric}
\pgfdeclarelayer{connection}
\pgfsetlayers{connection,main} % set the order of the layers (main is the standard layer)
\begin{document}
\begin{tikzpicture}[
spy using outlines={ellipse, size=5.5cm, height=3cm, connect spies, every spy on node/.append style={double, line width=1pt}},
]
\node[anchor=south west, inner sep=0pt] (image) at (0,0)
{\includegraphics[width=.6\textwidth]{example-image-a}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\coordinate (target point) at (0.4,0.3);
\coordinate (magnified result) at (0.7,-0.5);
\spy[red, magnification=3, spy connection path={
\begin{pgfonlayer}{connection}
\draw[red, double, line width=1pt] (tikzspyonnode) -- (tikzspyinnode);
\end{pgfonlayer}
}] on (target point) in node [double distance = 2pt, line width=2pt, fill=white] at (magnified result);
\end{scope}
\end{tikzpicture}
\end{document}
This places the connection line under the ovals, however it also places it under the image.
How could I place the connection line above the image, but under the ovals? Any help would be appreciated.