diff --git a/breccia_mapper/templates/base.html b/breccia_mapper/templates/base.html
index 3ad8a89..b9bb55e 100644
--- a/breccia_mapper/templates/base.html
+++ b/breccia_mapper/templates/base.html
@@ -84,7 +84,7 @@
- Map
+ Map
diff --git a/people/static/js/map.js b/people/static/js/map.js
index 905601e..a04859e 100644
--- a/people/static/js/map.js
+++ b/people/static/js/map.js
@@ -3,7 +3,7 @@ const marker_edge_colour = 'white';
const marker_fill_colour = 'gray';
// Size of the arrow markers used on the map
-const marker_scale = 9;
+const marker_scale = 7;
// Offset for the place type icon (multiplier for marker scale)
const marker_label_offset = 0.27 * marker_scale;
// Width and transparency for the edges of the markers
@@ -13,6 +13,7 @@ const marker_edge_width = 1.0;
let map = null;
let selected_marker = null;
let selected_marker_info = null;
+let markers = [];
function createMarker(map, marker_data) {
// Get the lat-long position from the data
@@ -75,7 +76,11 @@ function initMap() {
for (const marker_data of markers_data) {
try {
const marker = createMarker(map, marker_data);
+ marker.type = marker_data.type;
+ markers.push(marker);
+
bounds.extend(marker.position);
+
if (markers_data.length === 1) {
selected_marker = marker;
}
diff --git a/people/templates/people/map.html b/people/templates/people/map.html
new file mode 100644
index 0000000..688d32e
--- /dev/null
+++ b/people/templates/people/map.html
@@ -0,0 +1,44 @@
+{% extends 'base.html' %}
+
+{% block extra_head %}
+ {{ map_markers|json_script:'map-markers' }}
+
+ {% load staticfiles %}
+
+
+
+{% endblock %}
+
+{% block content %}
+
+
+ Map
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{% endblock %}
diff --git a/people/templates/people/person/map.html b/people/templates/people/person/map.html
deleted file mode 100644
index 78c7803..0000000
--- a/people/templates/people/person/map.html
+++ /dev/null
@@ -1,28 +0,0 @@
-{% extends 'base.html' %}
-
-{% block extra_head %}
- {{ map_markers|json_script:'map-markers' }}
-
- {% load staticfiles %}
-
-
-
-{% endblock %}
-
-{% block content %}
-
-
- Map
-
-
-
-{% endblock %}
diff --git a/people/urls.py b/people/urls.py
index b61a5a7..9f26151 100644
--- a/people/urls.py
+++ b/people/urls.py
@@ -77,8 +77,8 @@ urlpatterns = [
############
# Data views
path('map',
- views.person.PersonMapView.as_view(),
- name='person.map'),
+ views.map.MapView.as_view(),
+ name='map'),
path('network',
views.network.NetworkView.as_view(),
diff --git a/people/views/__init__.py b/people/views/__init__.py
index 26a117e..353fc4a 100644
--- a/people/views/__init__.py
+++ b/people/views/__init__.py
@@ -3,6 +3,7 @@ Views for displaying or manipulating models within the `people` app.
"""
from . import (
+ map,
network,
organisation,
person,
@@ -11,6 +12,7 @@ from . import (
__all__ = [
+ 'map',
'network',
'organisation',
'person',
diff --git a/people/views/map.py b/people/views/map.py
new file mode 100644
index 0000000..cd34d5d
--- /dev/null
+++ b/people/views/map.py
@@ -0,0 +1,52 @@
+import typing
+
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.db.models import QuerySet
+from django.urls import reverse
+from django.utils import timezone
+from django.views.generic import TemplateView
+
+from people import forms, models, permissions
+
+
+def get_map_data(obj: typing.Union[models.Person, models.Organisation]) -> typing.Dict[str, typing.Any]:
+ """Prepare data to mark people or organisations on a map."""
+ answer_set = obj.current_answers
+ organisation = getattr(answer_set, 'organisation', None)
+
+ try:
+ country = answer_set.country_of_residence.name
+
+ except AttributeError:
+ country = None
+
+ return {
+ 'name': obj.name,
+ 'lat': getattr(answer_set, 'latitude', None),
+ 'lng': getattr(answer_set, 'longitude', None),
+ 'organisation': getattr(organisation, 'name', None),
+ 'org_lat': getattr(organisation, 'latitude', None),
+ 'org_lng': getattr(organisation, 'longitude', None),
+ 'country': country,
+ 'url': obj.get_absolute_url(),
+ 'type': type(obj).__name__,
+ }
+
+
+class MapView(LoginRequiredMixin, TemplateView):
+ """View displaying a map of :class:`Person` and :class:`Organisation` locations."""
+ template_name = 'people/map.html'
+
+ def get_context_data(self,
+ **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
+ context = super().get_context_data(**kwargs)
+
+ map_markers = []
+
+ map_markers.extend(
+ get_map_data(person) for person in models.Person.objects.all())
+ map_markers.extend(
+ get_map_data(org) for org in models.Organisation.objects.all())
+ context['map_markers'] = map_markers
+
+ return context
diff --git a/people/views/person.py b/people/views/person.py
index 506bcc8..7d20bb2 100644
--- a/people/views/person.py
+++ b/people/views/person.py
@@ -5,11 +5,11 @@ Views for displaying or manipulating instances of :class:`Person`.
import typing
from django.contrib.auth.mixins import LoginRequiredMixin
-from django.urls import reverse
from django.utils import timezone
from django.views.generic import CreateView, DetailView, ListView, UpdateView
from people import forms, models, permissions
+from .map import get_map_data
class PersonCreateView(LoginRequiredMixin, CreateView):
@@ -130,42 +130,3 @@ class PersonUpdateView(permissions.UserIsLinkedPersonMixin, UpdateView):
answer_set.save()
return response
-
-
-def get_map_data(person: models.Person) -> typing.Dict[str, typing.Any]:
- """Prepare data to mark people on a map."""
- answer_set = person.current_answers
- organisation = getattr(answer_set, 'organisation', None)
-
- try:
- country = answer_set.country_of_residence.name
-
- except AttributeError:
- country = None
-
- return {
- 'name': person.name,
- 'lat': getattr(answer_set, 'latitude', None),
- 'lng': getattr(answer_set, 'longitude', None),
- 'organisation': getattr(organisation, 'name', None),
- 'org_lat': getattr(organisation, 'latitude', None),
- 'org_lng': getattr(organisation, 'longitude', None),
- 'country': country,
- 'url': reverse('people:person.detail', kwargs={'pk': person.pk})
- }
-
-
-class PersonMapView(LoginRequiredMixin, ListView):
- """View displaying a map of :class:`Person` locations."""
- model = models.Person
- template_name = 'people/person/map.html'
-
- def get_context_data(self,
- **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
- context = super().get_context_data(**kwargs)
-
- context['map_markers'] = [
- get_map_data(person) for person in self.object_list
- ]
-
- return context