private void DrawLoggedPosition(Position position)
        {
            System.Diagnostics.Debug.Write($"@@@@@ DrawLoggedPosition ");

            Tuple <int, int> index = customMap.GetIndexInGrid(position);

            if (drawnPositionsIndices.Contains(index))
            {
                return;
            }
            drawnPositionsIndices.Add(index);

            PolygonOptions polygon = GetPolygon();

            Tuple <Position, Position> visitedArea = customMap.GetAreaOnPosition(position);
            Position topLeft  = visitedArea.Item1;
            Position botRight = visitedArea.Item2;

            polygon.Add(new LatLng(topLeft.Latitude, topLeft.Longitude));
            polygon.Add(new LatLng(botRight.Latitude, topLeft.Longitude));
            polygon.Add(new LatLng(botRight.Latitude, botRight.Longitude));
            polygon.Add(new LatLng(topLeft.Latitude, botRight.Longitude));

            NativeMap.AddPolygon(polygon);
        }
        public void crearPoligono(GoogleMap map)
        {
            PolygonOptions rectOptions = new PolygonOptions();

            rectOptions.Add(new LatLng(37.35, -122.0));
            rectOptions.Add(new LatLng(37.45, -122.0));
            rectOptions.Add(new LatLng(37.45, -122.2));
            rectOptions.Add(new LatLng(37.35, -122.2));

            // notice we don't need to close off the polygon

            map.AddPolygon(rectOptions);
        }
Exemple #3
0
        public MapOverlay(Cell cell)
        {
            CellID = cell.ID;

            PolygonOptions = new PolygonOptions();
            PolygonOptions.Add(new LatLng((double)cell.Latitude, (double)cell.Longitude)); //first rectangle point
            PolygonOptions.Add(new LatLng((double)cell.Latitude, (double)cell.Longitude + (double)GameModel.FrontierInterval));
            PolygonOptions.Add(new LatLng((double)cell.Latitude + (double)GameModel.FrontierInterval, (double)cell.Longitude + (double)GameModel.FrontierInterval));
            PolygonOptions.Add(new LatLng((double)cell.Latitude + (double)GameModel.FrontierInterval, (double)cell.Longitude)); //automatically connects last two points

            Color color = ColorCode.TeamColor(cell.TeamID);

            PolygonOptions.InvokeFillColor(color); //Transparent (alpha) int [0-255] 255 being opaque
            PolygonOptions.InvokeStrokeWidth(0);
        }
Exemple #4
0
 protected override void OnMapReady(GoogleMap map)
 {
     base.OnMapReady(map);
     GoogleMap = map;
     map.UiSettings.MapToolbarEnabled = false;
     if (FormsMap.RoutePins != null && FormsMap.RoutePins.Count > 1)
     {
         var polylineOptions = new PolylineOptions();
         polylineOptions.InvokeColor(Color.Red.ToAndroid());
         foreach (var pins in FormsMap.RoutePins)
         {
             polylineOptions.Add(new LatLng(pins.Position.Latitude, pins.Position.Longitude));
         }
         NativeMap.AddPolyline(polylineOptions);
     }
     else if (FormsMap.AvailableRegions != null)
     {
         var polygonOptions = new PolygonOptions();
         polygonOptions.InvokeFillColor(Android.Graphics.Color.ParseColor("#2271cce7"));
         polygonOptions.InvokeStrokeColor(Android.Graphics.Color.ParseColor("#2271cce7"));
         polygonOptions.InvokeStrokeWidth(15.0f);
         foreach (var position in FormsMap.AvailableRegions)
         {
             polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
         }
         NativeMap.AddPolygon(polygonOptions);
     }
 }
Exemple #5
0
        private PolygonOptions GeoJsonPolygonToPolygon(GPolygon geoJsonPolygon)
        {
            System.Collections.ObjectModel.ReadOnlyCollection <LineString> coords = geoJsonPolygon?.Coordinates;
            if (coords == null || coords.Count() == 0)
            {
                return(null);
            }

            PolygonOptions polygonOptions = GetPolygonOptions();

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

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

            if (inner != null)
            {
                foreach (LineString linestring in inner)
                {
                    var holes = linestring.Coordinates.Select(coordinate => new LatLng(coordinate.Latitude, coordinate.Longitude)).ToList();
                    polygonOptions.Holes.Add(holes.ToJavaList());
                }
            }

            return(polygonOptions);
        }
Exemple #6
0
        private void HandleInfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
        {
            // Draw a circle on the map
            CircleOptions circleOptions = new CircleOptions();

            circleOptions.InvokeCenter(Location_NewYork);
            circleOptions.InvokeRadius(100000.0);
            circleOptions.InvokeFillColor(Android.Graphics.Color.White);
            _map.AddCircle(circleOptions);

            // Draw a polygon (Wyoming) on the map
            PolygonOptions polygonOptions = new PolygonOptions();

            polygonOptions.Add(new LatLng[]
            {
                new LatLng(45.00, -111.00),
                new LatLng(45, -104),
                new LatLng(41, -104),
                new LatLng(41, -111)
            });

            polygonOptions.InvokeFillColor(Android.Graphics.Color.Purple);
            polygonOptions.InvokeStrokeWidth(2);
            _map.AddPolygon(polygonOptions);
        }
        void AddPolygons(IList polygons)
        {
            var map = NativeMap;

            if (map == null)
            {
                return;
            }

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

            _polygons.AddRange(polygons.Cast <Polygon> ().Select(polygon => {
                var opts = new PolygonOptions();

                foreach (var p in polygon.Positions)
                {
                    opts.Add(new LatLng(p.Latitude, p.Longitude));
                }

                opts.InvokeStrokeWidth(polygon.StrokeWidth * _scaledDensity); // TODO: convert from px to pt. Is this collect? (looks like same iOS Maps)
                opts.InvokeStrokeColor(polygon.StrokeColor.ToAndroid());
                opts.InvokeFillColor(polygon.FillColor.ToAndroid());
                opts.Clickable(polygon.IsClickable);

                var nativePolygon = map.AddPolygon(opts);

                // associate pin with marker for later lookup in event handlers
                polygon.Id = nativePolygon;
                return(nativePolygon);
            }));
        }
        protected override NativePolygon CreateNativeItem(Polygon outerItem)
        {
            var opts = new PolygonOptions();

            foreach (var p in outerItem.Positions)
            {
                opts.Add(new LatLng(p.Latitude, p.Longitude));
            }

            opts.InvokeStrokeWidth(outerItem.StrokeWidth * this.ScaledDensity); // TODO: convert from px to pt. Is this collect? (looks like same iOS Maps)
            opts.InvokeStrokeColor(outerItem.StrokeColor.ToAndroid());
            opts.InvokeFillColor(outerItem.FillColor.ToAndroid());
            opts.Clickable(outerItem.IsClickable);

            var nativePolygon = NativeMap.AddPolygon(opts);

            // associate pin with marker for later lookup in event handlers
            outerItem.NativeObject = nativePolygon;
            outerItem.SetOnPositionsChanged((polygon, e) =>
            {
                var native    = polygon.NativeObject as NativePolygon;
                native.Points = polygon.Positions.ToLatLngs();
            });

            return(nativePolygon);
        }
Exemple #9
0
        private void SetupOverlays()
        {
            // render a circle on the map
            CircleOptions circleOptions = new CircleOptions();

            circleOptions.InvokeCenter(AtlantaCoords);
            circleOptions.InvokeRadius(8000.0);
            circleOptions.InvokeFillColor(Android.Graphics.Color.Orange);
            _map.AddCircle(circleOptions);

            // render a polygon on the map
            PolygonOptions polygonOptions = new PolygonOptions();

            polygonOptions.Add(new LatLng[]
            {
                new LatLng(25.25, -80.27),
                new LatLng(32.14, -64.97),
                new LatLng(18.23, -66.56)
            });

            polygonOptions.InvokeFillColor(Android.Graphics.Color.Yellow);
            polygonOptions.InvokeStrokeWidth(8);
            _map.AddPolygon(polygonOptions);

            // overlay images at physical size: _map.AddGroundOverlay
        }
Exemple #10
0
        public MapOverlay(Cell cell)
        {
            CellID = cell.ID;

            // Set cell overlay options
            cellPolygonOptions = new PolygonOptions();
            cellPolygonOptions.Add(new LatLng((double)cell.Latitude, (double)cell.Longitude)); //first rectangle point
            cellPolygonOptions.Add(new LatLng((double)cell.Latitude, (double)cell.Longitude + (double)GameModel.FrontierInterval));
            cellPolygonOptions.Add(new LatLng((double)cell.Latitude + (double)GameModel.FrontierInterval, (double)cell.Longitude + (double)GameModel.FrontierInterval));
            cellPolygonOptions.Add(new LatLng((double)cell.Latitude + (double)GameModel.FrontierInterval, (double)cell.Longitude)); //automatically connects last two points
            cellPolygonOptions.InvokeZIndex(100);

            // Set mine overlay options
            LatLng circleCenter = new LatLng((double)cell.Latitude + ((double)GameModel.FrontierInterval / 2), (double)cell.Longitude + ((double)GameModel.FrontierInterval / 2));

            mineCircleOptions = new CircleOptions();
            mineCircleOptions.InvokeCenter(circleCenter);
            mineCircleOptions.InvokeRadius(3);
            mineCircleOptions.InvokeStrokeWidth(6);
            mineCircleOptions.InvokeStrokeColor(Color.White);
            mineCircleOptions.InvokeZIndex(200);

            // Set antimine overlay options
            antiMineTriangleOptions = new PolygonOptions();
            antiMineTriangleOptions.Add(new LatLng(((double)cell.Latitude + ((double)GameModel.FrontierInterval) * .75), ((double)cell.Longitude + (double)GameModel.FrontierInterval / 2)));
            antiMineTriangleOptions.Add(new LatLng(((double)cell.Latitude + ((double)GameModel.FrontierInterval) * .25), ((double)cell.Longitude + (double)GameModel.FrontierInterval * .25)));
            antiMineTriangleOptions.Add(new LatLng(((double)cell.Latitude + ((double)GameModel.FrontierInterval) * .25), ((double)cell.Longitude + (double)GameModel.FrontierInterval * .75)));
            antiMineTriangleOptions.InvokeStrokeWidth(6);
            antiMineTriangleOptions.InvokeStrokeColor(Color.White);
            antiMineTriangleOptions.InvokeZIndex(200);

            UpdateColor(cell.HoldStrength, cell.TeamID);
            cellPolygonOptions.InvokeStrokeWidth(0);

            if (cell.TeamID == GameModel.Player.Team.ID)
            {
                MapOverlayClickHandler = new FriendlyOverlayClickHandler();
            }
            else
            {
                MapOverlayClickHandler = new EnemyOverlayClickHandler();
            }
        }
Exemple #11
0
        private void DrawPolygon()
        {
            PolygonOptions polygonOptions = GetPolygoneRenderer();

            foreach (var position in _shapeCoordinates)
            {
                polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
            }
            _polygon = NativeMap.AddPolygon(polygonOptions);
        }
Exemple #12
0
        public async void OnMapReady(GoogleMap googleMap)
        {
            float lat = (float)coordinates.Latitude;
            float lng = (float)coordinates.Longitude;

            LatLng coords = new LatLng(lat, lng);

            CameraPosition cameraPosition;

            using (CameraPosition.Builder builder = new CameraPosition.Builder())
            {
                builder.Zoom(12);
                builder.Target(coords);
                cameraPosition = builder.Build();
            }

            this.googleMap = googleMap;

            this.googleMap.MoveCamera(CameraUpdateFactory.NewCameraPosition(cameraPosition));
            this.googleMap.MapType = 3;

            this.googleMap.InfoWindowLongClick += GoogleMap_InfoWindowLongClick;

            MarkerOptions myLocationMarker = new MarkerOptions();

            myLocationMarker.SetPosition(new LatLng(lat, lng));
            myLocationMarker.SetTitle("My location");
            this.googleMap.AddMarker(myLocationMarker);

            var airScraper = new AirspaceScraper(lng, lat, 120);

            airspace = await airScraper.ScrapeAsync();

            hashes = new string[airspace.NOTAMZones.Length];

            for (int x = 0; x < airspace.NOTAMZones.Length; x++)
            {
                PolygonOptions polygonOptions = new PolygonOptions();
                for (int i = 0; i < airspace.NOTAMZones[x].Polypoints.Length; i++)
                {
                    polygonOptions.Add(new LatLng(airspace.NOTAMZones[x].Polypoints[i].Latitude, airspace.NOTAMZones[x].Polypoints[i].Longitude));
                }

                hashes[x] = $"{airspace.NOTAMZones[x].Latitude}{airspace.NOTAMZones[x].Longitude}";

                MarkerOptions notamMarker = new MarkerOptions();
                notamMarker.SetPosition(new LatLng(airspace.NOTAMZones[x].Latitude, airspace.NOTAMZones[x].Longitude));
                notamMarker.SetTitle($"{airspace.NOTAMZones[x].Reference} - {airspace.NOTAMZones[x].Meaning}");
                this.googleMap.AddMarker(notamMarker);

                this.googleMap.AddPolygon(polygonOptions);
            }
        }
        //add polygon shape to map
        public void addShape()
        {
            PolygonOptions polygonOptions = new PolygonOptions();

            polygonOptions.InvokeFillColor(0x66D0D0FF); //D0D0FF //00C8FF
            polygonOptions.InvokeStrokeColor(0x660000FF);
            polygonOptions.InvokeStrokeWidth(10.0f);

            foreach (var position in shapeCoordinates)
            {
                polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
            }
            polygon = NativeMap.AddPolygon(polygonOptions);
            NativeMap.MapLongClick += longClick;
        }
        protected override void OnMapReady(Android.Gms.Maps.GoogleMap map)
        {
            base.OnMapReady(map);

            var polygonOptions = new PolygonOptions();

            polygonOptions.InvokeFillColor(0x66FF0000);
            polygonOptions.InvokeStrokeColor(0x660000FF);
            polygonOptions.InvokeStrokeWidth(30.0f);

            foreach (var position in shapeCoordinates)
            {
                polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
            }
            NativeMap.AddPolygon(polygonOptions);
        }
        private void OnGoogleMapReady()
        {
            var element = (ExtendedMap)Element;

            NativeMap.SetOnInfoWindowClickListener(this);

            if (element.ItemsSource != null)
            {
                LoadPins(element);
            }

            if (element.Coverages != null)
            {
                foreach (Logic.Models.Domain.Polygon coverage in Coverages)
                {
                    int            inCB    = 0x66129EE0;
                    int            outCB   = 0x6601456B;
                    PolygonOptions polygon = new PolygonOptions();
                    if (coverage.CoverageCode == "CB")
                    {
                        polygon.InvokeFillColor(inCB);
                    }
                    else
                    {
                        polygon.InvokeFillColor(outCB);
                    }
                    polygon.InvokeStrokeColor(0x660000FF);
                    polygon.InvokeStrokeWidth(1);

                    if (coverage.Points != null)
                    {
                        bool Point = false;
                        foreach (Logic.Models.Domain.Point position in coverage.Points)
                        {
                            polygon.Add(new LatLng(position.Latitude, position.Longitude));
                            Point = true;
                        }
                        if (Point)
                        {
                            NativeMap.AddPolygon(polygon);
                        }
                    }
                }
            }

            isDrawn = true;
        }
Exemple #16
0
        public void OnMapReady(GoogleMap googleMap)
        {
            map = googleMap;

            var polygonOptions = new PolygonOptions();

            polygonOptions.InvokeFillColor(0x66FF0000);
            polygonOptions.InvokeStrokeColor(0x660000FF);
            polygonOptions.InvokeStrokeWidth(30.0f);

            foreach (var position in shapeCoordinates)
            {
                polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
            }

            map.AddPolygon(polygonOptions);
        }
        protected override void DrawSearchAreaPolygon(Geoposition[] polygonData)
        {
            Color color = FormsMap.SearchPolygonColor.ToAndroid();

            var polygonOptions = new PolygonOptions();

            polygonOptions.InvokeFillColor(color);
            polygonOptions.InvokeStrokeColor(color);
            polygonOptions.InvokeStrokeWidth(1.0f);

            foreach (var position in polygonData)
            {
                var nativeCoordinate = CoordinateConverter.ConvertToNative(position);
                polygonOptions.Add(nativeCoordinate);
            }

            _currentSearchPolygon = _nativeMap.AddPolygon(polygonOptions);
        }
Exemple #18
0
        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
            {
                var polygonOptions = new PolygonOptions();
                polygonOptions.InvokeFillColor(0x66FF0000);
                polygonOptions.InvokeStrokeColor(0x660000FF);
                polygonOptions.InvokeStrokeWidth(30.0f);

                foreach (var position in shapeCoordinates)
                {
                    polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
                }
                NativeMap.AddPolygon(polygonOptions);
                isDrawn = true;
            }
        }
        public void SetPolygon(LatLng[] vertices)
        {
            Log.Debug("SetPolygon", "Setting polygon positions");

            PolygonOptions polygon = new PolygonOptions();

            for (int i = 0; i < vertices.Length; i++)
            {
                polygon.Add(vertices[i]);
            }

            if (setActivity.setPlayArea.polygon == null)
            {
                BuildPolygon(polygon);
            }
            else
            {
                setActivity.setPlayArea.polygon.Points = vertices;
            }
        }
        protected override NativePolygon CreateNativeItem(Polygon outerItem)
        {
            var opts = new PolygonOptions();

            foreach (var p in outerItem.Positions)
            {
                opts.Add(new LatLng(p.Latitude, p.Longitude));
            }

            opts.InvokeStrokeWidth(outerItem.StrokeWidth * this.ScaledDensity); // TODO: convert from px to pt. Is this collect? (looks like same iOS Maps)
            opts.InvokeStrokeColor(outerItem.StrokeColor.ToAndroid());
            opts.InvokeFillColor(outerItem.FillColor.ToAndroid());
            opts.Clickable(outerItem.IsClickable);
            opts.InvokeZIndex(outerItem.ZIndex);

            foreach (var hole in outerItem.Holes)
            {
                opts.Holes.Add(hole.Select(x => x.ToLatLng()).ToJavaList());
            }

            var nativePolygon = NativeMap.AddPolygon(opts);

            // associate pin with marker for later lookup in event handlers
            outerItem.NativeObject = nativePolygon;
            outerItem.SetOnPositionsChanged((polygon, e) =>
            {
                var native    = polygon.NativeObject as NativePolygon;
                native.Points = polygon.Positions.ToLatLngs();
            });

            // FIXME workarround for #280
            //outerItem.SetOnHolesChanged((polygon, e) =>
            //{
            //    var native = polygon.NativeObject as NativePolygon;
            //    native.Holes = (IList<IList<LatLng>>)polygon.Holes
            //        .Select(x => (IList<LatLng>)x.Select(y=>y.ToLatLng()).ToJavaList())
            //        .ToJavaList();
            //});

            return(nativePolygon);
        }
Exemple #21
0
        //1 клик по маркеру
        private void mMap_MarkerClick(object sender, GoogleMap.MarkerClickEventArgs e)
        {
            LatLng pos = e.Marker.Position;

            if (arrayPointX[polygonCount].Count > 2 && pos.Latitude == arrayPointX[polygonCount][0] && pos.Longitude == arrayPointY[polygonCount][0])
            {
                rectangle = new PolygonOptions()
                            .InvokeFillColor(Color.ForestGreen.ToArgb())
                            .InvokeZIndex(10);
                for (int i = 0; i < arrayPointX[polygonCount].Count; i++)
                {
                    rectangle.Add(new LatLng(arrayPointX[polygonCount][i], arrayPointY[polygonCount][i]));
                }
                polygone             = mMap.AddPolygon(rectangle);
                polygone.StrokeWidth = 2;
                polygonCount++;
                arrayPointX.Add(new List <double>());
                arrayPointY.Add(new List <double>());
                Toast.MakeText(this, "Зажмите на области поля", ToastLength.Long).Show();
            }
        }
Exemple #22
0
        /// <summary>
        /// Adds a polygon to the map
        /// </summary>
        /// <param name="polygon">The polygon to add</param>
        private void AddPolygon(TKPolygon polygon)
        {
            polygon.PropertyChanged += OnPolygonPropertyChanged;

            var polygonOptions = new PolygonOptions();

            if (polygon.Coordinates != null && polygon.Coordinates.Any())
            {
                polygonOptions.Add(polygon.Coordinates.Select(i => i.ToLatLng()).ToArray());
            }
            if (polygon.Color != Color.Default)
            {
                polygonOptions.InvokeFillColor(polygon.Color.ToAndroid().ToArgb());
            }
            if (polygon.StrokeColor != Color.Default)
            {
                polygonOptions.InvokeStrokeColor(polygon.StrokeColor.ToAndroid().ToArgb());
            }
            polygonOptions.InvokeStrokeWidth(polygonOptions.StrokeWidth);

            this._polygons.Add(polygon, this._googleMap.AddPolygon(polygonOptions));
        }
        public void AddPolygon(View view)
        {
            if (null == hMap)
            {
                return;
            }
            if (null != mPolygon)
            {
                mPolygon.Remove();
            }

            PolygonOptions polygonOptions  = new PolygonOptions();
            var            rectangleLatLng = MapUtils.CreateRectangle(new LatLng(48.893478, 2.334595), 0.1, 0.1);

            foreach (LatLng item in rectangleLatLng)
            {
                polygonOptions.Add(item);
            }
            polygonOptions.InvokeFillColor(Color.Green).InvokeStrokeColor(Color.Black);
            mPolygon = hMap.AddPolygon(polygonOptions);
            hMap.SetOnPolygonClickListener(this);
        }
Exemple #24
0
        protected override void OnMapReady(GoogleMap map)
        {
            base.OnMapReady(map);

            foreach (var worksite in worksites)
            {
                var polygonOptions = new PolygonOptions();
                polygonOptions.InvokeFillColor(unchecked ((int)0xFF00FFFF));
                polygonOptions.InvokeStrokeColor(unchecked ((int)0xFF0000FF));
                polygonOptions.InvokeStrokeWidth(10.0f);

                foreach (var position in worksite.GeneratePolygonPositions())
                {
                    polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
                }

                if (polygonOptions.Points.Count > 0)
                {
                    var worksitePoly = new WorksitePolygon {
                        Worksite = worksite, Polygon = polygonOptions
                    };
                    polygons.Add(worksitePoly);
                    var polygon = NativeMap.AddPolygon(worksitePoly.Polygon);
                    polygon.Clickable = true;
                }
            }

            map.PolygonClick += (sender, e) => {
                var poly           = e.Polygon;
                var targetWorksite = polygons.FirstOrDefault(x => x.Polygon.PointsId() == poly.PointsId());

                if (targetWorksite != null)
                {
                    App.WorksiteLabel.Text      = targetWorksite.Worksite.name;
                    App.WorksiteLabel.IsVisible = true;
                }
            };
        }
Exemple #25
0
        protected override void OnMapReady(GoogleMap map)
        {
            var bottom = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics);
            var left   = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics);
            var right  = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics);
            var top    = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 48, Resources.DisplayMetrics);

            map.SetPadding(left, top, right, bottom);
            map.SetMapStyle(MapStyleOptions.LoadRawResourceStyle(Context, Resource.Raw.my_map_customization));
            map.InfoWindowClick += OnInfoWindowClick;
            map.SetInfoWindowAdapter(this);

//            var latLng = new LatLng(Communities.LagosLatitude, Communities.LagosLongitude);
//            CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
//            builder.Target(latLng);
//            builder.Zoom(15);
//            CameraPosition cameraPosition = builder.Build();
//            CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
//            map.MoveCamera(cameraUpdate);

            base.OnMapReady(map);
            MapReady?.Invoke(this);
            LocationAccessChanged(MainActivity.IsLocationAccessGranted);
            LocationSettingsChanged(MainActivity.IsLocationEnabled);
            NativeMap.UiSettings.ZoomControlsEnabled = false;

            var cuPolygonOptions = new PolygonOptions();

            cuPolygonOptions.InvokeStrokeColor(Android.Graphics.Color.Argb(255, 219, 62, 68));
            cuPolygonOptions.InvokeStrokeWidth(15.0f);
            foreach (Community cyclesCommunity in Communities.CyclesCommunities)
            {
                cyclesCommunity.PolygonCoordinates.ForEach(lng => { cuPolygonOptions.Add(lng); });
                NativeMap.AddPolygon(cuPolygonOptions).Tag = cyclesCommunity.ShortName;
            }
        }
Exemple #26
0
        public void SetPolygon(LinkedList <LatLng> vertices)
        {
            Log.Debug("SetPolygon", "Setting polygon positions");

            PolygonOptions polygon = new PolygonOptions();

            LinkedListNode <LatLng> verticesNode = vertices.First;

            while (true)
            {
                polygon.Add(verticesNode.Value);

                if (verticesNode.Next != null)
                {
                    verticesNode = verticesNode.Next;
                }
                else
                {
                    break;
                }
            }

            BuildPolygon(polygon);
        }
        private void OnUpdateHighlight()
        {
            var highlightableMap = (HighlightableMap)Element;

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

            NativeMap.Clear();

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

            var fillColor       = highlightableMap.Highlight.FillColor.ToAndroid().ToArgb();
            var strokeColor     = highlightableMap.Highlight.StrokeColor.ToAndroid().ToArgb();
            var strokeThickness = highlightableMap.Highlight.StrokeThickness;

            foreach (var polygon in highlightableMap.Highlight.Polygons)
            {
                var polygonOptions = new PolygonOptions();

                polygonOptions.InvokeFillColor(fillColor);
                polygonOptions.InvokeStrokeColor(strokeColor);
                polygonOptions.InvokeStrokeWidth(strokeThickness);

                foreach (var position in polygon.Positions)
                {
                    polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
                }

                NativeMap.AddPolygon(polygonOptions);
            }
        }
        private void LoadPlacemarks()
        {
            _Placemarks = new Dictionary <string, Placemark>();

            List <LatLng> points = new List <LatLng>();

            foreach (Placemark place in _Kml.Placemarks)
            {
                if (place.Type == PlacemarkType.Point)
                {
                    MarkerOptions mapOption = new MarkerOptions()
                                              .SetPosition(new LatLng(place.Coordinates[0][0], place.Coordinates[0][1]))
                                              //.SetSnippet(String.Format("{0}", desc))
                                              .SetTitle(String.Format("{0}", place.Name));

                    if (!place.Style.IconPath.StartsWith("http"))
                    {
                        var img = BitmapDescriptorFactory.FromPath(System.IO.Path.Combine(_Kml.BasePath, place.Style.IconPath));
                        mapOption.InvokeIcon(img);
                    }

                    Marker mark = _GoogleMap.AddMarker(mapOption);

                    _Placemarks.Add(mark.Id, place);

                    points.Add(mark.Position);
                }
                else if (place.Type == PlacemarkType.Polyline)
                {
                    PolylineOptions options = new PolylineOptions()
                                              .Visible(true)
                                              .InvokeColor(Android.Graphics.Color.Transparent.FromHexA(place.Style.LineColor))
                                              .InvokeWidth(place.Style.LineWidth);

                    foreach (var c in place.Coordinates)
                    {
                        options.Add(new LatLng(c[0], c[1]));
                    }

                    var line = _GoogleMap.AddPolyline(options);
                    points.AddRange(line.Points);
                }
                else if (place.Type == PlacemarkType.Polygon)
                {
                    PolygonOptions options = new PolygonOptions()
                                             .Visible(true)
                                             .InvokeStrokeColor(Android.Graphics.Color.Transparent.FromHexA(place.Style.LineColor))
                                             .InvokeFillColor(Android.Graphics.Color.Transparent.FromHexA(place.Style.FillColor))
                                             .InvokeStrokeWidth(place.Style.LineWidth);

                    foreach (var c in place.Coordinates)
                    {
                        options.Add(new LatLng(c[0], c[1]));
                    }

                    var poly = _GoogleMap.AddPolygon(options);

                    points.AddRange(poly.Points);
                }
            }

            SetPointsBounds(points);

            if (_Kml.Placemarks.Count == 0)
            {
                _GoogleMap.MyLocationChange += MapOnLocationChange;
            }
        }
Exemple #29
0
        public void OnMapReady(GoogleMap googleMap)
        {
            JMCdrone
            .SetPosition(latLongJMCdrone)
            .SetTitle("YMFCdrone")
            .SetSnippet(latLongJMCdrone.ToString())
            .SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.JMCdroneIcon));

            if (addWayPointCounter == 0 || number_used_sats == 0)
            {
                googleMap.Clear();
                googleMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(latLongJMCdrone, 0));
                jmcMarker = googleMap.AddMarker(JMCdrone);
            }

            if (floatingButton2_clicked && addWayPointCounter < wayPointArray.Length - 1)
            {
                floatingButton2_clicked = false;
                if (number_used_sats <= minSats)
                {
                    addWayPointCounter = 0;
                    googleMap.Clear();
                    jmcMarker = googleMap.AddMarker(JMCdrone);
                    floatingButton2_clicked_counter = 0;
                    Toast.MakeText(this, "not enough satelities", ToastLength.Long).Show();
                }
                else
                {
                    googleMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(latLongJMCdrone, zoom));

                    if (floatingButton2_clicked_counter == 1)
                    {
                        addWayPointCounter++;

                        MarkerOptions newMarker = new MarkerOptions()
                                                  .SetPosition(latLongJMCdrone)
                                                  .SetSnippet(latLongJMCdrone.ToString())
                                                  .SetTitle("wp_" + addWayPointCounter.ToString())
                                                  .Draggable(true)
                                                  .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed));


                        googleMap.AddMarker(newMarker).ShowInfoWindow();
                        wayPointArray[addWayPointCounter] = latLongJMCdrone;
                    }
                }
            }
            if (boolDragEnd)
            {
                boolDragEnd = false;
                floatingButton2_clicked_counter = 0;
                googleMap.Clear();
                jmcMarker = googleMap.AddMarker(JMCdrone);
                googleMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(latLongJMCdrone, zoom));

                wPpolygon.Points.Clear();
                wPpolygon.InvokeStrokeWidth(7f);
                wPpolygon.InvokeStrokeColor(Color.DarkRed.ToArgb());
                wPpolygon.InvokeFillColor(0x330000FF);
                for (int i = 0; i < addWayPointCounter + 1; i++)
                {
                    wPpolygon.Add(wayPointArray[i]);
                }
                googleMap.AddPolygon(wPpolygon);

                for (int i = 1; i < addWayPointCounter + 1; i++)
                {
                    marker
                    .SetPosition(wayPointArray[i])
                    .SetTitle("wp_" + (i).ToString())
                    .SetSnippet(((float)DistanceTo(wayPointArray[i - 1].Latitude, wayPointArray[i - 1].Longitude, wayPointArray[i].Latitude, wayPointArray[i].Longitude)).ToString("F1") + " meters")
                    .Draggable(true)
                    .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed));

                    googleMap.AddMarker(marker).ShowInfoWindow();
                }
            }
            if (flight_mode <= 9 && flight_mode >= 5)
            {
                if (startMission == 0)
                {
                    googleMap.Clear();
                    googleMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(latLongJMCdrone, zoom));
                    if (jmcMarker != null)
                    {
                        jmcMarker.Remove();
                    }
                    JMCdrone
                    .SetPosition(latLongJMCdrone)
                    .SetTitle("Distance to " + "wp_" + flyWayPointCounter.ToString())
                    .SetSnippet(((float)DistanceTo(latLongJMCdrone.Latitude, latLongJMCdrone.Longitude, wayPointArray[flyWayPointCounter].Latitude, wayPointArray[flyWayPointCounter].Longitude)).ToString("F1") + " meters")
                    .SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.JMCdroneIcon));

                    jmcMarker = googleMap.AddMarker(JMCdrone);
                    jmcMarker.ShowInfoWindow();

                    home
                    .SetPosition(homeLatLong)
                    .SetTitle("HOME")
                    .SetSnippet("jmcHome")
                    .Draggable(false)
                    .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueAzure));

                    googleMap.AddMarker(home);
                    for (int i = 1; i < addWayPointCounter + 1; i++)
                    {
                        marker
                        .SetPosition(wayPointArray[i])
                        .SetTitle("waypoint" + (i).ToString())
                        .Draggable(true)
                        .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueBlue));

                        googleMap.AddMarker(marker);
                    }
                    startMission = 1;
                    floatingButton2_clicked_counter = 0;
                    wPpolygon.Points.Clear();
                    wPpolygon.InvokeStrokeWidth(1f);
                    wPpolygon.InvokeStrokeColor(Color.DarkGreen.ToArgb());
                    wPpolygon.InvokeFillColor(0x33000011);
                    for (int i = 0; i < addWayPointCounter + 1; i++)
                    {
                        wPpolygon.Add(wayPointArray[i]);
                    }
                    googleMap.AddPolygon(wPpolygon);
                }
                else
                {
                    if (jmcMarker != null)
                    {
                        jmcMarker.Remove();
                    }
                    JMCdrone
                    .SetPosition(latLongJMCdrone)
                    .SetTitle("Distance to " + "wp_" + flyWayPointCounter.ToString())
                    .SetSnippet(((float)DistanceTo(latLongJMCdrone.Latitude, latLongJMCdrone.Longitude, wayPointArray[flyWayPointCounter].Latitude, wayPointArray[flyWayPointCounter].Longitude)).ToString("F1") + " meters");

                    jmcMarker = googleMap.AddMarker(JMCdrone);
                    jmcMarker.ShowInfoWindow();
                }
            }
            if (addWayPointCounter == wayPointArray.Length - 1)
            {
                addWayPointCounter = 0;
                floatingButton2_clicked_counter = 0;
                flyWayPointCounter = 0;
                startMission       = 0;
                googleMap.Clear();
                googleMap.AddMarker(JMCdrone);
                floatingButton4_clicked = false;
                floatingButton3.Show();
            }
            googleMap.MarkerDragEnd += GoogleMap_MarkerDragEnd;
        }
        public async void OnMapReady(GoogleMap map)
        {
            mmap = map;

            mmap.MyLocationEnabled = true;
            mmap.MapType           = GoogleMap.MapTypeHybrid;
            mmap.UiSettings.ZoomControlsEnabled = true;

            //Set the farm positions
            PolygonOptions rectOptions = new PolygonOptions();

            rectOptions.Add(new LatLng(11.838600285438176, 75.62577920991211));
            rectOptions.Add(new LatLng(11.83865591985375, 75.62651107020247));
            rectOptions.Add(new LatLng(11.838092620878797, 75.6262055362958));
            rectOptions.Add(new LatLng(11.838092620881227, 75.62620529054104));
            rectOptions.Add(new LatLng(11.838252570075255, 75.6257434369438));
            rectOptions.Add(new LatLng(11.838600285438176, 75.62577920991211));

            // Market settings
            rectOptions.InvokeFillColor(int.Parse("6ca5ce59", System.Globalization.NumberStyles.HexNumber));
            rectOptions.InvokeStrokeWidth(1);

            // Add polygon to map
            mmap.AddPolygon(rectOptions);

            // Set the current camera position
            CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
            builder.Zoom(19);
            LatLng tempLocation = new LatLng(11.83865591985375, 75.6262055362958);

            builder.Target(tempLocation);
            CameraPosition cameraPosition = builder.Build();
            CameraUpdate   cameraUpdate   = CameraUpdateFactory.NewCameraPosition(cameraPosition);

            mmap.MoveCamera(cameraUpdate);

            // Get weather details
            Weather weather = await GetWeather(11.83865591985375, 75.6262055362958);

            TextView weatherTV   = FindViewById <TextView>(Resource.Id.weather);
            TextView temperature = FindViewById <TextView>(Resource.Id.temperature);
            TextView wind        = FindViewById <TextView>(Resource.Id.wind);
            TextView humidity    = FindViewById <TextView>(Resource.Id.humidity);
            TextView visibility  = FindViewById <TextView>(Resource.Id.visibility);

            // Set weather details
            weatherTV.Text   = weather.Description;
            temperature.Text = weather.Temperature;
            wind.Text        = weather.Wind;
            humidity.Text    = weather.Humidity;
            visibility.Text  = weather.Visibility;

            // Set Status image
            var temperatureSummaryStatus = FindViewById <ImageView>(Resource.Id.temperatureSummaryStatus);

            temperatureSummaryStatus.SetImageResource(Resource.Drawable.toggle_checked);

            var soilSummaryStatus = FindViewById <ImageView>(Resource.Id.soilSummaryStatus);

            soilSummaryStatus.SetImageResource(Resource.Drawable.toggle_checked);

            var areaSummaryStatus = FindViewById <ImageView>(Resource.Id.areaSummaryStatus);

            areaSummaryStatus.SetImageResource(Resource.Drawable.toggle_checked);
        }