Пример #1
0
        private void PolylineDemo(HuaweiMap hMap)
        {
            hMap.Clear();

            Polyline        polyline1;
            PolylineOptions polyline1Options = new PolylineOptions()
                                               .Add(new LatLng(41.01929, 28.967267), new LatLng(41.016785, 28.986971), new LatLng(41.001917, 28.978743), new LatLng(41.002298, 28.954132));

            polyline1Options.InvokeColor(Color.Blue);
            polyline1Options.InvokeWidth(20);
            // polyline1Options.InvokeZIndex(2);
            polyline1Options.Visible(false);
            polyline1Options.Clickable(true);
            polyline1 = hMap.AddPolyline(polyline1Options);


            Polyline        polyline2;
            PolylineOptions polyline2Options = new PolylineOptions()
                                               .Add(new LatLng(41.010410, 28.978511), new LatLng(41.035243, 29.026812), new LatLng(41.022122, 29.00653), new LatLng(41.00415, 29.012449), new LatLng(41.001699, 28.978743));

            polyline2Options.InvokeColor(Color.Red);
            polyline1Options.InvokeZIndex(1);
            polyline2Options.Clickable(true);
            polyline2 = hMap.AddPolyline(polyline2Options);
        }
Пример #2
0
        protected override NativePolyline CreateNativeItem(Polyline outerItem)
        {
            var opts = new PolylineOptions();

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

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

            var nativePolyline = NativeMap.AddPolyline(opts);

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

            return(nativePolyline);
        }
Пример #3
0
        private PolylineOptions CreatePolylineOptions(MapPolyline polyline)
        {
            var op = new PolylineOptions();

            op.InvokeColor(polyline.Color.ToAndroid().ToArgb());
            op.InvokeWidth((float)polyline.Width);
            op.InvokeZIndex(polyline.ZIndex);
            return(op);
        }
Пример #4
0
        private static PolylineOptions CloneOptions(PolylineOptions op)
        {
            var options = new PolylineOptions();

            options.InvokeColor(op.Color);
            options.InvokeWidth(op.Width);
            options.InvokeZIndex(op.ZIndex);
            return(options);
        }
Пример #5
0
 /// <summary>
 /// Draw line from active location to active object, if it is a zone.
 /// </summary>
 void UpdateDistanceLine()
 {
     if (activeObject != null && activeObject is Zone)
     {
         if (activeObject is Zone && ((Zone)activeObject).State != PlayerZoneState.Inside)
         {
             if (distanceLine == null)
             {
                 // Draw line
                 PolylineOptions po = new PolylineOptions();
                 po.Points.Add(new LatLng(Main.GPS.Location.Latitude, Main.GPS.Location.Longitude));
                 po.Points.Add(new LatLng(((Zone)activeObject).ObjectLocation.Latitude, ((Zone)activeObject).ObjectLocation.Longitude));                           //.ObjectLocation.Latitude, ((Zone)activeObject).ObjectLocation.Longitude));
                 po.InvokeColor(Color.Cyan);
                 po.InvokeWidth(4);
                 po.InvokeZIndex(2);
                 distanceLine = _map.AddPolyline(po);
             }
             else
             {
                 // Set new line points
                 List <LatLng> points = new List <LatLng>(2);
                 points.Add(new LatLng(Main.GPS.Location.Latitude, Main.GPS.Location.Longitude));
                 points.Add(new LatLng(((Zone)activeObject).ObjectLocation.Latitude, ((Zone)activeObject).ObjectLocation.Longitude));                           //.ObjectLocation.Latitude, ((Zone)activeObject).ObjectLocation.Longitude));
                 distanceLine.Points = points;
             }
         }
         else
         {
             // Delete line
             if (distanceLine != null)
             {
                 distanceLine.Remove();
                 distanceLine = null;
             }
         }
     }
     else
     {
         // Delete line
         if (distanceLine != null)
         {
             distanceLine.Remove();
             distanceLine = null;
         }
     }
 }
Пример #6
0
        private void AddPolyline(Polyline polyline)
        {
            PolylineOptions options = new PolylineOptions();

            options.Add(polyline.Points.Select(p => new LatLng(p.Latitude, p.Longitude)).ToArray());
            if (polyline.ZIndex.HasValue)
            {
                options.InvokeZIndex(polyline.ZIndex.Value);
            }
            if (polyline.StrokeColor != null)
            {
                options.InvokeColor(Graphics.Color.ParseColor(polyline.StrokeColor));
            }
            if (polyline.StrokeWidth.HasValue)
            {
                options.InvokeWidth(polyline.StrokeWidth.Value);
            }
            googleMap.AddPolyline(options);
        }
Пример #7
0
        public void DrawLineBetweenPins()
        {
            #region Bind Pin Numbers
            for (int i = 0; i < customPins.Count; i++)
            {
                var marker = new MarkerOptions();
                marker.SetPosition(new LatLng(customPins[i].Position.Latitude, customPins[i].Position.Longitude));

                if (i == 0)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_1));
                }
                else if (i == 1)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_2));
                }
                else if (i == 2)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_3));
                }
                else if (i == 3)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_4));
                }
                else if (i == 4)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_5));
                }
                else if (i == 5)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_6));
                }
                else if (i == 6)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_7));
                }
                else if (i == 7)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_8));
                }
                else if (i == 8)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_9));
                }
                else if (i == 9)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_10));
                }
                else if (i == 10)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_11));
                }
                else if (i == 11)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_12));
                }
                else if (i == 12)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_11));
                }
                else if (i == 13)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_12));
                }
                else if (i == 14)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_13));
                }
                else if (i == 15)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_14));
                }
                else if (i == 16)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_15));
                }
                else if (i == 17)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_16));
                }
                else if (i == 18)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_17));
                }
                else if (i == 19)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_18));
                }
                else if (i == 20)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_19));
                }
                else
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_20));
                }

                marker.SetTitle(customPins[i].Label);
                marker.SetSnippet(customPins[i].Address);
                //marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.route_pin_1));

                NativeMap.AddMarker(marker);
            }
            #endregion
            var polylineOptions = new PolylineOptions();
            polylineOptions.InvokeColor(0x662873DD);
            polylineOptions.InvokeZIndex(5);
            polylineOptions.InvokeWidth(7);

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

            NativeMap.AddPolyline(polylineOptions);
        }
        /// <summary>
        /// Add new point to the polyline
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">User's new position</param>
        private void Model_NewPosition(object sender, PositionArgs e)
        {
            var position = new LatLng(e.LocationData.Latitude, e.LocationData.Longitude);

            // Refresh texts
            _speedTextView.Text    = Math.Round(e.LocationData.Speed, 2).ToString(CultureInfo.InvariantCulture);
            _sumDistance           = _sumDistance + e.LocationData.Distance;
            _distanceTextView.Text = Math.Round(_sumDistance, 2).ToString(CultureInfo.InvariantCulture);

            // Add new line
            if (e.LocationData.RunningSpeedType != _lastRunningSpeedType)
            {
                LatLng lastPosition = null;

                if (_previousStateOfCurrentPolyline != null)
                {
                    lastPosition = _polylineOptions.Points.Last();
                }

                _previousStateOfCurrentPolyline = null;
                _lastRunningSpeedType           = e.LocationData.RunningSpeedType;

                _polylineOptions = new PolylineOptions();

                switch (e.LocationData.RunningSpeedType)
                {
                case RunningSpeed.Slow:
                    _polylineOptions.InvokeColor(Color.Rgb(238, 163, 54));
                    break;

                case RunningSpeed.Normal:
                    _polylineOptions.InvokeColor(Color.Rgb(51, 127, 192));
                    break;

                case RunningSpeed.Fast:
                    _polylineOptions.InvokeColor(Color.Rgb(33, 175, 95));
                    break;

                case RunningSpeed.StartPoint:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                _polylineOptions.InvokeZIndex(5);

                if (lastPosition != null)
                {
                    _polylineOptions.Add(lastPosition);
                }
            }
            _polylineOptions.Add(position);

            // Drawing the line
            var timer = new Timer();

            timer.Interval = Model.GpsMinTime / 2;
            timer.Elapsed += (o, args) =>
            {
                RunOnUiThread(() =>
                {
                    var currentPolyline = _map.AddPolyline(_polylineOptions);
                    _previousStateOfCurrentPolyline?.Remove();
                    _previousStateOfCurrentPolyline = currentPolyline;
                });
                timer.Stop();
            };
            timer.Start();
        }