Compare commits
No commits in common. "e1002b5315e936b3367690d1785c60d2f8013a34" and "7f73035b022113863815f3cb7a75d4e9ec30d873" have entirely different histories.
e1002b5315
...
7f73035b02
@ -92,13 +92,8 @@ class Place (models.Model):
|
|||||||
|
|
||||||
tags = TaggableManager(blank=True)
|
tags = TaggableManager(blank=True)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return reverse('place_detail', kwargs={'pk': self.pk})
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
# Get center position of LP-geocoordinates.
|
# Get center position of LP-geocoordinates.
|
||||||
def average_latlon(cls, place_list):
|
def average_latlon(place_list):
|
||||||
amount = len(place_list)
|
amount = len(place_list)
|
||||||
# Init fill values to prevent None
|
# Init fill values to prevent None
|
||||||
longitude = 0
|
longitude = 0
|
||||||
@ -108,9 +103,9 @@ class Place (models.Model):
|
|||||||
for place in place_list:
|
for place in place_list:
|
||||||
longitude += place.longitude
|
longitude += place.longitude
|
||||||
latitude += place.latitude
|
latitude += place.latitude
|
||||||
return {'latitude':latitude / amount, 'longitude': longitude / amount}
|
return (latitude / amount, longitude / amount)
|
||||||
|
|
||||||
return {'latitude': latitude, 'longitude': longitude}
|
return (latitude, longitude)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -11,20 +11,20 @@
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
view: new ol.View({
|
view: new ol.View({
|
||||||
center: ol.proj.fromLonLat([{{config.map_center.longitude}}, {{config.map_center.latitude}}]),
|
center: ol.proj.fromLonLat([{{place_map_center|last}}, {{place_map_center|first}}]),
|
||||||
zoom: 9
|
zoom: 9
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
var vectorSource = new ol.source.Vector({
|
var vectorSource = new ol.source.Vector({
|
||||||
features: [
|
features: [
|
||||||
{% for config.point in point_list %}
|
{% for place in place_list %}
|
||||||
new ol.Feature({
|
new ol.Feature({
|
||||||
geometry: new ol.geom.Point(
|
geometry: new ol.geom.Point(
|
||||||
ol.proj.fromLonLat([{{point.longitude}},{{point.latitude}}])
|
ol.proj.fromLonLat([{{place.longitude}},{{place.latitude}}])
|
||||||
),
|
),
|
||||||
url: '{{point.get_absolute_url}}',
|
url: '{% url 'place_detail' pk=place.pk %}',
|
||||||
name: '{{point.name}}'
|
name: '{{place.name}}'
|
||||||
}),
|
}),
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
]
|
]
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
<section class="LP-Section">
|
<section class="LP-Section">
|
||||||
<h1 class="LP-Headline">Map-Links</h1>
|
<h1 class="LP-Headline">Map-Links</h1>
|
||||||
{% include 'partials/osm_map.html' with config=map_config%}
|
{% include 'partials/osm_map.html' %}
|
||||||
<div class="LP-LinkList">
|
<div class="LP-LinkList">
|
||||||
<ul class="LP-LinkList__Container">
|
<ul class="LP-LinkList__Container">
|
||||||
<li class="LP-LinkList__Item"><a target="_blank" href="https://www.google.com/maps?q={{place.latitude}},{{place.longitude}}" class="LP-Link"><span class="LP-Text">Google Maps</span></a></li>
|
<li class="LP-LinkList__Item"><a target="_blank" href="https://www.google.com/maps?q={{place.latitude}},{{place.longitude}}" class="LP-Link"><span class="LP-Text">Google Maps</span></a></li>
|
||||||
|
@ -84,20 +84,12 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
|
|||||||
place_list.append(place)
|
place_list.append(place)
|
||||||
|
|
||||||
avg_latlon = Place.average_latlon(place_list)
|
avg_latlon = Place.average_latlon(place_list)
|
||||||
|
self.assertEqual(avg_latlon[0], 5.5,
|
||||||
self.assertTrue('latitude' in avg_latlon,
|
|
||||||
msg='Expecting avg_latlon dict to have an \'latitude\' key'
|
|
||||||
)
|
|
||||||
self.assertTrue('longitude' in avg_latlon,
|
|
||||||
msg='Expecting avg_latlon dict to have an \'longitude\' key'
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(avg_latlon['latitude'], 5.5,
|
|
||||||
msg='%s: average latitude missmatch' % (
|
msg='%s: average latitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(avg_latlon['longitude'], 14.5,
|
self.assertEqual(avg_latlon[1], 14.5,
|
||||||
msg='%s: average longitude missmatch' % (
|
msg='%s: average longitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
@ -110,12 +102,12 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
|
|||||||
'''
|
'''
|
||||||
place = Place.objects.get(id=1)
|
place = Place.objects.get(id=1)
|
||||||
avg_latlon = Place.average_latlon([place])
|
avg_latlon = Place.average_latlon([place])
|
||||||
self.assertEqual(avg_latlon['latitude'], place.latitude,
|
self.assertEqual(avg_latlon[0], place.latitude,
|
||||||
msg='%s:(one place) average latitude missmatch' % (
|
msg='%s:(one place) average latitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(avg_latlon['longitude'], place.longitude,
|
self.assertEqual(avg_latlon[1], place.longitude,
|
||||||
msg='%s: (one place) average longitude missmatch' % (
|
msg='%s: (one place) average longitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
@ -127,12 +119,12 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
|
|||||||
an empty list
|
an empty list
|
||||||
'''
|
'''
|
||||||
avg_latlon = Place.average_latlon([])
|
avg_latlon = Place.average_latlon([])
|
||||||
self.assertEqual(avg_latlon['latitude'], 0,
|
self.assertEqual(avg_latlon[0], 0,
|
||||||
msg='%s: (no places) average latitude missmatch' % (
|
msg='%s: (no places) average latitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(avg_latlon['longitude'], 0,
|
self.assertEqual(avg_latlon[1], 0,
|
||||||
msg='%s: a(no places) verage longitude missmatch' % (
|
msg='%s: a(no places) verage longitude missmatch' % (
|
||||||
self.model_name
|
self.model_name
|
||||||
)
|
)
|
||||||
|
@ -31,10 +31,8 @@ class PlaceDetailView(IsAuthenticated, View):
|
|||||||
place = Place.objects.get(pk=pk)
|
place = Place.objects.get(pk=pk)
|
||||||
context = {
|
context = {
|
||||||
'place': place,
|
'place': place,
|
||||||
'map_config': {
|
'place_list': [ place ],
|
||||||
'point_list': [ place ],
|
'place_map_center': [ place.latitude, place.longitude ],
|
||||||
'map_center': {'latitude': place.latitude, 'longitude': place.longitude},
|
|
||||||
},
|
|
||||||
'tagging_config': {
|
'tagging_config': {
|
||||||
'all_tags': Tag.objects.all(),
|
'all_tags': Tag.objects.all(),
|
||||||
'submit_form': TagSubmitForm(),
|
'submit_form': TagSubmitForm(),
|
||||||
|
Loading…
Reference in New Issue
Block a user