Fix: Clean up map_iframe_single.html, remove debug overlay, ensure clean map rendering.
This commit is contained in:
@@ -28,6 +28,11 @@ def index():
|
||||
|
||||
return render_template('community/index.html', posts=posts, posts_with_routes=posts_with_routes)
|
||||
|
||||
@community.route('/test-map')
|
||||
def test_map():
|
||||
"""Test map page for debugging"""
|
||||
return render_template('community/test_map.html')
|
||||
|
||||
@community.route('/post/<int:id>')
|
||||
def post_detail(id):
|
||||
"""Individual post detail page"""
|
||||
@@ -666,47 +671,68 @@ def save_gpx_file(gpx_file, post_id):
|
||||
|
||||
@community.route('/api/routes')
|
||||
def api_routes():
|
||||
"""API endpoint to get all routes for map display"""
|
||||
posts_with_routes = Post.query.filter_by(published=True).join(GPXFile).all()
|
||||
routes_data = []
|
||||
|
||||
for post in posts_with_routes:
|
||||
for gpx_file in post.gpx_files:
|
||||
"""API endpoint to get all routes for map display - database optimized"""
|
||||
try:
|
||||
from app.utils.gpx_processor import get_all_map_routes
|
||||
|
||||
routes_data = get_all_map_routes()
|
||||
|
||||
# Add additional post information and format for frontend
|
||||
formatted_routes = []
|
||||
for route_data in routes_data:
|
||||
try:
|
||||
# Read and parse GPX file using new folder structure
|
||||
if post.media_folder:
|
||||
gpx_path = os.path.join(current_app.root_path, 'static', 'media', 'posts',
|
||||
post.media_folder, 'gpx', gpx_file.filename)
|
||||
else:
|
||||
# Fallback to old path for existing files
|
||||
gpx_path = os.path.join(current_app.instance_path, 'uploads', 'gpx', gpx_file.filename)
|
||||
|
||||
if os.path.exists(gpx_path):
|
||||
with open(gpx_path, 'r') as f:
|
||||
gpx_content = f.read()
|
||||
|
||||
gpx = gpxpy.parse(gpx_content)
|
||||
|
||||
# Extract coordinates
|
||||
coordinates = []
|
||||
for track in gpx.tracks:
|
||||
for segment in track.segments:
|
||||
for point in segment.points:
|
||||
coordinates.append([point.latitude, point.longitude])
|
||||
|
||||
if coordinates:
|
||||
routes_data.append({
|
||||
'id': post.id,
|
||||
'title': post.title,
|
||||
'author': post.author.nickname,
|
||||
'coordinates': coordinates,
|
||||
'url': url_for('community.post_detail', id=post.id)
|
||||
})
|
||||
formatted_routes.append({
|
||||
'id': route_data['post_id'],
|
||||
'title': route_data['post_title'],
|
||||
'author': route_data['post_author'],
|
||||
'coordinates': route_data['coordinates'],
|
||||
'url': url_for('community.post_detail', id=route_data['post_id']),
|
||||
'distance': route_data['stats']['distance'],
|
||||
'elevation_gain': route_data['stats']['elevation_gain'],
|
||||
'max_elevation': route_data['stats']['max_elevation'],
|
||||
'total_points': len(route_data['coordinates']),
|
||||
'start_point': route_data['start_point'],
|
||||
'end_point': route_data['end_point'],
|
||||
'bounds': route_data['bounds']
|
||||
})
|
||||
except Exception as e:
|
||||
current_app.logger.error(f'Error processing GPX file {gpx_file.filename}: {str(e)}')
|
||||
current_app.logger.error(f'Error formatting route data: {str(e)}')
|
||||
continue
|
||||
|
||||
return jsonify(routes_data)
|
||||
|
||||
return jsonify(formatted_routes)
|
||||
|
||||
except Exception as e:
|
||||
current_app.logger.error(f'Error getting map routes: {str(e)}')
|
||||
return jsonify([]) # Return empty array on error
|
||||
|
||||
|
||||
@community.route('/api/route/<int:post_id>')
|
||||
def api_route_detail(post_id):
|
||||
"""API endpoint to get detailed route data for a specific post"""
|
||||
try:
|
||||
from app.utils.gpx_processor import get_post_route_details
|
||||
|
||||
route_data = get_post_route_details(post_id)
|
||||
|
||||
if not route_data:
|
||||
return jsonify({'error': 'Route not found'}), 404
|
||||
|
||||
# Format for frontend
|
||||
formatted_route = {
|
||||
'id': route_data['post_id'],
|
||||
'coordinates': route_data['coordinates'],
|
||||
'simplified_coordinates': route_data['simplified_coordinates'],
|
||||
'start_point': route_data['start_point'],
|
||||
'end_point': route_data['end_point'],
|
||||
'bounds': route_data['bounds'],
|
||||
'stats': route_data['stats']
|
||||
}
|
||||
|
||||
return jsonify(formatted_route)
|
||||
|
||||
except Exception as e:
|
||||
current_app.logger.error(f'Error getting route details for post {post_id}: {str(e)}')
|
||||
return jsonify({'error': 'Internal server error'}), 500
|
||||
|
||||
@community.route('/media/posts/<post_folder>/images/<filename>')
|
||||
def serve_image(post_folder, filename):
|
||||
|
||||
Reference in New Issue
Block a user