Refactored the logic for updating the context map and the scale bar.