Keeping them off trees would be another story but, it just stuck me that if the map itself is relatively positioned and the moving element is absolutely positioned and located inside the element that is the map, you could just do a simple (considering the alternatives):
Code:
movingel.style.top=Math.min(Math.max(parseInt(movingel.style.top)+incrementTop, 0),map.offsetHeight)+'px'
movingel.style.left=Math.min(Math.max(parseInt(movingel.style.left)+incrementLeft, 0),map.offsetWidth)+'px'
The increments could be either positive or negative but the position would never be less than 0 (the top and left edges of the container) nor greater than the offsetHeight and offsetWidth of the container, respectively (its bottom and right edges).
Bookmarks