Improve park detail page by integrating map data

Refactors the park detail template to pass map coordinates and park name as data attributes to a hidden div, which is then used to initialize the park map via JavaScript.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 48ecdb60-d0f0-4b75-95c9-34e409ef35fb
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
pac7
2025-09-22 15:18:50 +00:00
parent 789d5db37a
commit 5737e5953d
2 changed files with 24 additions and 9 deletions

View File

@@ -261,12 +261,31 @@
{% if park.location.exists %}
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="{% static 'js/park-map.js' %}"></script>
<!-- Map data container -->
{% with location=park.location.first %}
{% if location.latitude and location.longitude %}
<div id="map-data"
data-latitude="{{ location.latitude|floatformat:6|default:'' }}"
data-longitude="{{ location.longitude|floatformat:6|default:'' }}"
data-park-name="{{ park.name|escapejs|default:'' }}"
style="display: none;"></div>
<script>
document.addEventListener('DOMContentLoaded', function() {
{% with location=park.location.first %}
initParkMap({{ location.latitude }}, {{ location.longitude }}, "{{ park.name }}");
{% endwith %}
});
document.addEventListener('DOMContentLoaded', function() {
var mapDataElement = document.getElementById('map-data');
if (mapDataElement) {
var latitude = parseFloat(mapDataElement.dataset.latitude);
var longitude = parseFloat(mapDataElement.dataset.longitude);
var parkName = mapDataElement.dataset.parkName;
if (!isNaN(latitude) && !isNaN(longitude) && parkName) {
initParkMap(latitude, longitude, parkName);
}
}
});
</script>
{% endif %}
{% endwith %}
{% endif %}
{% endblock %}