示例#1
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());
        }
示例#2
0
        private void HighlightCountry()
        {
            //Create map polygons
            var polygons = new List <MapPolygon>();

            foreach (var availableCountry in AvailableCountries)
            {
                var feature = _countryPolygons.Features.FirstOrDefault(f =>
                                                                       f.Id.Equals(availableCountry.CountryId, StringComparison.CurrentCultureIgnoreCase));

                if (feature == null)
                {
                    return;
                }

                if (feature.Geometry.Type == GeoJSONObjectType.MultiPolygon)
                {
                    //Country area consists of multiple polygons
                    var multiPolygonGeometry = feature.Geometry as MultiPolygon;
                    foreach (var polygonGeometry in multiPolygonGeometry?.Coordinates)
                    {
                        var polygon = GeoJsonPolygonToMapPolygon(polygonGeometry);
                        if (polygon != null)
                        {
                            polygons.Add(polygon);
                        }
                    }
                }

                else if (feature.Geometry.Type == GeoJSONObjectType.Polygon)
                {
                    //Single polygon
                    var polygonGeometry = feature.Geometry as Polygon;
                    var polygon         = GeoJsonPolygonToMapPolygon(polygonGeometry);
                    if (polygon != null)
                    {
                        polygons.Add(polygon);
                    }
                }
            }

            //Create the map highlight
            var highlight = new MapHighlight(polygons.ToArray())
            {
                FillColor       = Color.FromRgba(255, 0, 0, 128),
                StrokeColor     = Color.FromRgba(0, 0, 255, 128),
                StrokeThickness = 3
            };

            Map.Highlight = highlight;
        }