Skip to content

Commit

Permalink
[#709] Updated all project maps with project update locations
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Aug 7, 2014
1 parent d5c9a3f commit 0f75761
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 30 deletions.
4 changes: 4 additions & 0 deletions akvo/rsr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,10 @@ def image_path(instance, file_name):
blank=True,
upload_to=image_path,
thumbnail={'size': (300, 225), 'options': ('autocrop', 'sharpen', )},
extra_thumbnails={
'map_thumb': {'size': (160, 120), 'options': ('autocrop', 'detail', )},
'fb_thumb': {'size': (200, 200), 'options': ('pad', )}
},
help_text=_(u'The image should have 4:3 height:width ratio for best displaying result'),
)
photo_caption = ValidXMLCharField(_(u'photo caption'), blank=True, max_length=75, help_text=_(u'75 characters'))
Expand Down
68 changes: 47 additions & 21 deletions akvo/rsr/templatetags/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ def project_map(id, width, height, dynamic='dynamic'):
locations.append([location.latitude, location.longitude])

for update_location in ProjectUpdateLocation.objects.filter(location_target__project=id):
update_locations.append([update_location.latitude, update_location.longitude])
project_update = update_location.location_target

# Small map, so don't show thumbnail of updates
thumbnail = ""

update_locations.append([update_location.latitude,
update_location.longitude,
[str(project_update.pk),project_update.title.encode('utf8'), thumbnail, 'project',
str(id)]])

template_context = {
'map_id': map_id,
Expand Down Expand Up @@ -75,7 +83,6 @@ def organisation_map(id, width, height, dynamic='dynamic'):
dynamic = False

map_id = 'akvo_map_%s' % os.urandom(8).encode('hex')
marker_icon = ORGANISATION_MARKER_ICON

locations = []

Expand All @@ -86,7 +93,7 @@ def organisation_map(id, width, height, dynamic='dynamic'):
'map_id': map_id,
'width': width,
'height': height,
'marker_icon': marker_icon,
'marker_icon': ORGANISATION_MARKER_ICON,
'locations': locations,
'dynamic': dynamic,
'infowindows': False,
Expand All @@ -108,9 +115,9 @@ def global_project_map(width, height, dynamic='dynamic'):
dynamic = False

map_id = 'akvo_map_%s' % os.urandom(8).encode('hex')
marker_icon = PROJECT_MARKER_ICON

locations = []
update_locations = []

for project in Project.objects.all().active():
try:
Expand All @@ -125,12 +132,27 @@ def global_project_map(width, height, dynamic='dynamic'):
except:
pass

for update_location in ProjectUpdateLocation.objects.filter(location_target__project=project):
project_update = update_location.location_target

try:
thumbnail = project_update.photo.extra_thumbnails['map_thumb'].absolute_url
except:
thumbnail = ""

update_locations.append([update_location.latitude,
update_location.longitude,
[str(project_update.pk), project_update.title.encode('utf8'), thumbnail, 'project',
str(project.pk)]])

template_context = {
'map_id': map_id,
'width': width,
'height': height,
'marker_icon': marker_icon,
'marker_icon': PROJECT_MARKER_ICON,
'update_marker_icon': PROJECT_UPDATE_MARKER_ICON,
'locations': locations,
'update_locations': update_locations,
'dynamic': dynamic,
'infowindows': True,
'partnersite_widget': False
Expand All @@ -151,7 +173,6 @@ def global_organisation_map(width, height, dynamic='dynamic'):
dynamic = False

map_id = 'akvo_map_%s' % os.urandom(8).encode('hex')
marker_icon = ORGANISATION_MARKER_ICON

locations = []

Expand All @@ -169,7 +190,7 @@ def global_organisation_map(width, height, dynamic='dynamic'):
'map_id': map_id,
'width': width,
'height': height,
'marker_icon': marker_icon,
'marker_icon': ORGANISATION_MARKER_ICON,
'locations': locations,
'dynamic': dynamic,
'infowindows': True,
Expand All @@ -192,9 +213,9 @@ def projects_map(projects, width, height, dynamic='dynamic'):
dynamic = False

map_id = 'akvo_map_%s' % os.urandom(8).encode('hex')
marker_icon = PROJECT_MARKER_ICON

locations = []
update_locations = []

for project in projects:
proj_locations = ProjectLocation.objects.filter(location_target=project)
Expand All @@ -203,25 +224,30 @@ def projects_map(projects, width, height, dynamic='dynamic'):
thumbnail = project.current_image.extra_thumbnails['map_thumb'].absolute_url
except:
thumbnail = ""
locations.append(
[
location.latitude,
location.longitude,
[
str(project.pk),
project.title.encode('utf8'),
thumbnail,
'project'
]
]
)
locations.append([location.latitude,
location.longitude,
[str(project.pk), project.title.encode('utf8'), thumbnail, 'project']])

for update_location in ProjectUpdateLocation.objects.filter(location_target__project=project):
project_update = update_location.location_target

try:
thumbnail = project_update.photo.extra_thumbnails['map_thumb'].absolute_url
except:
thumbnail = ""

update_locations.append([update_location.latitude,
update_location.longitude,
[str(project_update.pk), project_update.title.encode('utf8'), thumbnail, 'project', str(project.pk)]])

template_context = {
'map_id': map_id,
'width': width,
'height': height,
'marker_icon': marker_icon,
'marker_icon': PROJECT_MARKER_ICON,
'update_marker_icon': PROJECT_UPDATE_MARKER_ICON,
'locations': locations,
'update_locations': update_locations,
'dynamic': dynamic,
'infowindows': True
}
Expand Down
43 changes: 34 additions & 9 deletions akvo/templates/inclusion_tags/maps.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
'</div>';

}

window['contentString' + i] += '</div>';

(function(marker, i) {
google.maps.event.addListener(marker, 'click', function() {
infowindow = new google.maps.InfoWindow({
content: window['contentString'+i]
content: window['contentString' + i]
});
infowindow.open(map, marker);
});
Expand All @@ -61,17 +61,42 @@

// Project update locations
{% if update_locations %}
for (i = 0; i < this.update_locations.length; i++) {
var position = new google.maps.LatLng(this.update_locations[i][0], this.update_locations[i][1]);

var marker = new google.maps.Marker({
var j;

for (j = 0; j < this.update_locations.length; j++) {
var update_position = new google.maps.LatLng(this.update_locations[j][0], this.update_locations[j][1]);

var update_marker = new google.maps.Marker({
icon: '{{ update_marker_icon }}',
position: position,
map: map,
clickable: false
position: update_position,
map: map
});

bounds.extend(marker.position);
window['contentStringUpdate' + j] = '<div class="mapInfoWindow" style="overflow:hidden;">'+
'<a href="/'+this.update_locations[j][2][3]+'/'+this.update_locations[j][2][4]+'/update/'+this.update_locations[j][2][0]+'/">'+this.update_locations[j][2][1]+'</a>';

if (this.update_locations[j][2][2] != "") {
window['contentStringUpdate' + j] += '<div style="text-align: center; margin-top: 10px;">' +
'<a href="/' + this.update_locations[j][2][3] + '/' + this.update_locations[j][2][4] + '/update/' + this.update_locations[j][2][0] + '/" title="' + this.update_locations[j][2][1] + '">' +
'<img src="' + this.update_locations[j][2][2] + '" alt="">' +
'</a>' +
'</div>';

}

window['contentStringUpdate' + j] += '</div>';

(function(update_marker, j) {
google.maps.event.addListener(update_marker, 'click', function() {
infowindow = new google.maps.InfoWindow({
content: window['contentStringUpdate' + j]
});
infowindow.open(map, update_marker);
});
})(update_marker, j);

bounds.extend(update_marker.position);
};
{% endif %}

Expand Down

0 comments on commit 0f75761

Please sign in to comment.