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()); }
public PointCluster(IPoint point, int id) { X = SuperCluster.LngX(point.X); Y = SuperCluster.LatY(point.Y); Index = id; }