Moved the edge detection code into the map.