1.1 --- a/EventAggregatorSupport.py Mon May 09 00:38:13 2011 +0200
1.2 +++ b/EventAggregatorSupport.py Wed May 11 00:45:47 2011 +0200
1.3 @@ -338,6 +338,24 @@
1.4 else:
1.5 return None
1.6
1.7 +def getLocationPosition(location, locations):
1.8 +
1.9 + """
1.10 + Attempt to return the position of the given 'location' using the 'locations'
1.11 + dictionary provided. If no position can be found, return a latitude of None
1.12 + and a longitude of None.
1.13 + """
1.14 +
1.15 + latitude, longitude = None, None
1.16 +
1.17 + if location is not None:
1.18 + try:
1.19 + latitude, longitude = map(getMapReference, locations[location].split())
1.20 + except (KeyError, ValueError):
1.21 + pass
1.22 +
1.23 + return latitude, longitude
1.24 +
1.25 # Action support functions.
1.26
1.27 def getPageRevision(page):
2.1 --- a/macros/EventAggregator.py Mon May 09 00:38:13 2011 +0200
2.2 +++ b/macros/EventAggregator.py Wed May 11 00:45:47 2011 +0200
2.3 @@ -1542,18 +1542,33 @@
2.4 # Get events by position.
2.5
2.6 events_by_location = {}
2.7 + event_locations = {}
2.8
2.9 for event in all_shown_events:
2.10 event_details = event.getDetails()
2.11
2.12 location = event_details.get("location")
2.13
2.14 - # Use a normalised location if possible.
2.15 -
2.16 - location = location and getNormalisedLocation(location) or location
2.17 + if not event_locations.has_key(location):
2.18 +
2.19 + # Look up the position of a location using the locations page.
2.20 +
2.21 + latitude, longitude = getLocationPosition(location, locations)
2.22 +
2.23 + # Use a normalised location if necessary.
2.24 +
2.25 + if latitude is None and longitude is None:
2.26 + normalised_location = getNormalisedLocation(location)
2.27 + if normalised_location is not None:
2.28 + latitude, longitude = getLocationPosition(normalised_location, locations)
2.29 + if latitude is not None and longitude is not None:
2.30 + location = normalised_location
2.31 +
2.32 + event_locations[location] = latitude, longitude
2.33
2.34 if not events_by_location.has_key(location):
2.35 events_by_location[location] = []
2.36 +
2.37 events_by_location[location].append(event)
2.38
2.39 # Get the map image URL.
2.40 @@ -1578,24 +1593,14 @@
2.41 output.append(fmt.number_list(on=1))
2.42
2.43 unpositioned_events = []
2.44 - event_locations = events_by_location.keys()
2.45 + event_locations = event_locations.items()
2.46 event_locations.sort()
2.47
2.48 # Show the events in the map.
2.49
2.50 - for location in event_locations:
2.51 + for location, (latitude, longitude) in event_locations:
2.52 events = events_by_location[location]
2.53
2.54 - # Look up the position of a location using the locations page.
2.55 -
2.56 - latitude, longitude = None, None
2.57 -
2.58 - if location is not None:
2.59 - try:
2.60 - latitude, longitude = map(getMapReference, locations[location].split())
2.61 - except (KeyError, ValueError):
2.62 - pass
2.63 -
2.64 # Skip unpositioned locations and locations outside the map.
2.65
2.66 if latitude is None or longitude is None or \