1.1 --- a/macros/EventAggregator.py Sun Apr 10 23:52:35 2011 +0200
1.2 +++ b/macros/EventAggregator.py Tue Apr 12 00:01:28 2011 +0200
1.3 @@ -1342,7 +1342,16 @@
1.4
1.5 if maps is not None and map_name is not None:
1.6 try:
1.7 - map_bottom_left, map_top_right, map_width, map_height, map_image = maps[map_name].split()
1.8 + map_details = maps[map_name].split()
1.9 +
1.10 + map_bottom_left_latitude, map_bottom_left_longitude, map_top_right_latitude, map_top_right_longitude = \
1.11 + map(getMapReference, map_details[:4])
1.12 + map_width, map_height = map(int, map_details[4:6])
1.13 + map_image = map_details[6]
1.14 +
1.15 + map_x_scale = map_width / (map_top_right_longitude - map_bottom_left_longitude).to_degrees()
1.16 + map_y_scale = map_height / (map_top_right_latitude - map_bottom_left_latitude).to_degrees()
1.17 +
1.18 except (KeyError, ValueError):
1.19 pass
1.20
1.21 @@ -1368,10 +1377,22 @@
1.22 _("You do not have read access to the locations page:"),
1.23 locations_page))
1.24
1.25 - # Attempt to show the image.
1.26 + # Attempt to show the map.
1.27
1.28 else:
1.29
1.30 + # Get events by position.
1.31 +
1.32 + events_by_location = {}
1.33 +
1.34 + for event in all_shown_events:
1.35 + event_details = event.getDetails()
1.36 +
1.37 + location = event_details.get("location")
1.38 + if not events_by_location.has_key(location):
1.39 + events_by_location[location] = []
1.40 + events_by_location[location].append(event)
1.41 +
1.42 # Get the map image URL.
1.43
1.44 map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request)
1.45 @@ -1385,6 +1406,65 @@
1.46 escattr(map_width), escattr(map_height), map_image_url)
1.47 ))
1.48
1.49 + # Show the events in the map.
1.50 +
1.51 + for location, events in events_by_location.items():
1.52 +
1.53 + # Look up the position of a location using the locations page.
1.54 +
1.55 + latitude, longitude = None, None
1.56 +
1.57 + if location is not None:
1.58 + try:
1.59 + latitude, longitude = map(getMapReference, locations[location].split())
1.60 + except (KeyError, ValueError):
1.61 + pass
1.62 +
1.63 + # Skip unpositioned locations or events.
1.64 +
1.65 + if latitude is None or longitude is None:
1.66 + continue
1.67 +
1.68 + # Get the position and dimensions of the map marker.
1.69 + # NOTE: Use one degree as the marker size.
1.70 +
1.71 + marker_x, marker_y = getPositionForCentrePoint(
1.72 + getPositionForReference(latitude, longitude, map_bottom_left_latitude, map_bottom_left_longitude,
1.73 + map_x_scale, map_y_scale),
1.74 + map_x_scale, map_y_scale)
1.75 +
1.76 + # Put a marker on the map.
1.77 +
1.78 + output.append(fmt.div(on=1, css_class="event-map-label",
1.79 + style="left:%dpx; bottom:%dpx; min-width:%dpx; min-height:%dpx") % (
1.80 + marker_x, marker_y, map_x_scale, map_y_scale))
1.81 + output.append(fmt.div(on=1, css_class="event-map-details"))
1.82 + output.append(fmt.div(on=1, css_class="event-map-shadow"))
1.83 + output.append(fmt.div(on=1, css_class="event-map-description"))
1.84 +
1.85 + output.append(fmt.paragraph(on=1))
1.86 + output.append(fmt.text(location))
1.87 + output.append(fmt.paragraph(on=0))
1.88 +
1.89 + output.append(fmt.bullet_list(on=1, attr={"class" : "event-map-description-events"}))
1.90 +
1.91 + for event in events:
1.92 + event_page = event.getPage()
1.93 + event_summary = event.getSummary(parent_name)
1.94 +
1.95 + # Link to the page using the summary.
1.96 +
1.97 + output.append(fmt.listitem(on=1))
1.98 + output.append(event_page.linkToPage(request, event_summary))
1.99 + output.append(fmt.listitem(on=0))
1.100 +
1.101 + output.append(fmt.bullet_list(on=0))
1.102 +
1.103 + output.append(fmt.div(on=0))
1.104 + output.append(fmt.div(on=0))
1.105 + output.append(fmt.div(on=0))
1.106 + output.append(fmt.div(on=0))
1.107 +
1.108 # End of map view output.
1.109
1.110 output.append(fmt.div(on=0))