Skip to content

Commit

Permalink
show all stops in a locality on map
Browse files Browse the repository at this point in the history
  • Loading branch information
jclgoodwin committed Jun 24, 2015
1 parent 83d8893 commit af3af91
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
17 changes: 9 additions & 8 deletions busstops/static/js/map.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
(function (locations) {
(function (locations, bounds, center) {
if (locations.length && document.getElementById('map').clientWidth === 460) {
var map = L.map('map');
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
console.log(locations);

for (var i = 0; i < locations.length; i++) {
L.marker([locations[i][0], locations[i][1]]).addTo(map).bindPopup(locations[i][2]).openPopup();
}
// if (locations.length === 1) {

if (bounds && center) {
map.fitBounds(bounds).setView(center);
} else {
map.setView([locations[0][0], locations[0][1]], 17);
// } else {

// }
}
}
})(mapLocations);
})(mapOptions.locations, mapOptions.bounds || false, mapOptions.center || false);
23 changes: 15 additions & 8 deletions busstops/templates/busstops/locality_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ <h2>Stops in {{ locality }}</h2>
{% endfor %}
</ul>

{% load staticfiles %}
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script>
window.mapLocations = [{% for stop in stops %}[{{ stop.location }}, '{{ stop }}'],{% endfor %}];
</script>
<script src="{% static 'js/map.js' %}"></script>
</script>
{% if stops %}
{% load staticfiles %}
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script>
window.mapOptions = {
locations: [{% for stop in stops %}[{{ stop.location }}, '{{ stop }}'],{% endfor %}],
bounds: [[{{ max_latitude }}, {{ max_longitude }}],
[{{ min_latitude }}, {{ min_longitude }}]],
center: [{{ mid_latitude }}, {{ mid_longitude }}]
};
</script>
<script src="{% static 'js/map.js' %}?2"></script>
</script>
{% endif %}

{% include 'footer.html' %}
6 changes: 4 additions & 2 deletions busstops/templates/busstops/stoppoint_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ <h2>Stops nearby</h2>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script>
window.mapLocations = [[{{ stoppoint.location }}, '{{ stoppoint }}']];
window.mapOptions = {
locations: [[{{ stoppoint.location }}, '{{ stoppoint }}']]
};
</script>
<script src="{% static 'js/map.js' %}"></script>
<script src="{% static 'js/map.js' %}?2"></script>

{% include 'footer.html' %}

0 comments on commit af3af91

Please sign in to comment.