first commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static i18n i18n_tags %}
|
||||
|
||||
{% block breadcrumb %}{% include 'includes/breadcrumb.html' %}{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.css">
|
||||
<style>
|
||||
.leaflet-popup-content-wrapper { border-radius: 8px; }
|
||||
.leaflet-popup-content { margin: 12px 16px; }
|
||||
.leaflet-popup-content h6 { margin-bottom: 4px; color: var(--title-color); }
|
||||
.leaflet-popup-content p { margin-bottom: 0; color: var(--text-secondary); font-size: 0.875rem; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="section bg-white py-4">
|
||||
<div class="container">
|
||||
<div class="section-title">
|
||||
<h2>{% trans '客户分布' %}</h2>
|
||||
<p>{% trans '我们的客户遍布全国各地' %}</p>
|
||||
</div>
|
||||
<div id="customer-map"></div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const map = L.map('customer-map').setView([35.8617, 104.1954], 4);
|
||||
|
||||
L.tileLayer('https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}', {
|
||||
subdomains: ['1', '2', '3', '4'],
|
||||
attribution: '© 高德地图'
|
||||
}).addTo(map);
|
||||
|
||||
fetch("{% url 'customer_locations_api' %}")
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.locations && data.locations.length) {
|
||||
data.locations.forEach(loc => {
|
||||
const marker = L.circleMarker([loc.lat, loc.lng], {
|
||||
radius: 8,
|
||||
fillColor: loc.color || '#165DFF',
|
||||
color: '#fff',
|
||||
weight: 2,
|
||||
opacity: 1,
|
||||
fillOpacity: 0.8
|
||||
}).addTo(map);
|
||||
if (loc.name || loc.address || loc.description) {
|
||||
let popup = '';
|
||||
if (loc.name) popup += '<h6>' + loc.name + '</h6>';
|
||||
if (loc.address) popup += '<p><i class="fa fa-map-marker"></i> ' + loc.address + '</p>';
|
||||
if (loc.description) popup += '<p>' + loc.description + '</p>';
|
||||
if (popup) marker.bindPopup(popup);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user