Include the query when rebasing heatmap SVG refs

Some browsers seem to care about this. Close #1241.