超过5000个地方的定制集群

时间:2018-06-22 11:30:56

标签: android google-maps

我在android中有一个应用程序,在地图上加载了5000多个地方。我当时在考虑将NonHierarchicalViewBasedAlgorithm与可扩展NonHierarchicalDistanceBasedAlgorithm的聚类一起使用,但问题是客户只想先加载优先级较高的项目(不聚类-因此我们应该在启动时显示所有约500个位置),同时进行足够的缩放(例如zoomlevel) > 10),我们应该在地图上添加所有优先级的所有可见项。 因此,我自定义了NonHierarchicalDistanceBasedAlgorithm,我目前不使用它来对项目进行聚类(之所以这样做,是因为我需要四叉树逻辑来仅在地图中添加可见位置) 这是我的自定义内容:

@Override
public Set<? extends Cluster<T>> getClusters(double zoom) {
    final int discreteZoom = (int) zoom;

    final double zoomSpecificSpan = mMaxDistance / Math.pow(2, discreteZoom) / 256;

    final Set<QuadItem<T>> visitedCandidates = new HashSet<QuadItem<T>>();
    final Set<Cluster<T>> results = new HashSet<Cluster<T>>();
    final Map<QuadItem<T>, Double> distanceToCluster = new HashMap<QuadItem<T>, Double>();
    final Map<QuadItem<T>, StaticCluster<T>> itemToCluster = new HashMap<QuadItem<T>, StaticCluster<T>>();

    synchronized (mQuadTree) {
        for (QuadItem<T> candidate : getClusteringItems(mQuadTree, discreteZoom)) {
            if (visitedCandidates.contains(candidate)) {
                // Candidate is already part of another cluster.
                continue;
            }

            Bounds searchBounds = createBoundsFromSpan(candidate.getPoint(), zoomSpecificSpan);
            Collection<QuadItem<T>> clusterItems;
            clusterItems = mQuadTree.search(searchBounds);
            //if (clusterItems.size() == 1 ) { //I commented out this part
                // Only the current marker is in range. Just add the single item to the results.
                results.add(candidate);
                visitedCandidates.add(candidate);
                distanceToCluster.put(candidate, 0d);
                continue;
            /*Also commented out this so as to not cluster}
            StaticCluster<T> cluster = new StaticCluster<T>(candidate.mClusterItem.getPosition());
            results.add(cluster);

            for (QuadItem<T> clusterItem : clusterItems) {
                Double existingDistance = distanceToCluster.get(clusterItem);
                double distance = distanceSquared(clusterItem.getPoint(), candidate.getPoint());
                if (existingDistance != null) {
                    // Item already belongs to another cluster. Check if it's closer to this cluster.
                    if (existingDistance < distance) {
                        continue;
                    }
                    // Move item to the closer cluster.
                    itemToCluster.get(clusterItem).remove(clusterItem.mClusterItem);
                }
                distanceToCluster.put(clusterItem, distance);
                cluster.add(clusterItem.mClusterItem);
                itemToCluster.put(clusterItem, cluster);
            }
            visitedCandidates.addAll(clusterItems); */
        }
    }
    return results;
}

我知道我的实现不是最好的,也不是正确的(我可以从地图的速度看到它,这就是为什么我要提出任何想法!

0 个答案:

没有答案