Esempio n. 1
0
        public IPoint[] GetClusters(double minX, double minY, double maxX, double maxY, int zoom)
        {
            var minLng = ((minX + 180) % 360 + 360) % 360 - 180;
            var minLat = Math.Max(-90, Math.Min(90, minY));
            var maxLng = maxX == 180? 180 : ((maxX + 180) % 360) % 360 - 180;
            var maxLat = Math.Max(-90, Math.Min(90, minY));

            if (maxX - minX >= 360)
            {
                minLng = -180;
                maxLng = 180;
            }
            else
            {
                if (minLng > maxLng)
                {
                    var easternHem = this.GetClusters(minLng, minLat, 180, maxLat, zoom);
                    var westernHem = this.GetClusters(-180, minLat, maxLng, maxLat, zoom);
                    return(easternHem.Concat(westernHem).ToArray());
                }
            }

            var tree    = this.trees[this._limitZoom(zoom)];
            var ids     = tree.Range(SuperCluster.LngX(minLng), SuperCluster.LatY(maxLat), SuperCluster.LngX(maxLng), SuperCluster.LatY(minLat)); //注意 LatY之后 颠倒了原先的y值
            var cluster = new Stack <IPoint>();

            foreach (var id in ids)
            {
                var c = tree.Points[id] as PointCluster;
                cluster.Push(c is Cluster ? SuperCluster.CreatePointFromCluster(c as Cluster) : this.points[c.Index]);
            }

            return(cluster.ToArray());
        }
Esempio n. 2
0
        public IPoint[] GetChildren(int clusterId)
        {
            var originId   = clusterId >> 5;
            var originZoom = clusterId % 32;
            var errorMsg   = "No cluster with the specified id.";

            var index = this.trees[originZoom];

            if (index == null)
            {
                throw new Exception(errorMsg);
            }

            var origin = index.Points[originId];

            if (origin == null)
            {
                throw new Exception(errorMsg);
            }

            var r        = this.radius / this.extent * Math.Pow(2, originZoom - 1);
            var ids      = index.WithIn(origin.X, origin.Y, r);
            var children = new Stack <IPoint>();

            foreach (var id in ids)
            {
                var c = index.Points[id] as PointCluster;
                if (c.ParentId == clusterId)
                {
                    children.Push(c is Cluster ? SuperCluster.CreatePointFromCluster(c as Cluster) : this.points[c.Index]);
                }
            }

            if (children.Count == 0)
            {
                throw new Exception(errorMsg);
            }

            return(children.ToArray());
        }
Esempio n. 3
0
 public PointCluster(IPoint point, int id)
 {
     X     = SuperCluster.LngX(point.X);
     Y     = SuperCluster.LatY(point.Y);
     Index = id;
 }