コード例 #1
0
 def cluster_tooltip(cluster, r_list):
     cluster_rids = [
         r_list[point.id] for point in cluster['points']
     ]
     pins = [
         getObjectFromCatalog(catalog, rid) for rid in cluster_rids
     ]
     return self.cluster_index(pins=pins)
コード例 #2
0
ファイル: GeoMapTool.py プロジェクト: eaudeweb/Naaya-legacy
    def _search_geo_clusters(self, filters):
        """
        Returns all the clusters that match the specified criteria.
        This does not check for the 180/-180 meridian in the map
        """
        # unpack map limits
        if filters:
            lat_min = float(filters[0]['geo_latitude']['query'][0])
            lat_max = float(filters[0]['geo_latitude']['query'][1])

            lon_min = float(filters[0]['geo_longitude']['query'][0])
            lon_max = float(filters[0]['geo_longitude']['query'][1])
        else:  # this should not happen
            return [], []

        # preparing for the call to the catalog
        catalog_tool = self.getCatalogTool()

        # call the improved cluster_catalog function for getting the clusters
        centers, groups = clusters_catalog.getClusters(catalog_tool, filters)

        # transform centers to Geo
        centers = map(lambda c: Geo(str(c.lat), str(c.lon)), centers)

        cluster_obs, single_obs = [], []
        for i in range(len(centers)):
            if len(groups[i]) < 10:
                # from this const on we actually return clusters
                for so in groups[i]:
                    sobject = clusters_catalog.getObjectFromCatalog(
                        catalog_tool, so)

                    # do not display it if it is not in the actual map
                    if (Decimal(str(lat_min)) < sobject.geo_location.lat <
                            Decimal(str(lat_max))):
                        if (Decimal(str(lon_min)) < sobject.geo_location.lon <
                                Decimal(str(lon_max))):
                            single_obs.append(sobject)
            else:
                if (Decimal(str(lat_min)) < centers[i].lat <
                        Decimal(str(lat_max))):
                    if (Decimal(str(lon_min)) < centers[i].lon <
                            Decimal(str(lon_max))):
                        group_paths = [
                            clusters_catalog.getObjectPathFromCatalog(
                                catalog_tool, rid)
                            for rid in groups[i]]
                        cluster_obs.append((centers[i], group_paths))

        return cluster_obs, single_obs
コード例 #3
0
        def point_data(cluster, r_list):
            def cluster_tooltip(cluster, r_list):
                cluster_rids = [
                    r_list[point.id] for point in cluster['points']
                ]
                pins = [
                    getObjectFromCatalog(catalog, rid) for rid in cluster_rids
                ]
                return self.cluster_index(pins=pins)

            num_points = len(cluster['points'])
            if num_points == 1:
                point = cluster['points'][0]
                pin = getObjectFromCatalog(catalog, r_list[point.id])
                icon_name = 'mk_single_rating_%s_%d' % (pin.type, pin.rating)

                return {
                    'id': pin.id,
                    'icon_name': icon_name,
                    'lat': pin.latitude,
                    'lon': pin.longitude,
                    'display_tooltip': False,
                    'tooltip': '',
                    'label': ''
                }
            else:
                rating = int(cluster['averageRating'])

                display_tooltip = (lat_max - lat_min) < 1.
                if display_tooltip:
                    tooltip = cluster_tooltip(cluster, r_list)
                else:
                    tooltip = ''
                icon_name = 'mk_rating_%s_%d_%d' % (cluster['type'], rating,
                                                    num_points)
                return {
                    'id': '',
                    'icon_name': icon_name,
                    'lat': cluster['center'].lat,
                    'lon': cluster['center'].lon,
                    'display_tooltip': display_tooltip,
                    'tooltip': tooltip,
                    'label': 'cluster',
                    'num_points': num_points
                }
コード例 #4
0
ファイル: views.py プロジェクト: eaudeweb/naaya.observatory
        def point_data(cluster, r_list):
            def cluster_tooltip(cluster, r_list):
                cluster_rids = [r_list[point.id] for point in cluster['points']]
                pins = [getObjectFromCatalog(catalog, rid) for rid in cluster_rids]
                return self.cluster_index(pins=pins)

            num_points = len(cluster['points'])
            if num_points == 1:
                point = cluster['points'][0]
                pin = getObjectFromCatalog(catalog, r_list[point.id])
                icon_name = 'mk_single_rating_%s_%d' % (pin.type, pin.rating)

                return {'id': pin.id,
                        'icon_name': icon_name,
                        'lat': pin.latitude,
                        'lon': pin.longitude,
                        'display_tooltip': False,
                        'tooltip': '',
                        'label': ''}
            else:
                rating = int(cluster['averageRating'])

                display_tooltip = (lat_max - lat_min) < 1.
                if display_tooltip:
                    tooltip = cluster_tooltip(cluster, r_list)
                else:
                    tooltip = ''
                icon_name = 'mk_rating_%s_%d_%d' % (cluster['type'],
                                                    rating,
                                                    num_points)
                return {'id': '',
                        'icon_name': icon_name,
                        'lat': cluster['center'].lat,
                        'lon': cluster['center'].lon,
                        'display_tooltip': display_tooltip,
                        'tooltip': tooltip,
                        'label': 'cluster',
                        'num_points': num_points}
コード例 #5
0
ファイル: views.py プロジェクト: eaudeweb/naaya.observatory
 def cluster_tooltip(cluster, r_list):
     cluster_rids = [r_list[point.id] for point in cluster['points']]
     pins = [getObjectFromCatalog(catalog, rid) for rid in cluster_rids]
     return self.cluster_index(pins=pins)