Exemplo n.º 1
0
        public static bool FBBoundingBoxContainsCoordinate(FBBoundingBox box, CLLocationCoordinate2D coordinate)
        {
            bool containsX = box.x0 <= coordinate.Latitude && coordinate.Latitude <= box.xf;
            bool containsY = box.y0 <= coordinate.Longitude && coordinate.Longitude <= box.yf;

            return(containsX && containsY);
        }
Exemplo n.º 2
0
        public void EnumerateAnnotationsInBox(FBBoundingBox box, FBQuadTreeNode withNode, AnnotationEnumDelegate enumFunc)
        {
            if (!FBUtils.FBBoundingBoxIntersectsBoundingBox(withNode.BoundingBox, box))
            {
                return;
            }

            List <IMKAnnotation> tempArray = new List <IMKAnnotation>(withNode.Annotations);

            foreach (IMKAnnotation annotation in tempArray)
            {
                if (FBUtils.FBBoundingBoxContainsCoordinate(box, annotation.Coordinate))
                {
                    enumFunc(annotation);
                }
            }

            if (withNode.IsLeaf())
            {
                return;
            }

            EnumerateAnnotationsInBox(box, withNode.NorthEast, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.NorthWest, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.SouthEast, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.SouthWest, enumFunc);
        }
Exemplo n.º 3
0
        public static MKMapRect FBMapRectForBoundingBox(FBBoundingBox boundingBox)
        {
            MKMapPoint topLeft  = MKMapPoint.FromCoordinate(new CLLocationCoordinate2D(boundingBox.x0, boundingBox.y0));
            MKMapPoint botRight = MKMapPoint.FromCoordinate(new CLLocationCoordinate2D(boundingBox.xf, boundingBox.yf));

            return(new MKMapRect(topLeft.X, botRight.Y, Math.Abs(botRight.X - topLeft.X), Math.Abs(botRight.Y - topLeft.Y)));
        }
        public List <IMKAnnotation> ClusteredAnnotationsWithinMapRect(MKMapRect rect, double zoomScale, Dictionary <IMKAnnotation, bool> filter)
        {
            double cellSize = FBCellSizeForZoomScale(zoomScale);

            if (RespondsToSelector != null)
            {
                cellSize *= RespondsToSelector(this);
            }
            double scaleFactor = zoomScale / cellSize;

            int minX = (int)Math.Floor(rect.MinX * scaleFactor);
            int maxX = (int)Math.Floor(rect.MaxX * scaleFactor);
            int minY = (int)Math.Floor(rect.MinY * scaleFactor);
            int maxY = (int)Math.Floor(rect.MaxY * scaleFactor);

            List <IMKAnnotation> clusteredAnnotations = new List <IMKAnnotation>();

            lock (this)
            {
                for (int x = minX; x <= maxX; x++)
                {
                    for (int y = minY; y <= maxY; y++)
                    {
                        MKMapRect     mapRect = new MKMapRect(x / scaleFactor, y / scaleFactor, 1.0 / scaleFactor, 1.0 / scaleFactor);
                        FBBoundingBox mapBox  = FBUtils.FBBoundingBoxForMapRect(mapRect);

                        double totalLatitude  = 0;
                        double totalLongitude = 0;

                        List <IMKAnnotation> annotations = new List <IMKAnnotation>();

                        _tree.EnumerateAnnotationsInBox(mapBox, delegate(IMKAnnotation annotation)
                        {
                            if (filter == null || filter[annotation])
                            {
                                totalLatitude  += annotation.Coordinate.Latitude;
                                totalLongitude += annotation.Coordinate.Longitude;
                                annotations.Add(annotation);
                            }
                        });

                        int count = annotations.Count;
                        if (count == 1)
                        {
                            clusteredAnnotations.AddRange(annotations);
                        }
                        if (count > 1)
                        {
                            CLLocationCoordinate2D coordinate = new CLLocationCoordinate2D(totalLatitude / count, totalLongitude / count);
                            FBAnnotationCluster    cluster    = new FBAnnotationCluster(coordinate);
                            cluster.Annotations = annotations;
                            clusteredAnnotations.Add(cluster);
                        }
                    }
                }
            }

            return(clusteredAnnotations);
        }
        public void Subdivide()
        {
            NorthEast = new FBQuadTreeNode();
            NorthWest = new FBQuadTreeNode();
            SouthEast = new FBQuadTreeNode();
            SouthWest = new FBQuadTreeNode();

            FBBoundingBox box  = BoundingBox;
            double        xMid = (box.xf + box.x0) / 2.0;
            double        yMid = (box.yf + box.y0) / 2.0;

            NorthEast.BoundingBox = FBUtils.FBBoundingBoxMake(xMid, box.y0, box.xf, yMid);
            NorthWest.BoundingBox = FBUtils.FBBoundingBoxMake(box.x0, box.y0, xMid, yMid);
            SouthEast.BoundingBox = FBUtils.FBBoundingBoxMake(xMid, yMid, box.xf, box.yf);
            SouthWest.BoundingBox = FBUtils.FBBoundingBoxMake(box.x0, yMid, xMid, box.yf);
        }
Exemplo n.º 6
0
        public void EnumerateAnnotationsInBox(FBBoundingBox box, FBQuadTreeNode withNode, AnnotationEnumDelegate enumFunc)
        {
            if (!FBUtils.FBBoundingBoxIntersectsBoundingBox(withNode.BoundingBox, box)) {
                return;
            }

            List<IMKAnnotation> tempArray = new List<IMKAnnotation>(withNode.Annotations);

            foreach (IMKAnnotation annotation in tempArray) {
                if (FBUtils.FBBoundingBoxContainsCoordinate(box, annotation.Coordinate)) {
                    enumFunc(annotation);
                }
            }

            if (withNode.IsLeaf()) {
                return;
            }

            EnumerateAnnotationsInBox(box, withNode.NorthEast, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.NorthWest, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.SouthEast, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.SouthWest, enumFunc);
        }
Exemplo n.º 7
0
 public void EnumerateAnnotationsInBox(FBBoundingBox box, AnnotationEnumDelegate enumFunc)
 {
     EnumerateAnnotationsInBox(box, _rootNode, enumFunc);
 }
 public FBQuadTreeNode(FBBoundingBox box) : base()
 {
     Init();
     BoundingBox = box;
 }
Exemplo n.º 9
0
 public void EnumerateAnnotationsInBox(FBBoundingBox box, AnnotationEnumDelegate enumFunc)
 {
     EnumerateAnnotationsInBox(box, _rootNode, enumFunc);
 }
Exemplo n.º 10
0
 public FBQuadTreeNode(FBBoundingBox box) : base()
 {
     Init();
     BoundingBox = box;
 }
Exemplo n.º 11
0
 public static bool FBBoundingBoxIntersectsBoundingBox(FBBoundingBox box1, FBBoundingBox box2)
 {
     return(box1.x0 <= box2.xf && box1.xf >= box2.x0 && box1.y0 <= box2.yf && box1.yf >= box2.y0);
 }