Beispiel #1
0
        public void CreateZone(List <LatitudeLongitude> coordonates
                               , bool isInAlert
                               , bool isLastMarker = false
                               , int index         = 0)
        {
            if (coordonates?.Count < 1)
            {
                return;
            }
            DeleteZone();

            var listLocation = new List <CLLocationCoordinate2D>();

            coordonates.ForEach(coord => listLocation.Add(new CLLocationCoordinate2D {
                Latitude = coord.Latitude, Longitude = coord.Longitude
            }));

            // Create an array of coordinates from allPins
            var finalCoordonates = new CLLocationCoordinate2D[listLocation.Count + 1];

            int i = 0;

            foreach (var currentPin in listLocation)
            {
                finalCoordonates[i] = currentPin;
                i++;
            }
            finalCoordonates[i] = finalCoordonates[0];

            // Add an overlay of the Zone
            ZonePolygon = MKPolygon.FromCoordinates(finalCoordonates);
            MapViewControl.AddOverlay(ZonePolygon);
        }
        protected override void DrawSearchAreaPolygon(Geoposition[] polygonData)
        {
            var polygonNativeCoordinates = polygonData.Select(CoordinateConverter.ConvertToNative);

            _currentSearchPolygon = MKPolygon.FromCoordinates(polygonNativeCoordinates.ToArray());
            _nativeMap.AddOverlay(_currentSearchPolygon);
        }
Beispiel #3
0
        void CreateMap()
        {
            var mapView = Control as MKMapView;

            mapView.OverlayRenderer = OverlayRenderer;

            var tileOverlay = new CustomTileOverlay("https://wexmothership-qa.azurewebsites.net/Content/Floors/Images/2/{z}/{x}/{y}.png")
            {
                MinimumZ             = 0,
                MaximumZ             = 5,
                CanReplaceMapContent = true
            };

            mapView.AddOverlay(tileOverlay);

            var polygonOverlay = MKPolygon.FromCoordinates(new[] {
                new CoreLocation.CLLocationCoordinate2D(0, 0.5),
                new CoreLocation.CLLocationCoordinate2D(0, 11),
                new CoreLocation.CLLocationCoordinate2D(10, 10),
                new CoreLocation.CLLocationCoordinate2D(7, 6),
                new CoreLocation.CLLocationCoordinate2D(5, 5)
            });

            mapView.AddOverlay(polygonOverlay);
        }
        public void AddOverlays()
        {
            // sample coordinates
            CLLocationCoordinate2D c1 = new CLLocationCoordinate2D(41.86337816, -72.56874647);
            CLLocationCoordinate2D c2 = new CLLocationCoordinate2D(41.96337816, -72.96874647);
            CLLocationCoordinate2D c3 = new CLLocationCoordinate2D(41.45537816, -72.76874647);
            CLLocationCoordinate2D c4 = new CLLocationCoordinate2D(42.34994, -71.09292);

            // circle
            MKCircle circle = MKCircle.Circle(c1, 10000.0);  // 10000 meter radius

            map.AddOverlay(circle);

            // polygon
            MKPolygon polygon = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[] { c1, c2, c3 });

            map.AddOverlay(polygon);

            // triangle
            MKPolyline polyline = MKPolyline.FromCoordinates(new CLLocationCoordinate2D[] { c1, c2, c3 });

            map.AddOverlay(polyline);

            CustomOverlay co = new CustomOverlay(c4);

            map.AddOverlay(co);
        }
Beispiel #5
0
        private MKPolygon GeoJsonPolygonToPolygon(Polygon geoJsonPolygon)
        {
            System.Collections.ObjectModel.ReadOnlyCollection <LineString> coords = geoJsonPolygon?.Coordinates;
            if (coords == null || coords.Count() == 0)
            {
                return(null);
            }

            LineString outer = coords.FirstOrDefault();
            IEnumerable <LineString> inner = coords.Count > 1 ? coords.Skip(1) : null;

            var outerCoordinates = new List <CLLocationCoordinate2D>();

            foreach (IPosition coordinate in outer.Coordinates)
            {
                outerCoordinates.Add(new CLLocationCoordinate2D(coordinate.Latitude, coordinate.Longitude));
            }

            var innerPolygons = new List <MKPolygon>();

            if (inner != null)
            {
                foreach (LineString linestring in inner)
                {
                    var innerCoordinates = new List <CLLocationCoordinate2D>();
                    foreach (IPosition coordinate in linestring.Coordinates)
                    {
                        innerCoordinates.Add(new CLLocationCoordinate2D(coordinate.Latitude, coordinate.Longitude));
                    }
                    innerPolygons.Add(MKPolygon.FromCoordinates(innerCoordinates.ToArray()));
                }
            }
            return(MKPolygon.FromCoordinates(outerCoordinates.ToArray(), innerPolygons.ToArray()));
        }
Beispiel #6
0
        private void OnUpdateHighlight()
        {
            var highlightableMap = (HighlightableMap)Element;
            var nativeMap        = Control as MKMapView;

            if (highlightableMap == null || nativeMap == null)
            {
                return;
            }

            nativeMap.RemoveOverlays(nativeMap.Overlays);

            if (highlightableMap?.Highlight == null)
            {
                return;
            }

            _currentHighlight = highlightableMap.Highlight;

            var overlays = new List <IMKOverlay>();

            foreach (var polygon in highlightableMap.Highlight.Polygons)
            {
                var coordinates = new List <CLLocationCoordinate2D>();
                foreach (var position in polygon.Positions)
                {
                    coordinates.Add(new CLLocationCoordinate2D(position.Latitude, position.Longitude));
                }

                var blockOverlay = MKPolygon.FromCoordinates(coordinates.ToArray());
                overlays.Add(blockOverlay);
            }

            nativeMap.AddOverlays(overlays.ToArray());
        }
Beispiel #7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Map = new MKMapView(View.Bounds)
            {
                RotateEnabled = true,
                ScrollEnabled = true,
                ZoomEnabled   = true,
                Delegate      = new MapDelegate(),
                MapType       = MKMapType.Standard
            };

            View.AddSubview(Map);

            foreach (var location in SampleData.Locations)
            {
                Map.AddOverlay(MKPolygon.FromCoordinates(location.BoundaryData
                                                         .Select(boundaryLocation => new CLLocationCoordinate2D(boundaryLocation.Latitude, boundaryLocation.Longitude))
                                                         .ToArray()));

                Map.AddAnnotation(new MKPointAnnotation
                {
                    Title      = location.Title,
                    Coordinate = new CLLocationCoordinate2D(location.Latitude, location.Longitude)
                });
            }

            Map.ShowAnnotations(Map.Annotations, true);
        }
Beispiel #8
0
        void AddMapElements(IEnumerable <MapElement> mapElements)
        {
            foreach (var element in mapElements)
            {
                element.PropertyChanged += MapElementPropertyChanged;

                IMKOverlay overlay = null;
                switch (element)
                {
                case Polyline polyline:
                    overlay = MKPolyline.FromCoordinates(polyline.Geopath
                                                         .Select(position => new CLLocationCoordinate2D(position.Latitude, position.Longitude))
                                                         .ToArray());
                    break;

                case Polygon polygon:
                    overlay = MKPolygon.FromCoordinates(polygon.Geopath
                                                        .Select(position => new CLLocationCoordinate2D(position.Latitude, position.Longitude))
                                                        .ToArray());
                    break;
                }

                element.MapElementId = overlay;

                ((MKMapView)Control).AddOverlay(overlay);
            }
        }
Beispiel #9
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                if (nativeMap != null)
                {
                    nativeMap.RemoveOverlays(nativeMap.Overlays);
                    nativeMap.OverlayRenderer = null;
                    polygonRenderer           = null;
                }
            }

            if (e.NewElement != null)
            {
                var formsMap  = (BindableMap)e.NewElement;
                var nativeMap = Control as MKMapView;

                nativeMap.OverlayRenderer = GetOverlayRenderer;

                CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.ShapeCoordinates.Count];

                int index = 0;
                foreach (var position in formsMap.ShapeCoordinates)
                {
                    coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }

                var blockOverlay = MKPolygon.FromCoordinates(coords);
                nativeMap.AddOverlay(blockOverlay);
            }
        }
Beispiel #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);
            #region Area
            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                if (nativeMap != null)
                {
                    nativeMap.RemoveOverlays(nativeMap.Overlays);
                    nativeMap.OverlayRenderer = null;
                    polygonRenderer           = null;
                }
            }
            if (e.NewElement != null)
            {
                var formsMap  = (AreaMap)e.NewElement;
                var nativeMap = Control as MKMapView;

                nativeMap.OverlayRenderer = GetOverlayRenderer;

                CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.ShapeCoordinates.Count];

                int index = 0;
                foreach (var position in formsMap.ShapeCoordinates)
                {
                    coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }

                var blockOverlay = MKPolygon.FromCoordinates(coords);
                nativeMap.AddOverlay(blockOverlay);
            }
            #endregion
            #region Pines
            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                if (nativeMap != null)
                {
                    nativeMap.RemoveAnnotations(nativeMap.Annotations);
                    nativeMap.GetViewForAnnotation           = null;
                    nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
                    nativeMap.DidSelectAnnotationView       -= OnDidSelectAnnotationView;
                    nativeMap.DidDeselectAnnotationView     -= OnDidDeselectAnnotationView;
                }
            }
            if (e.NewElement != null)
            {
                var formsMap  = (AreaMap)e.NewElement;
                var nativeMap = Control as MKMapView;
                customPins = formsMap.CustomPins;

                nativeMap.GetViewForAnnotation           = GetViewForAnnotation;
                nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
                nativeMap.DidSelectAnnotationView       += OnDidSelectAnnotationView;
                nativeMap.DidDeselectAnnotationView     += OnDidDeselectAnnotationView;
            }
            #endregion
        }
Beispiel #11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                locationManager.RequestWhenInUseAuthorization();
            }



            // change map type, show user location and allow zooming and panning
            map.MapType           = MKMapType.Standard;
            map.ShowsUserLocation = true;
            map.ZoomEnabled       = true;
            map.ScrollEnabled     = true;

            // set map center and region
            double lat = 30.2652233534254;
            double lon = -97.73815460962083;
            CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D(lat, lon);
            MKCoordinateRegion     mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 100, 100);

            map.CenterCoordinate = mapCenter;
            map.Region           = mapRegion;

            // set the map delegate
            mapDelegate  = new MapDelegate();
            map.Delegate = mapDelegate;

            // add a custom annotation at the map center
            map.AddAnnotations(new ConferenceAnnotation("Evolve Conference", mapCenter));

            // add an overlay of the hotel
            MKPolygon hotelOverlay = MKPolygon.FromCoordinates(
                new CLLocationCoordinate2D[] {
                new CLLocationCoordinate2D(30.2649977168594, -97.73863627705),
                new CLLocationCoordinate2D(30.2648461170005, -97.7381627734755),
                new CLLocationCoordinate2D(30.2648355402574, -97.7381750192576),
                new CLLocationCoordinate2D(30.2647791309417, -97.7379872505988),
                new CLLocationCoordinate2D(30.2654525150319, -97.7377341711021),
                new CLLocationCoordinate2D(30.2654807195004, -97.7377994819399),
                new CLLocationCoordinate2D(30.2655089239607, -97.7377994819399),
                new CLLocationCoordinate2D(30.2656428950368, -97.738346460207),
                new CLLocationCoordinate2D(30.2650364981811, -97.7385709662122),
                new CLLocationCoordinate2D(30.2650470749025, -97.7386199493406)
            });

            map.AddOverlay(hotelOverlay);

            UITapGestureRecognizer tap = new UITapGestureRecognizer(g => {
                var pt = g.LocationInView(map);
                CLLocationCoordinate2D tapCoord = map.ConvertPoint(pt, map);

                Console.WriteLine("new CLLocationCoordinate2D({0}, {1}),", tapCoord.Latitude, tapCoord.Longitude);
            });

            map.AddGestureRecognizer(tap);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            try
            {
                base.OnElementChanged(e);

                if (e.OldElement != null)
                {
                    var nativeMap = Control as MKMapView;
                    nativeMap.GetViewForAnnotation           = null;
                    nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
                    nativeMap.RemoveOverlays(nativeMap.Overlays);
                    nativeMap.OverlayRenderer = null;
                    polygonRenderer           = null;
                }

                if (e.NewElement != null)
                {
                    var formsMap  = (ExtendedMap)e.NewElement;
                    var nativeMap = Control as MKMapView;
                    customPins = formsMap.ItemsSource;

                    nativeMap.GetViewForAnnotation           = GetViewForAnnotation;
                    nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;

                    if (formsMap.Coverages != null)
                    {
                        List <IMKOverlay> overlayList = new List <IMKOverlay>();
                        nativeMap.OverlayRenderer = GetOverlayRenderer;
                        foreach (Polygon poligon in formsMap.Coverages)
                        {
                            if (poligon != null && poligon.Points != null && poligon.Points.Count > 0)
                            {
                                CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[poligon.Points.Count];
                                int index = 0;
                                foreach (var point in poligon.Points)
                                {
                                    coords[index] = new CLLocationCoordinate2D(point.Latitude, point.Longitude);
                                    index++;
                                }
                                MKPolygon blockOverlay = MKPolygon.FromCoordinates(coords);
                                blockOverlay.Title = poligon.CoverageCode;
                                overlayList.Add(blockOverlay);
                            }
                        }
                        IMKOverlay[] imko = overlayList.ToArray();
                        nativeMap.AddOverlays(imko);
                    }
                }
            }
            catch (Exception ex)
            {
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("Message", ex.Message);
                properties.Add("Source", ex.Source);
                properties.Add("StackTrace", ex.StackTrace);
                Analytics.TrackEvent("OnElementChanged", properties);
            }
        }
Beispiel #13
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.

            // add the map view
            var map = new MKMapView(UIScreen.MainScreen.Bounds);

            View.Add(map);

            // change the map style
            map.MapType = MKMapType.Standard;

            // enable/disable interactions
            // map.ZoomEnabled = false;
            // map.ScrollEnabled = false;

            // show user location
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                locationManager.RequestWhenInUseAuthorization();
            }
            map.ShowsUserLocation = true;

            // specify a custom map delegate
            var mapDelegate = new MyMapDelegate();

            map.Delegate = mapDelegate;

            // add a point annotation
            map.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "MyAnnotation",
                Coordinate = new CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // add a custom annotation
            // map.AddAnnotation(new CustomAnnotation("CustomSpot", new CLLocationCoordinate2D(38.364260, -68.120824)));

            // TODO: Step 4a - draw a circle overlay
            var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(33.755, -84.39), 100 * 1609.34); // 1609.34 = meters in a mile

            map.AddOverlay(circleOverlay);

            // TODO: Step 4b - draw a polygon (Wyoming)
            var stateOverlay = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[]
            {
                new CLLocationCoordinate2D(45.00, -111.00),
                new CLLocationCoordinate2D(45, -104),
                new CLLocationCoordinate2D(41, -104),
                new CLLocationCoordinate2D(41, -111)
            });

            map.AddOverlay(stateOverlay);
        }
Beispiel #14
0
        public void updatePolygon()
        {
            var points = itemsArray.Select(l => l.Coordinate).ToArray();

            if (Polygon != null)
            {
                mainMapView.RemoveOverlay(Polygon);
            }
            Polygon = MKPolygon.FromCoordinates(points);
            mainMapView.AddOverlay(Polygon);
        }
Beispiel #15
0
        private void UpdatePolygon()
        {
            var points = items.Select(item => item.Coordinate).ToArray();

            if (polygon != null)
            {
                mapView.RemoveOverlay(polygon);
                polygon.Dispose();
                polygon = null;
            }

            polygon = MKPolygon.FromCoordinates(points);
            mapView.AddOverlay(polygon);
        }
        private void DrawRegionBorderPolyGon(MKMapView nativeMap)
        {
            nativeMap.OverlayRenderer = GetBorderOverlayRenderer;
            var coords = new CLLocationCoordinate2D[FormsMap.AvailableRegions.Count];
            int index  = 0;

            foreach (var borders in FormsMap.AvailableRegions)
            {
                coords[index] = new CLLocationCoordinate2D(borders.Latitude, borders.Longitude);
                index++;
            }
            var borderOverlay = MKPolygon.FromCoordinates(coords);

            nativeMap.AddOverlay(borderOverlay);
        }
Beispiel #17
0
        private void AddOverlays()
        {
            var circle = MKCircle.Circle(AtlantaCoords, 100 * METERS_IN_A_MILE);

            MyMapView.AddOverlay(circle);

            var poly = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[]
            {
                new CLLocationCoordinate2D(25.25, -80.27),
                new CLLocationCoordinate2D(32.14, -64.97),
                new CLLocationCoordinate2D(18.23, -66.56)
            });

            MyMapView.AddOverlay(poly);
        }
Beispiel #18
0
        //add polygon shape to map
        public void addShape()
        {
            nativeMap.OverlayRenderer = GetOverlayRenderer;
            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[POLY_POINTS];
            int index = 0;

            foreach (var position in map.ShapeCoordinates)
            {
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }

            polygon = MKPolygon.FromCoordinates(coords);
            nativeMap.AddOverlay(polygon);
            /* NativeMap.MapLongClick += longClick; */
        }
Beispiel #19
0
        /// <summary>
        /// Adds a HeatMap to the map.
        /// </summary>
        /// <param name="points">Points for the Heatmap.</param>
        private void AddHeatMap(List <HeatmapPoint> points)
        {
            var polygons = new List <ColorPolygon>();

            var max = points.Max(r => r.Mean);
            var min = points.Min(r => r.Mean);

            var difference = max - min;

            foreach (var item in points)
            {
                var singlepolygon = (ColorPolygon)MKPolygon.FromCoordinates(ConvertCoordinates(item.BoundingCoordinates));
                var red           = ((((item.Mean - min) / difference) * 245) + 10) / 255;
                var color         = Color.FromRgb(red, 0, 1 - red);
                singlepolygon.FillColor    = color.ToCGColor();
                singlepolygon.DrawOutlines = false;
                polygons.Add(singlepolygon);
            }

            var heatmap = new MultiPolygon(polygons);

            this.mapView.AddOverlay(heatmap);

            /* Showing a 'Real' heatmap using just points
             * current Version is using multiple polygons
             * TODO Readd LFHeatMap project first
             * Found at https://github.com/TreeWatch/LFHeatMaps
             * Code :
             * var positions = new List<Position>();
             * var weights = new List<Double>();
             *
             * foreach (var item in points)
             * {
             *
             *  foreach (var pos in item.BoundingCoordinates) {
             *      positions.Add(pos);
             *          weights.Add(item.Mean);
             *  }
             * }
             * var view = new UIHeatMapView(positions, weights, mapView);
             * mapView.AddSubview(view); */
        }
Beispiel #20
0
        /// <summary>
        /// Adds the fields to the map.
        /// </summary>
        private void AddFields()
        {
            var connection = new TreeWatchDatabase();

            foreach (var field in this.myMap.Fields)
            {
                var query         = new DBQuery <Field>(connection);
                var blockPolygons = new List <ColorPolygon>();
                query.GetChildren(field);
                if (field.Blocks.Count != 0)
                {
                    foreach (var block in field.Blocks)
                    {
                        if (block.BoundingCoordinates.Count != 0 && block.BoundingCoordinates.Count >= 3)
                        {
                            var blockPoints  = ConvertCoordinates(block.BoundingCoordinates);
                            var blockPolygon = (ColorPolygon)MKPolygon.FromCoordinates(blockPoints);
                            blockPolygon.FillColor = block.TreeType.ColorProp.ToCGColor();
                            blockPolygons.Add(blockPolygon);
                        }
                    }

                    var blockMultiPolygon = new MultiPolygon(blockPolygons);

                    this.mapView.AddOverlay(blockMultiPolygon);
                }

                if (field.BoundingCoordinates.Count != 0 && field.BoundingCoordinates.Count >= 3)
                {
                    var points  = ConvertCoordinates(field.BoundingCoordinates);
                    var polygon = MKPolygon.FromCoordinates(points);
                    polygon.Title = "Field";
                    this.mapView.AddOverlay(polygon);
                }
            }

            var query2   = new DBQuery <HeatMap>(connection);
            var heatmaps = query2.GetAllWithChildren();
            var heatmap  = heatmaps[0];

            this.AddHeatMap(heatmap.Points);
        }
Beispiel #21
0
        private void DrawPolygon()
        {
            var nativeMap = Control as MKMapView;

            nativeMap.OverlayRenderer = GetPolygoneRenderer;
            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[_shapeCoordinates.Count];
            int index = 0;

            foreach (var position in _shapeCoordinates)
            {
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }
            if (nativeMap.Overlays != null)
            {
                nativeMap.RemoveOverlays(nativeMap.Overlays);
            }
            var polygoneOverlay = MKPolygon.FromCoordinates(coords);

            nativeMap.AddOverlay(polygoneOverlay);
        }
Beispiel #22
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                if (nativeMap != null)
                {
                    nativeMap.RemoveOverlays(nativeMap.Overlays);
                    nativeMap.OverlayRenderer = null;
                }
            }

            if (e.NewElement != null)
            {
                var formsMap  = (DrawableMap)e.NewElement;
                var nativeMap = Control as MKMapView;

                nativeMap.OverlayRenderer = GetOverlayRenderer;


                foreach (var worksite in formsMap.Worksites)
                {
                    var positions = worksite.GeneratePolygonPositions();

                    if (positions.Count > 0)
                    {
                        var coords = new List <CLLocationCoordinate2D>();
                        foreach (var position in positions)
                        {
                            coords.Add(new CLLocationCoordinate2D(position.Latitude, position.Longitude));
                        }

                        var blockOverlay = MKPolygon.FromCoordinates(coords.ToArray());
                        nativeMap.AddOverlay(blockOverlay);
                    }
                }
            }
        }
Beispiel #23
0
        void FindSafeZones()
        {
            var polygonOverlay = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[] {
                new CLLocationCoordinate2D(45.00, -111.00),
                new CLLocationCoordinate2D(45, -104),
                new CLLocationCoordinate2D(41, -104),
                new CLLocationCoordinate2D(41, -111)
            });

            map.AddOverlay(polygonOverlay);

            map.OverlayRenderer = (mapView, overlay) => {
                if (overlay is MKCircle)
                {
                    if (circleRenderer == null)
                    {
                        circleRenderer = new MKCircleRenderer(overlay as MKCircle)
                        {
                            FillColor = UIColor.Red,
                            Alpha     = 0.5f
                        };
                    }
                    return(circleRenderer);
                }
                else if (overlay is MKPolygon)
                {
                    if (polyRenderer == null)
                    {
                        polyRenderer           = new MKPolygonRenderer(overlay as MKPolygon);
                        polyRenderer.FillColor = UIColor.Green;
                        polyRenderer.Alpha     = 0.5f;
                    }
                    return(polyRenderer);
                }
                return(null);
            };

            Helpers.CenterOnCheyenne(map);
        }
Beispiel #24
0
 public static BindingMKPolygon FromCoordinates(CLLocationCoordinate2D[] coords)
 => new BindingMKPolygon(MKPolygon.FromCoordinates(coords));
Beispiel #25
0
 public static BindingMKPolygon FromCoordinates(CLLocationCoordinate2D[] coords, MKPolygon[] interiorPolygons)
 => new BindingMKPolygon(MKPolygon.FromCoordinates(coords, interiorPolygons));
Beispiel #26
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            MapDelegate mapDelegate = new MapDelegate();

            mapView.Delegate = mapDelegate;


            MKCoordinateRegion region = new MKCoordinateRegion();

            #region Location ausgeben (Text)
            locationManager = new CLLocationManager();

            locationManager.RequestAlwaysAuthorization();

            locationManager.LocationsUpdated += (sender, args) =>
            {
                location = args.Locations[0];
                double latitude  = Math.Round(location.Coordinate.Latitude, 4);
                double longitude = Math.Round(location.Coordinate.Longitude, 4);
                double accuracy  = Math.Round(location.HorizontalAccuracy, 0);


                lblOutput.Text = string.Format("Latitude: {0}\nLongitude: {1}\nAccuracy: {2}m", latitude, longitude, accuracy);
                Console.WriteLine("Zeitstempel Standort {0}", location.Timestamp);

                //region = new MKCoordinateRegion();
                //CLLocation secondlocation = new CLLocation(48.88370, 2.294481);
                region.Center = location.Coordinate;

                mapView.SetRegion(region, true);
            };

            locationManager.Failed += (sender, args) =>
            {
                lblOutput.Text = string.Format("Standortbestimmung fehlgeschlagen! \nFehlermeldung: {0}", args.Error.LocalizedDescription);
            };

            btnlocalize.TouchUpInside += (sender, args) =>
            {
                lblOutput.Text = "Bestimme Standort...";
                locationManager.StartUpdatingLocation();
            };

            btnStop.TouchUpInside += (sender, args) =>
            {
                locationManager.StopUpdatingLocation();
                lblOutput.Text = "Standortbestimmung beendet...";
            };
            #endregion

            #region Location in Map ausgeben

            //Aktuelle Position anzeigen
            mapView.ShowsUserLocation = true;
            mapView.ZoomEnabled       = true;

            mapView.MapType = MKMapType.Standard;

            //Karte auf der Position zentrieren
            //MKCoordinateRegion region = new MKCoordinateRegion();
            CLLocation secondlocation = new CLLocation(37.687834, -122.406417);
            region.Center = secondlocation.Coordinate;

            //Zoom-Level setzen
            MKCoordinateSpan span = new MKCoordinateSpan();
            span.LatitudeDelta  = 0.5;
            span.LongitudeDelta = 0.5;
            region.Span         = span;

            mapView.SetRegion(region, true);

            //Pin auf Karte setzen
            mapView.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "Sehenswürdigkeit",
                Coordinate = new CLLocationCoordinate2D(37.687834, -122.406417)
            });

            MKPointAnnotation myAnnotation = new MKPointAnnotation();
            myAnnotation.Coordinate = new CLLocationCoordinate2D(37.687834, -122.406417);
            myAnnotation.Title      = "Unsere Position";

            MKPointAnnotation mysecondAnnotation = new MKPointAnnotation();
            mysecondAnnotation.Coordinate = new CLLocationCoordinate2D(37.787834, -122.406417);
            mysecondAnnotation.Title      = "Unsere Position";
            mapView.AddAnnotations(new IMKAnnotation[] { myAnnotation, mysecondAnnotation });

            //mapView.GetViewForAnnotation += (mapView, annotation) =>
            //{
            //    string pID = "PinAnnotation";
            //    if (annotation is MKPointAnnotation)
            //    {
            //        MKPinAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pID);
            //        if (pinView == null)
            //            pinView = new MKPinAnnotationView(annotation, pID);

            //        pinView.PinColor = MKPinAnnotationColor.Green;
            //        pinView.CanShowCallout = true;
            //        pinView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
            //        pinView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("Default.png"));
            //        return pinView;
            //    }
            //    else
            //    {
            //        return null;
            //    }
            //};

            //var circleOverlay = MKCircle.Circle(secondlocation.Coordinate, 1000);
            //mapView.AddOverlay(circleOverlay);

            //var circleView = new MKCircleView(circleOverlay);
            //circleView.FillColor = UIColor.Blue;
            //mapView.AddOverlay(mapView,  circleView);

            MKPolygon hotelOverlay = MKPolygon.FromCoordinates(
                new CLLocationCoordinate2D[]
            {
                new CLLocationCoordinate2D(37.787834, -122.406417),
                new CLLocationCoordinate2D(37.797834, -122.406417),
                new CLLocationCoordinate2D(37.797834, -122.416417),
                new CLLocationCoordinate2D(37.787834, -122.416417),
                new CLLocationCoordinate2D(37.787834, -122.406417),
            });
            mapView.AddOverlay(hotelOverlay);
            #endregion

            #region Suchleiste in der Map
            //var searchResultContainer = new SearchResultsViewController(mapView);
            //var searchUpdater = new UISearchResultsUpdating();

            //UISearchController searchController = new UISearchController(searchResultsController: null);

            #endregion
        }
Beispiel #27
0
        public void FromCoordinates_Interior_Empty()
        {
            MKPolygon pg = MKPolygon.FromCoordinates(new CLLocationCoordinate2D [] { }, new MKPolygon [] { });

            CheckEmpty(pg);
        }
Beispiel #28
0
 public void FromCoordinates_Null()
 {
     MKPolygon.FromCoordinates(null);
 }
Beispiel #29
0
        private void ParseGeoJson()
        {
            var geoJson       = System.IO.File.ReadAllText("SharedAssets/map.geo.json");
            var geoJsonObject = JsonConvert.DeserializeObject <GeoJsonObject>(geoJson);

            foreach (var geoJsonFeature in geoJsonObject.features)
            {
                if (geoJsonFeature.geometry.type == "Polygon")
                {
                    var geometryList = JsonConvert.DeserializeObject <List <List <List <double> > > >(geoJsonFeature.geometry.coordinates.ToString());
                    Console.WriteLine(geometryList.Count + " polygon with " + geometryList[0].Count + " corners");
                    var polygonCorners = new CLLocationCoordinate2D[geometryList[0].Count];
                    var i = 0;
                    foreach (var corner in geometryList[0])
                    {
                        polygonCorners[i] = new CLLocationCoordinate2D(corner[1], corner[0]);
                        i++;
                    }

                    MKPolygon polygonOverlay = MKPolygon.FromCoordinates(polygonCorners);
                    (mapView.Delegate as MapDelegate).PolygonStyles.Add(polygonOverlay, geoJsonFeature.properties.style);

                    MKMapItem placemark = new MKMapItem(new MKPlacemark(polygonOverlay.Coordinate));

                    placemark.Name = geoJsonFeature.properties.name;
                    var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(polygonOverlay.Coordinate.Latitude, polygonOverlay.Coordinate.Longitude), geoJsonFeature.properties.name);
                    if (geoJsonFeature.properties.style == "kampeergrond")
                    {
                        annotation.AnnotationType = BasicMapAnnotation.AnnotationTypeEnum.Campground;
                    }
                    else
                    {
                        annotation.AnnotationType = BasicMapAnnotation.AnnotationTypeEnum.Region;
                    }
                    mapView.AddAnnotation(annotation);
                    mapView.AddOverlay(polygonOverlay);
                }
                else if (geoJsonFeature.geometry.type == "Point")
                {
                    var geometryList = JsonConvert.DeserializeObject <List <double> >(geoJsonFeature.geometry.coordinates.ToString());
                    var annotation   = new BasicMapAnnotation(new CLLocationCoordinate2D(geometryList[1], geometryList[0]), geoJsonFeature.properties.name);
                    annotation.AnnotationType = BasicMapAnnotation.AnnotationTypeEnum.Point;
                    mapView.AddAnnotation(annotation);
                }
                else if (geoJsonFeature.geometry.type == "LineString")
                {
                    var geometryList = JsonConvert.DeserializeObject <List <List <double> > >(geoJsonFeature.geometry.coordinates.ToString());
                    var roadCorners  = new CLLocationCoordinate2D[geometryList.Count];
                    var i            = 0;
                    foreach (var corner in geometryList)
                    {
                        roadCorners[i] = new CLLocationCoordinate2D(corner[1], corner[0]);
                        i++;
                    }

                    MKPolyline roadOverlay = MKPolyline.FromCoordinates(roadCorners);
                    (mapView.Delegate as MapDelegate).PolygonStyles.Add(roadOverlay, geoJsonFeature.properties.style);

                    mapView.AddOverlay(roadOverlay);
                }
            }
        }
Beispiel #30
0
 public void FromCoordinates_Null()
 {
     Assert.Throws <ArgumentNullException> (() => MKPolygon.FromCoordinates(null));
 }