Don't allow the tooltip to be positioned outside the map's bounds

It's undesirable (at least for us) to have the tooltip appear outside of the bounds of the map, which causes the tooltip to be partially hidden if the map is in an iframe. This patch prevents that by moving the tooltip to the right (or below) the mouse position if its left or top side would otherwise have a negative coordinate.