Ejemplo n.º 1
0
 /// <summary>
 /// Draws the map rectangle.
 /// </summary>
 /// <param name="mapRect">Map rectangle.</param>
 /// <param name="zoomScale">Zoom scale.</param>
 /// <param name="context"> Graphics context.</param>
 public override void DrawMapRect(MKMapRect mapRect, nfloat zoomScale, CGContext context)
 {
     base.DrawMapRect(mapRect, zoomScale, context);
     var multiPolygons = (MultiPolygon)this.polygonOverlay;
     foreach (var item in multiPolygons.Polygons)
     {
         var path = new CGPath();
         this.InvokeOnMainThread(() =>
             {
                 path = PolyPath(item.Polygon);
             });
         if (path != null)
         {
             context.SetFillColor(item.FillColor);
             context.BeginPath();
             context.AddPath(path);
             context.DrawPath(CGPathDrawingMode.EOFill);
             if (item.DrawOutlines)
             {
                 context.BeginPath();
                 context.AddPath(path);
                 context.StrokePath();
             }
         }
     }
 }
        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;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TreeWatch.iOS.MultiPolygon"/> class.
        /// </summary>
        /// <param name="polygons">List of Polygons to display.</param>
        public MultiPolygon(List<ColorPolygon> polygons)
        {
            this.Polygons = polygons;

            this.boundingRect.Origin = polygons[0].Polygon.BoundingMapRect.Origin;
            foreach (var item in polygons)
            {
                this.boundingRect = MKMapRect.Union(this.boundingRect, item.Polygon.BoundingMapRect);
            }
        }
Ejemplo n.º 4
0
 public override void DrawMapRect(MKMapRect mapRect, float zoomScale, CGContext context)
 {
     if(_polygon != null)
         DrawPolygon(_polygon,mapRect,zoomScale,context);
     else
         foreach(var polygon in _polygons)
         {
             DrawPolygon(polygon,mapRect,zoomScale,context);
         }
 }
Ejemplo n.º 5
0
 public void DrawPolyline(MKPolyline polygon,MKMapRect mapRect, float zoomScale, CGContext context)
 {
     CGPath path = this.polyPath (polygon,mapRect,zoomScale,context);
     if (path != null)
     {
         this.ApplyFillProperties (context, zoomScale);
         context.BeginPath ();
         context.AddPath (path);
         context.DrawPath (CGPathDrawingMode.Stroke);
         this.ApplyStrokeProperties (context, zoomScale);
         context.BeginPath ();
         context.AddPath (path);
         context.StrokePath ();
     }
 }
Ejemplo n.º 6
0
 public override void DrawMapRect(MKMapRect mapRect, float zoomScale, CGContext context)
 {
     Console.WriteLine("Drawing paths");
     Console.WriteLine(zoomScale);
      Console.WriteLine( MKRoadWidthAtZoomScale(zoomScale));
     //this.LineDashPattern = new NSNumber[]{new NSNumber(2),new NSNumber(0),new NSNumber(1)};
     this.LineJoin = CGLineJoin.Round;
     if(_polyline != null)
         DrawPolyline(_polyline,mapRect,zoomScale,context);
     else
         foreach(var polyline in _polylines)
         {
             DrawPolyline(polyline,mapRect,zoomScale,context);
         }
 }
Ejemplo n.º 7
0
        public CGPath polyPath(MKPolyline polyline,MKMapRect mapRect, float zoomScale, CGContext context)
        {
            MKMapPoint[] points = polyline.Points;
            Int32 pointCount = polyline.PointCount;
            Int32 i;

            if (pointCount < 3)
                return null;

            CGPath path = new CGPath ();

            PointF relativePoint = this.PointForMapPoint (points[0]);
            path.MoveToPoint (relativePoint.X, relativePoint.Y);
            for (i = 1; i < pointCount; i++)
            {
                relativePoint = this.PointForMapPoint (points[i]);
                path.AddLineToPoint(relativePoint);
            }

            return path;
        }
 public override void DrawMapRect (MKMapRect mapRect, float zoomScale, CGContext context)
 {
     UIGraphics.PushContext(context);
     
     context.SetLineWidth (4000);    
     
     UIColor.Blue.SetFill();  
     CGPath path = new CGPath ();
     
     RectangleF r = this.RectForMapRect(_overlay.BoundingMapRect());
     PointF _origin = r.Location;
                          
     path.AddLines (new PointF[] { 
         _origin, 
         new PointF (_origin.X + 35000, _origin.Y + 80000),
         new PointF (_origin.X - 50000, _origin.Y + 30000),
         new PointF (_origin.X + 50000, _origin.Y + 30000),
         new PointF (_origin.X - 35000, _origin.Y + 80000) });
              
     context.AddPath (path);
     context.DrawPath (CGPathDrawingMode.Fill);
     
     UIGraphics.PopContext();
 }
		public override void DrawMapRect (MKMapRect mapRect, nfloat zoomScale, CGContext context)
		{
			if (cachedImages?.Count > index)
				context.DrawImage (cachedRect, cachedImages [Convert.ToInt32 (index)]);
		}
Ejemplo n.º 10
0
		public override bool CanDrawMapRect (MKMapRect mapRect, nfloat zoomScale) => cachedImages?.Count > index;
Ejemplo n.º 11
0
        public List <IMKAnnotation> ClusteredAnnotationsWithinMapRect(MKMapRect rect, double zoomScale, Dictionary <IMKAnnotation, bool> filter)
        {
            double cellSize = CellSizeForZoomScale(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);
                        BoundingBox mapBox  = Utils.BoundingBoxForMapRect(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);
                            CustomAnnotation       cluster    = new CustomAnnotation()
                            {
                                Location = coordinate
                            };
                            cluster.Annotations = annotations;
                            clusteredAnnotations.Add(cluster);
                        }
                    }
                }
            }

            return(clusteredAnnotations);
        }
 public List<IMKAnnotation> ClusteredAnnotationsWithinMapRect(MKMapRect rect, double zoomScale)
 {
     return ClusteredAnnotationsWithinMapRect(rect, zoomScale, null);
 }
 static extern FBBoundingBox FBBoundingBoxForMapRect(MKMapRect mapRect);
Ejemplo n.º 14
0
        public void ClusterInMapRect(MKMapRect rect)
        {
            if (_rootMapCluster != null)
            {
                var clustersToShowOnMap            = _rootMapCluster.FindChildrenInMapRect(NumberOfClusters(), rect);
                var availableSingleAnnotations     = new List <ClusterAnnotation>();
                var availableClusterAnnotations    = new List <ClusterAnnotation>();
                var selfDividingSingleAnnotations  = new List <ClusterAnnotation>();
                var selfDividingClusterAnnotations = new List <ClusterAnnotation>();

                // TODO: Surely this can be done prettier
                var temp = _singleAnnotationsPool;
                temp.AddRange(_clusterAnnotationsPool);

                foreach (var annotation in temp)
                {
                    bool isAncestor = false;
                    if (annotation.Cluster != null)
                    {
                        foreach (var cluster in clustersToShowOnMap)
                        {
                            if (annotation.Cluster.IsAncestorOf(cluster))
                            {
                                if (cluster.Annotation != null)
                                {
                                    selfDividingSingleAnnotations.Add(annotation);
                                }
                                else
                                {
                                    selfDividingClusterAnnotations.Add(annotation);
                                }

                                isAncestor = true;
                                break;
                            }
                        }
                    }

                    if (!isAncestor)
                    {
                        if (!AnnotationBelongsToClusters(annotation, clustersToShowOnMap))
                        {
                            if (annotation.Type == ClusterAnnotationType.Leaf)
                            {
                                availableSingleAnnotations.Add(annotation);
                            }
                            else
                            {
                                availableClusterAnnotations.Add(annotation);
                            }
                        }
                    }
                }

                // TODO: Surely this can be done prettier
                var temp2 = selfDividingSingleAnnotations;
                temp2.AddRange(selfDividingClusterAnnotations);

                foreach (ClusterAnnotation annotation in temp2)
                {
                    var willNeedAnAvailableAnnotation = false;
                    var originalAnnotationCoordinate  = annotation.Coordinate;
                    var originalAnnotationCluster     = annotation.Cluster;

                    foreach (var cluster in clustersToShowOnMap)
                    {
                        if (originalAnnotationCluster.IsAncestorOf(cluster))
                        {
                            if (!willNeedAnAvailableAnnotation)
                            {
                                willNeedAnAvailableAnnotation = true;
                                annotation.Cluster            = cluster;

                                if (cluster.Annotation != null)
                                {
                                    if (annotation.Type != ClusterAnnotationType.Leaf)
                                    {
                                        var singleAnnotation = availableSingleAnnotations.Last();
                                        availableSingleAnnotations.RemoveAt(availableSingleAnnotations.Count - 1);
                                        // TODO What if count = 0
                                        singleAnnotation.Cluster    = annotation.Cluster;
                                        singleAnnotation.Coordinate = originalAnnotationCoordinate;
                                        availableClusterAnnotations.Add(annotation);
                                    }
                                }
                            }
                            else
                            {
                                ClusterAnnotation availableAnnotation;

                                if (cluster.Annotation != null)
                                {
                                    availableAnnotation = availableSingleAnnotations.Last();
                                    availableSingleAnnotations.RemoveAt(availableSingleAnnotations.Count - 1);
                                    // TODO What if count = 0
                                }
                                else
                                {
                                    availableAnnotation = availableClusterAnnotations.Last();
                                    availableClusterAnnotations.RemoveAt(availableClusterAnnotations.Count - 1);
                                    // TODO What if count = 0
                                }

                                availableAnnotation.Cluster    = cluster;
                                availableAnnotation.Coordinate = originalAnnotationCoordinate;
                            }
                        }
                    }
                }

                foreach (var cluster in clustersToShowOnMap)
                {
                    var didAlreadyFindAChild = false;
                    var tempList             = _clusterAnnotations; // TODO: The original adjusts the annotation in below for loop, we can't do that

                    foreach (var annotation in _clusterAnnotations)
                    {
                        if (annotation.GetType() != typeof(MKUserLocation))
                        {
                            if (annotation.Cluster != null && annotation.GetType() != typeof(MKUserLocation))
                            {
                                if (cluster.IsAncestorOf(annotation.Cluster))
                                {
                                    var index = _clusterAnnotations.IndexOf(annotation);

                                    if (annotation.Type == ClusterAnnotationType.Leaf)
                                    {
                                        ClusterAnnotation clusterAnnotation = availableClusterAnnotations.Last();
                                        availableClusterAnnotations.RemoveAt(availableClusterAnnotations.Count - 1);
                                        // TODO What if count = 0
                                        clusterAnnotation.Cluster    = cluster;
                                        clusterAnnotation.Coordinate = annotation.Coordinate;
                                        availableSingleAnnotations.Add(annotation);

                                        tempList[index] = clusterAnnotation;
                                    }
                                    else
                                    {
                                        tempList[index].Cluster = cluster;
                                    }

                                    if (didAlreadyFindAChild)
                                    {
                                        tempList[index].ShouldBeRemovedAfterAnimation = true;
                                    }

                                    if (tempList[index].IsOffscreen(tempList[index].Coordinate))
                                    {
                                        tempList[index].Coordinate = tempList[index].Cluster.ClusterCoordinate;
                                    }

                                    didAlreadyFindAChild = true;
                                }
                            }
                        }
                    }

                    _clusterAnnotations = tempList;
                }

                foreach (var annotation in availableSingleAnnotations)
                {
                    if (annotation.Type == ClusterAnnotationType.Leaf && annotation.Cluster != null)
                    {
                        annotation.Reset();
                    }
                }

                foreach (var annotation in availableClusterAnnotations)
                {
                    if (annotation.Type == ClusterAnnotationType.Cluster && annotation.Cluster != null)
                    {
                        annotation.Reset();
                    }
                }

                BeginAnimations("ADClusterMapViewAnimation");
                SetAnimationBeginsFromCurrentState(false);
                SetAnimationDelegate(this);
                SetAnimationDuration(0.5f);

                foreach (var annotation in _clusterAnnotations)
                {
                    if (annotation.GetType() != typeof(MKUserLocation) && annotation.Cluster != null)
                    {
                        if (!annotation.IsOffscreen(annotation.Coordinate))
                        {
                            annotation.Coordinate = annotation.Cluster.ClusterCoordinate;
                        }
                    }
                }

                CommitAnimations();

                foreach (MapCluster cluster in clustersToShowOnMap)
                {
                    bool isAlreadyAnnotated = false;

                    foreach (ClusterAnnotation annotation in _clusterAnnotations)
                    {
                        if (annotation.GetType() != typeof(MKUserLocation))
                        {
                            if (cluster.Equals(annotation.Cluster))
                            {
                                isAlreadyAnnotated = true;
                                break;
                            }
                        }
                    }

                    if (!isAlreadyAnnotated)
                    {
                        if (cluster.Annotation != null)
                        {
                            (availableSingleAnnotations.Last()).Cluster    = cluster;
                            (availableSingleAnnotations.Last()).Coordinate = cluster.ClusterCoordinate;
                            availableSingleAnnotations.RemoveAt(availableSingleAnnotations.Count - 1);
                            // TODO What if count = 0
                        }
                        else
                        {
                            (availableClusterAnnotations.Last()).Cluster    = cluster;
                            (availableClusterAnnotations.Last()).Coordinate = cluster.ClusterCoordinate;
                            availableClusterAnnotations.RemoveAt(availableClusterAnnotations.Count - 1);
                            // TODO What if count = 0
                        }
                    }
                }

                foreach (ClusterAnnotation annotation in availableSingleAnnotations)
                {
                    if (annotation.Type == ClusterAnnotationType.Leaf)
                    {
                        annotation.Reset();
                    }
                }

                foreach (ClusterAnnotation annotation in availableClusterAnnotations)
                {
                    if (annotation.Type == ClusterAnnotationType.Cluster)
                    {
                        annotation.Reset();
                    }
                }
            }
        }
Ejemplo n.º 15
0
 public extern static void RectangleF_objc_msgSend_stret_MKMapRect(out RectangleF buf, IntPtr receiver, IntPtr selector, MKMapRect p1);
Ejemplo n.º 16
0
 public extern static RectangleF RectangleF_objc_msgSend_MKMapRect(IntPtr receiver, IntPtr selector, MKMapRect p1);
 public CustomOverlay (CLLocationCoordinate2D coordinate)
 {       
     MKMapPoint mp = MKMapPointForCoordinate(coordinate);       
     
     _boundingMapRect = new MKMapRect(mp, new MKMapSize(MKMapSizeWorld.Height/4, MKMapSizeWorld.Width/4));
 }
Ejemplo n.º 18
0
 public List <IMKAnnotation> ClusteredAnnotationsWithinMapRect(MKMapRect rect, double zoomScale)
 {
     return(ClusteredAnnotationsWithinMapRect(rect, zoomScale, null));
 }