示例#1
0
        void PolygonOnPropertyChanged(Polygon polygon, PropertyChangedEventArgs e)
        {
            var nativePolygon = GetNativePolygon(polygon);

            if (nativePolygon == null)
            {
                return;
            }

            if (e.PropertyName == MapElement.StrokeColorProperty.PropertyName)
            {
                nativePolygon.StrokeColor = polygon.StrokeColor.ToAndroid(Colors.Black);
            }
            else if (e.PropertyName == MapElement.StrokeWidthProperty.PropertyName)
            {
                nativePolygon.StrokeWidth = polygon.StrokeWidth;
            }
            else if (e.PropertyName == Polygon.FillColorProperty.PropertyName)
            {
                nativePolygon.FillColor = polygon.FillColor.ToAndroid();
            }
            else if (e.PropertyName == nameof(polygon.Geopath))
            {
                nativePolygon.Points = polygon.Geopath.Select(p => new LatLng(p.Latitude, p.Longitude)).ToList();
            }
        }
示例#2
0
        protected virtual PolygonOptions CreatePolygonOptions(Polygon polygon)
        {
            var opts = new PolygonOptions();

            opts.InvokeStrokeColor(polygon.StrokeColor.ToAndroid(Colors.Black));
            opts.InvokeStrokeWidth(polygon.StrokeWidth);

            if (!polygon.StrokeColor.IsDefault())
            {
                opts.InvokeFillColor(polygon.FillColor.ToAndroid());
            }

            // Will throw an exception when added to the map if Points is empty
            if (polygon.Geopath.Count == 0)
            {
                opts.Points.Add(new LatLng(0, 0));
            }
            else
            {
                foreach (var position in polygon.Geopath)
                {
                    opts.Points.Add(new LatLng(position.Latitude, position.Longitude));
                }
            }

            return(opts);
        }
示例#3
0
        void RemovePolygon(Polygon polygon)
        {
            var native = GetNativePolygon(polygon);

            if (native != null)
            {
                native.Remove();
                _polygons.Remove(native);
            }
        }
示例#4
0
        protected Polygon GetFormsPolygon(APolygon polygon)
        {
            Polygon targetPolygon = null;

            for (int i = 0; i < Element.MapElements.Count; i++)
            {
                var element = Element.MapElements[i];
                if ((string)element.MapElementId == polygon.Id)
                {
                    targetPolygon = (Polygon)element;
                    break;
                }
            }

            return(targetPolygon);
        }
示例#5
0
        public MapElementsGallery()
        {
            InitializeComponent();

            Map.MoveToRegion(
                MapSpan.FromCenterAndRadius(
                    new Position(39.828152, -98.569817),
                    Distance.FromMiles(1681)));

            _polyline = new Maps.Polyline
            {
                Geopath =
                {
                    new Position(47.641944, -122.127222),
                    new Position(37.411625, -122.071327),
                    new Position(35.138901, -80.922623)
                }
            };

            _polygon = new Maps.Polygon
            {
                StrokeColor = Color.FromHex("#002868"),
                FillColor   = Color.FromHex("#88BF0A30"),
                Geopath     =
                {
                    new Position(37, -102.05),
                    new Position(37, -109.05),
                    new Position(41, -109.05),
                    new Position(41, -102.05)
                }
            };

            _circle = new Circle
            {
                Center      = new Position(42.352364, -71.067177),
                Radius      = Distance.FromMiles(100.0),
                StrokeColor = Color.FromRgb(31, 174, 206),
                FillColor   = Color.FromRgba(31, 174, 206, 127)
            };

            Map.MapElements.Add(_polyline);
            Map.MapElements.Add(_polygon);
            Map.MapElements.Add(_circle);

            ElementPicker.SelectedIndex = 0;
        }
示例#6
0
        void AddClicked(object sender, EventArgs e)
        {
            switch (_selectedType)
            {
            case SelectedElementType.Polyline:
                Map.MapElements.Add(_polyline = new Maps.Polyline());
                break;

            case SelectedElementType.Polygon:
                Map.MapElements.Add(_polygon = new Maps.Polygon());
                break;

            case SelectedElementType.Circle:
                Map.MapElements.Add(_circle = new Circle());
                break;
            }
        }
示例#7
0
        protected APolygon GetNativePolygon(Polygon polygon)
        {
            APolygon targetPolygon = null;

            if (_polygons != null)
            {
                for (int i = 0; i < _polygons.Count; i++)
                {
                    var native = _polygons[i];
                    if (native.Id == (string)polygon.MapElementId)
                    {
                        targetPolygon = native;
                        break;
                    }
                }
            }

            return(targetPolygon);
        }
示例#8
0
        void AddPolygon(Polygon polygon)
        {
            var map = NativeMap;

            if (map == null)
            {
                return;
            }

            if (_polygons == null)
            {
                _polygons = new List <APolygon>();
            }

            var options       = CreatePolygonOptions(polygon);
            var nativePolygon = map.AddPolygon(options);

            polygon.MapElementId = nativePolygon.Id;

            _polygons.Add(nativePolygon);
        }
示例#9
0
        void RemoveClicked(object sender, EventArgs e)
        {
            switch (_selectedType)
            {
            case SelectedElementType.Polyline:
                Map.MapElements.Remove(_polyline);
                _polyline = Map.MapElements.OfType <Maps.Polyline>().LastOrDefault();

                if (_polyline == null)
                {
                    Map.MapElements.Add(_polyline = new Maps.Polyline());
                }

                break;

            case SelectedElementType.Polygon:
                Map.MapElements.Remove(_polygon);
                _polygon = Map.MapElements.OfType <Maps.Polygon>().LastOrDefault();

                if (_polygon == null)
                {
                    Map.MapElements.Add(_polygon = new Maps.Polygon());
                }

                break;

            case SelectedElementType.Circle:
                Map.MapElements.Remove(_circle);
                _circle = Map.MapElements.OfType <Circle>().LastOrDefault();

                if (_circle == null)
                {
                    Map.MapElements.Add(_circle = new Circle());
                }

                break;
            }
        }