def get_venues(self):
        """This function retrieves all related Venue objects for given Info
        and for each Venue gets the coordinates.

        Return a list of venues which have coordinates set.

        Each element of this list is a dictionary that contains three keys:
        location, title, description
        """
        venues = []
        refs = self.context.venue
        if not refs:
            return venues

        for ref in refs:
            ob = ref.to_object
            geo = IGeoManager(ob, None)
            if geo and geo.isGeoreferenceable():
                geometry, coordinates = geo.getCoordinates()
                if not coordinates or len(coordinates) != 2:
                    continue
                else:
                    longitude, latitude = coordinates
                if geometry == 'Point' and longitude and latitude:
                    venues.append({
                        'title':
                        ob.Title(),
                        'description':
                        DESC_TEMPLATE % ob.Description(),
                        'location':
                        "%r,%r,0.000000" % (longitude, latitude),
                    })

        return venues
示例#2
0
    def _get_markers(self, brain):
        """Return dict of marker details.

        Handle Info objects in special way.
        """
        markers = []
        if brain.portal_type == 'tbfac.Info':
            # get related Venues
            obj = brain.getObject()
            if obj is None:
                return []

            refs = obj.venue
            if not refs:
                return []

            for ref in refs:
                venue = ref.to_object
                geo = IGeoManager(venue, None)
                if geo and geo.isGeoreferenceable():
                    geometry, coordinates = geo.getCoordinates()
                    if not coordinates or len(coordinates) != 2:
                        continue
                    else:
                        longitude, latitude = coordinates
                    if geometry == 'Point' and longitude and latitude:
                        markers.append({
                            'uid': IUUID(venue),
                            'search_uid': brain.UID,
                            'url': brain.getURL(),
                            'title': brain.Title,
                            'tags': brain.Subject or [],
                            'start': brain.start or '',
                            'end': brain.end or '',
                            'geometry': {
                                'style': None,
                                'type': 'Point',
                                'coordinates': (longitude, latitude)
                            },
                            'latitude': latitude,
                            'longitude': longitude,
                        })
        else:
            markers = super(UshahidiMapView, self)._get_markers(brain)

        return markers
示例#3
0
 def apply_coordinates(self, content):
     c = self.coordinates
     if c:
         IGeoManager(content).setCoordinates(c['type'], c['coordinates'])
     else:
         IGeoManager(content).removeCoordinates()