Пример #1
0
        /// <summary>
        /// initializes the <see cref="MarkerOptions"/>
        /// </summary>
        /// <param name="markerOptions">Instance of the marker options</param>
        /// <param name="setPosition">if <value>true</value>, the position will be updated</param>
        /// <returns><see cref="Task"/></returns>
        public async Task InitializeMarkerOptionsAsync(MarkerOptions markerOptions, bool setPosition = true)
        {
            if (setPosition)
            {
                markerOptions.SetPosition(new LatLng(Pin.Position.Latitude, Pin.Position.Longitude));
            }

            if (!string.IsNullOrWhiteSpace(Pin.Title))
            {
                markerOptions.SetTitle(Pin.Title);
            }
            if (!string.IsNullOrWhiteSpace(Pin.Subtitle))
            {
                markerOptions.SetSnippet(Pin.Subtitle);
            }

            await UpdateImageAsync(markerOptions);

            markerOptions.Draggable(Pin.IsDraggable);
            markerOptions.Visible(Pin.IsVisible);
            markerOptions.SetRotation((float)Pin.Rotation);
            if (Pin.Image != null)
            {
                markerOptions.Anchor((float)Pin.Anchor.X, (float)Pin.Anchor.Y);
            }
        }
        /// <summary>
        /// Creates a pin and sets the icon of it according to what type of pin it is.
        /// If it is a ship pin, it rotates the pin according to the direction of the ship
        /// </summary>
        /// <param name="pin">The pin that will be created</param>
        /// <returns>The MarkerOptions for the pin</returns>
        protected override MarkerOptions CreateMarker(Pin pin)
        {
            var marker = new MarkerOptions();

            marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
            marker.SetTitle(pin.Label);
            marker.SetSnippet(pin.Address);
            if (!String.IsNullOrEmpty(pin.Address))
            {
                if (sharedData.SelectedShipId == int.Parse(pin.Address))
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.markedBoatIcon));
                }
                else
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.boaticon));
                }
                marker.SetRotation((sharedData.Direction) - rotationOffset);
            }
            else
            {
                if (pin.Label.ToLower().Equals("startline"))
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.startIconR));
                }
                else if (pin.Label.ToLower().Equals("finishline"))
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.finishiconR));
                }
            }
            return(marker);
        }
Пример #3
0
 private MarkerOptions CreateUserMarker()
 {
     userMarkerOptions = new MarkerOptions();
     userMarkerOptions.SetPosition(new LatLng(lastLocation?.Latitude ?? 30, lastLocation?.Longitude ?? 30));
     userMarkerOptions.SetTitle("UserPostion");
     userMarkerOptions.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.icono));
     userMarkerOptions.SetRotation((float)UnitConverters.DegreesToRadians(lastLocation?.Course ?? 0));
     return(userMarkerOptions);
 }
Пример #4
0
        public void TimerThread()
        {
            while (true)
            {
                var planes = Jsonloader(lat, lon, null);

                RunOnUiThread(() => {
                    mMap.Clear();
                    planesHash.Clear();
                    foreach (var r in planes["acList"])
                    {
                        Plane plane = new Plane();

                        plane.Lat  = (r["Lat"] == null)?0.0:r["Lat"];
                        plane.Lon  = (r["Long"] == null) ? 0.0:r["Long"];
                        plane.Mdl  = (r["Mdl"] == null) ? "":r["Mdl"];
                        plane.Trak = (r["Trak"] == null)?0.0:r["Trak"];
                        plane.Spd  = (r["Spd"] == null)?0.0:r["Spd"];
                        plane.Type = (r["Type"] == null)?"":r["Type"];
                        plane.To   = (r["To"] == null)?"":r["To"];
                        plane.From = (r["From"] == null)?"":r["From"];
                        plane.Icao = (r["Icao"] == null)?"":r["Icao"];

                        planesHash.Add(plane.Icao, plane);


                        MarkerOptions planemarker = new MarkerOptions();
                        planemarker.SetPosition(new LatLng(plane.Lat, plane.Lon));
                        planemarker.SetTitle(plane.Icao);
                        planemarker.SetRotation((float)plane.Trak);

                        planemarker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pl));
                        //planemarker.SetSnippet("hello");
                        // OnInfoWindowClick(planemarker);

                        mMap.AddMarker(planemarker);
                    }

                    MarkerOptions marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(lat, lon));
                    marker.SetTitle("U zelf");
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.p));

                    mMap.AddMarker(marker);
                });
                Thread.Sleep(5000);
            }
        }
        private void UpdateLocationPinHeading()
        {
            if (LocationHelper.IsGeoServiceAvailable)
            {
                var oldRotation = LocationMarkerOptions.Rotation;
                var newRotation = (float)AppMobileService.Locaion.CurrentHeading - 45 -
                                  (NativeMap.CameraPosition?.Bearing).GetValueOrDefault();

                if (Math.Abs(newRotation - oldRotation) > MapTile.MinCompassRotation)
                {
                    LocationMarkerOptions.SetRotation(newRotation);

                    if (LocationMarker != null)
                    {
                        LocationMarker.Rotation = newRotation;
                    }
                }
            }
        }
Пример #6
0
        private void desenharRadar(RadarPin radar)
        {
            var marker = new MarkerOptions();

            marker.SetPosition(new LatLng(radar.Pin.Position.Latitude, radar.Pin.Position.Longitude));
            marker.SetTitle(radar.Pin.Label);
            marker.SetSnippet(radar.Pin.Address);

            marker.SetRotation((float)radar.Sentido);
            switch (radar.Tipo)
            {
            case RadarTipoEnum.RadarFixo:
                marker.SetIcon(BitmapDescriptorFactory.FromAsset("radares/" + radar.Imagem));
                break;

            case RadarTipoEnum.SemaforoComRadar:
                marker.SetIcon(BitmapDescriptorFactory.FromAsset("radares/radar_40_semaforo.png"));
                break;

            case RadarTipoEnum.SemaforoComCamera:
                marker.SetIcon(BitmapDescriptorFactory.FromAsset("radares/semaforo.png"));
                break;

            case RadarTipoEnum.RadarMovel:
                marker.SetIcon(BitmapDescriptorFactory.FromAsset("radares/radar_movel.png"));
                break;

            case RadarTipoEnum.PoliciaRodoviaria:
                marker.SetIcon(BitmapDescriptorFactory.FromAsset("radares/policiarodoviaria.png"));
                break;

            case RadarTipoEnum.Lombada:
                marker.SetIcon(BitmapDescriptorFactory.FromAsset("radares/lombada.png"));
                break;

            case RadarTipoEnum.Pedagio:
                marker.SetIcon(BitmapDescriptorFactory.FromAsset("radares/pedagio.png"));
                break;
            }

            map.AddMarker(marker);
        }
Пример #7
0
        protected override MarkerOptions CreateMarker(Pin pin)
        {
            var marker = new MarkerOptions();

            marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
            marker.SetTitle(pin.Label);

            if (pin is CustomMapPin customMapPin)
            {
                if (customMapPin.IsSpeedPin)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.speed_icon));
                }

                if (customMapPin.IsJumpPin)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.jump_icon));
                }

                marker.SetRotation(customMapPin.Rotation);
            }

            return(marker);
        }
Пример #8
0
        async Task setCustomizeIcon(UbicacionDTO[] coordenadasArray, bool pubnubResponse)
        {
            await Task.Run(() => {
                int contador = 1;
                foreach (var coordenadas in coordenadasArray)
                {
                    LatLng ubicacion      = new LatLng((double)coordenadas.Latitud, (double)coordenadas.Longitud);
                    LastLocation newPoint = new LastLocation("", ubicacion);
                    bool mustLeaveIcon1KM = (lastMarkerPubNub != null && lastPointMarker1KM.DistanceTo(newPoint) > 500);
                    int ResourceIDFlechas;
                    int ResourceIDCarro;
                    var marker = new MarkerOptions();

                    if (coordenadas.Velocidad > 90)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Marron;
                        ResourceIDCarro   = Resource.Drawable.icono_rojo;
                    }
                    else if (coordenadas.Velocidad <= 90 && coordenadas.Velocidad > 70)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Rosada;
                        ResourceIDCarro   = Resource.Drawable.icono_rosado;
                    }
                    else if (coordenadas.Velocidad <= 70 && coordenadas.Velocidad > 40)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Verde;
                        ResourceIDCarro   = Resource.Drawable.icono_verde;
                    }
                    else if (coordenadas.Velocidad <= 40 && coordenadas.Velocidad > 10)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Aqua;
                        ResourceIDCarro   = Resource.Drawable.icono_azul_claro;
                    }
                    else if (coordenadas.Velocidad <= 10 && coordenadas.Velocidad > 1)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Azul;
                        ResourceIDCarro   = Resource.Drawable.icono_azul_oscuro;
                    }
                    else
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Morada;
                        ResourceIDCarro   = Resource.Drawable.icono_morado;
                    }

                    marker.SetPosition(ubicacion);
                    marker.SetRotation((float)coordenadas.Bearing);
                    marker.Anchor(0.5f, 0.5f);
                    marker.SetTitle(coordenadas.Nombre_Usuario);
                    marker.SetSnippet("Tiempo: " + coordenadas.Tiempo + "*Latitud: " + coordenadas.Latitud + "*Longitud: " + coordenadas.Longitud + "*Velocidad: " + string.Format("{0:0.##}", coordenadas.Velocidad) + "*Direccion: " + coordenadas.Direccion);

                    if (pubnubResponse == false)
                    {
                        using (Bitmap icon = BitmapFactory.DecodeResource(Resources, ResourceIDFlechas))
                        {
                            using (Bitmap bhalfsize = Bitmap.CreateScaledBitmap(icon, (int)convertDpToPixel(23, this), (int)convertDpToPixel(33, this), false))
                            {
                                marker.SetIcon(BitmapDescriptorFactory.FromBitmap(bhalfsize));
                            }
                        }
                    }

                    if (coordenadasArray.Count() == contador || pubnubResponse == true)
                    {
                        using (Bitmap icon = BitmapFactory.DecodeResource(Resources, ResourceIDCarro))
                        {
                            using (Bitmap bhalfsize = Bitmap.CreateScaledBitmap(icon, (int)convertDpToPixel(27, this), (int)convertDpToPixel(37, this), false))
                            {
                                marker.SetIcon(BitmapDescriptorFactory.FromBitmap(bhalfsize));
                            }
                        }
                    }

                    if (pubnubResponse)
                    {
                        RunOnUiThread(() =>
                        {
                            googleMap.AddPolyline(mPolylineOptions.Add(ubicacion));

                            if (mustLeaveIcon1KM)
                            {
                                using (Bitmap icon = BitmapFactory.DecodeResource(Resources, ResourceIDFlechas))
                                {
                                    using (Bitmap bhalfsize = Bitmap.CreateScaledBitmap(icon, (int)convertDpToPixel(23, this), (int)convertDpToPixel(33, this), false))
                                    {
                                        lastMarkerPubNub.SetIcon(BitmapDescriptorFactory.FromBitmap(bhalfsize));
                                        lastPointMarker1KM = newPoint;
                                    }
                                }
                            }
                            else if (lastMarkerPubNub != null)
                            {
                                lastMarkerPubNub.Remove();
                            }
                            else
                            {
                                lastPointMarker1KM = new LastLocation("", ubicacion);
                                using (Bitmap icon = BitmapFactory.DecodeResource(Resources, ResourceIDFlechas))
                                {
                                    using (Bitmap bhalfsize = Bitmap.CreateScaledBitmap(icon, (int)convertDpToPixel(23, this), (int)convertDpToPixel(33, this), false))
                                    {
                                        lastMarker.SetIcon(BitmapDescriptorFactory.FromBitmap(bhalfsize));
                                    }
                                }
                            }
                            googleMap.AnimateCamera(CameraUpdateFactory.NewLatLng(ubicacion));
                            lastMarkerPubNub = googleMap.AddMarker(marker);
                        });
                    }
                    else
                    {
                        RunOnUiThread(() =>
                        {
                            lastMarker = googleMap.AddMarker(marker);
                        });
                    }
                    contador += 1;
                }
            });
        }