增加地图自定义图标并显示客列表

This commit is contained in:
2026-08-03 16:01:36 +08:00
parent 841295da9e
commit 696c613b80
5 changed files with 214 additions and 30 deletions
+15 -12
View File
@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.http import JsonResponse
from .models import CustomerLocation
from django.utils.translation import get_language
from django.conf import settings
def customer_map(request):
@@ -12,19 +13,21 @@ def customer_map(request):
def customer_locations_api(request):
lang = get_language()
suffix = 'en' if lang.startswith('en') else 'zh'
locations = CustomerLocation.objects.filter(is_active=True).values(
'id', f'name_{suffix}', f'address_{suffix}', f'description_{suffix}',
'latitude', 'longitude', 'marker_color'
)
locations = CustomerLocation.objects.filter(is_active=True).order_by('sort_order', '-id')
data = []
for loc in locations:
for index, loc in enumerate(locations, start=1):
icon_url = None
if loc.marker_icon:
icon_url = settings.MEDIA_URL + str(loc.marker_icon)
data.append({
'id': loc['id'],
'name': loc[f'name_{suffix}'],
'address': loc[f'address_{suffix}'],
'description': loc[f'description_{suffix}'],
'lat': loc['latitude'],
'lng': loc['longitude'],
'color': loc['marker_color'] or '#165DFF',
'id': loc.id,
'index': index,
'name': getattr(loc, f'name_{suffix}'),
'address': getattr(loc, f'address_{suffix}'),
'description': getattr(loc, f'description_{suffix}'),
'lat': loc.latitude,
'lng': loc.longitude,
'color': loc.marker_color or '#165DFF',
'icon': icon_url,
})
return JsonResponse({'locations': data})