Exemple #1
0
        private void IconPropertyChanged()
        {
            if (this.nativeMap == null)
            {
                return;
            }
            if (!formsMaP.Pins?.Any() ?? true)
            {
                return;
            }

            MarkerOptions markerOptions = new MarkerOptions();

            markerOptions.SetPosition(new LatLng(formsMaP.Pins[0].Position.Latitude, formsMaP.Pins[0].Position.Longitude));
            markerOptions.SetIcon(BitmapDescriptorFactory.FromBitmap(GetImageBitmapFromUrl(this.formsMaP.Icon)));


            Device.BeginInvokeOnMainThread(() =>
            {
                try
                {
                    this.formsMaP.Pins.Clear();
                    this.nativeMap.AddMarker(markerOptions);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message, ex);
                }
            });
        }
Exemple #2
0
        protected override async void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName.Equals(nameof(CustomMap.CustomPins)) && GoogleMap != null)
            {
                GoogleMap.Clear();
                var formsMap   = (CustomMap)Element;
                var customPins = formsMap.CustomPins;
                if (customPins == null)
                {
                    return;
                }

                foreach (var pin in customPins)
                {
                    var marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(pin.Latitude, pin.Longitude));
                    marker.SetTitle(pin.Label);
                    marker.SetSnippet(pin.Address);

                    var bitm = await ImageService.Instance.LoadUrl(pin.Url).AsBitmapDrawableAsync();

                    marker.SetIcon(BitmapDescriptorFactory.FromBitmap(bitm.Bitmap));

                    GoogleMap.AddMarker(marker);
                }
            }
        }
Exemple #3
0
        private void AddPokemonMarker(Pokemon p)
        {
            var mOps = new MarkerOptions();

            mOps.SetPosition(p.Location);

            if (PokesVisible.Count() < 100)
            {
                mOps.SetIcon(BitmapDescriptorFactory.FromBitmap(GetPokemonMarker(p)));
            }
            else
            {
                var img = BitmapDescriptorFactory.FromResource(pokeResourceMap[p.pokemon_id]);
                mOps.SetIcon(img);
            }
            mOps.Anchor(0.5f, 0.5f);
            var marker = map.AddMarker(mOps);

            marker.Tag = $"poke:{p.id}";
            if (marker != null)
            {
                p.PokeMarker = marker;
                PokesVisible.Add(p);
            }
        }
        private void AddCircle(LatLng location)
        {
            try
            {
                if (!(circle is null))
                {
                    circle.Remove();
                }

                Drawable drawable = ContextCompat.GetDrawable(this, icMapmarker);

                Bitmap bitmap = Bitmap.CreateBitmap((int)(circleSize * pixelDensity), (int)(circleSize * pixelDensity), Bitmap.Config.Argb8888);
                Canvas canvas = new Canvas(bitmap);
                drawable.SetBounds(0, 0, canvas.Width, canvas.Height);
                drawable.Draw(canvas);

                MarkerOptions markerOptions = new MarkerOptions();
                markerOptions.SetPosition(location);
                markerOptions.SetIcon(BitmapDescriptorFactory.FromBitmap(bitmap));
                markerOptions.Anchor(0.5f, 0.5f);
                circle = thisMap.AddMarker(markerOptions);
            }
            catch
            {
            }
        }
        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);

            Android.Views.View v        = null;
            LayoutInflater     inflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService);

            if (customMap.selectedHelper != null && customMap.selectedHelper.LocationType == 'S')
            {
                v = inflater.Inflate(Resource.Layout.Home, null);
            }
            else if (customMap.selectedHelper != null && customMap.selectedHelper.LocationType == 'M')
            {
                v = inflater.Inflate(Resource.Layout.Mobile, null);
            }
            else
            {
                v = inflater.Inflate(Resource.Layout.Job, null);
            }

            TextView tv = v.FindViewById <TextView>(Resource.Id.tv);

            tv.Text = pin.Label;

            marker.SetIcon(BitmapDescriptorFactory.FromBitmap(LoadBitmapFromView(v)));

            return(marker);
        }
Exemple #6
0
 public override IDictionary <string, MarkerOptions> GetOptions()
 {
     return(new Dictionary <string, MarkerOptions>
     {
         {
             VehicleMarkerKey,
             new MarkerOptions()
             .Anchor(0.5f, 0.5f)
             .SetPosition(this.ViewModel.Location.ToLatLng())
             .SetTitle(this.ViewModel.RouteNumber)
             .SetIcon(this.ViewModel.Icon as BitmapDescriptor)
             .Flat(true)
             .SetAlpha(this.ConvertSelectionStateToAlpha(this.ViewModel.SelectionState))
             .SetRotation(Convert.ToSingle(this.ViewModel.Location.Heading))
         },
         {
             TitleMarkerKey,
             new MarkerOptions()
             .Anchor(0.5f, 1.0f)
             .SetPosition(this.ViewModel.Location.ToLatLng())
             .SetTitle(this.ViewModel.RouteNumber)
             .SetIcon(BitmapDescriptorFactory.FromBitmap(this.ViewModel.TitleIcon as Bitmap))
             .Visible(this.ViewModel.IsTitleVisible)
             .Flat(false)
             .SetAlpha(this.ConvertSelectionStateToAlpha(this.ViewModel.SelectionState))
         }
     });
 }
Exemple #7
0
            //protected override void OnClusterUpdated(ICluster cluster, Marker marker)
            //{
            //    // Same implementation as onBeforeClusterRendered() (to update cached markers)
            //    marker.SetIcon(getClusterIcon(cluster));
            //}

            /**
             * Get a descriptor for multiple people (a cluster) to be used for a marker icon. Note: this
             * method runs on the UI thread. Don't spend too much time in here (like in this example).
             *
             * @param cluster cluster to draw a BitmapDescriptor for
             * @return a BitmapDescriptor representing a cluster
             */
            private BitmapDescriptor getClusterIcon(ICluster cluster)
            {
                List <Drawable> profilePhotos = new List <Drawable>(Math.Min(4, cluster.Size));
                int             width         = mDimension;
                int             height        = mDimension;

                foreach (Person p in cluster.Items)
                {
                    // Draw 4 at most.
                    if (profilePhotos.Count == 4)
                    {
                        break;
                    }
                    Drawable drawable = context.Resources.GetDrawable(p.profilePhoto);
                    drawable.SetBounds(0, 0, width, height);
                    profilePhotos.Add(drawable);
                }
                MultiDrawable multiDrawable = new MultiDrawable(profilePhotos);

                multiDrawable.SetBounds(0, 0, width, height);

                mClusterImageView.SetImageDrawable(multiDrawable);
                Bitmap icon = mClusterIconGenerator.MakeIcon(cluster.Size.ToString());

                return(BitmapDescriptorFactory.FromBitmap(icon));
            }
Exemple #8
0
        private async Task <BitmapDescriptor> DeterminMarkerImage(IMapPin pin, bool selected)
        {
            if (pin == null)
            {
                return(null);
            }

            BitmapDescriptor icon;

            if (pin.Image != null)
            {
                var image = selected && pin.SelectedImage != null ? pin.SelectedImage : pin.Image;
                icon = BitmapDescriptorFactory.FromBitmap(await image.ToBitmap(Context));
            }
            else
            {
                var color = selected ? pin.SelectedColor : pin.Color;
                icon = color.ToStandardMarkerIcon();
            }

            if (icon == null)
            {
                icon = BitmapDescriptorFactory.DefaultMarker();
            }
            return(icon);
        }
Exemple #9
0
        void AddMapPin(LatLng position, string type)
        {
            try
            {
                MarkerOptions markerOpt = new MarkerOptions();
                markerOpt.SetPosition(position);

                var metrics = Resources.DisplayMetrics;
                var wScreen = metrics.WidthPixels;

                Bitmap bmp       = GetPinIconByType(type);
                Bitmap newBitmap = ScaleDownImg(bmp, wScreen / 7, true);
                markerOpt.SetIcon(BitmapDescriptorFactory.FromBitmap(newBitmap));

                RunOnUiThread(() =>
                {
                    var marker = mMapView.AddMarker(markerOpt);
                    pointIDs.Add(marker.Id);
                });
            }
            catch (Exception err)
            {
                Toast.MakeText(this, err.ToString(), ToastLength.Long).Show();
            }
        }
        public static BitmapDescriptor ToBitmapDescriptor(this Drawable drawable)
        {
            if (drawable is BitmapDrawable bitmapDrawable)
            {
                if (bitmapDrawable.Bitmap != null)
                {
                    return(BitmapDescriptorFactory.FromBitmap(bitmapDrawable.Bitmap));
                }
            }

            Bitmap bitmap = null;

            if (drawable.IntrinsicWidth <= 0 || drawable.IntrinsicHeight <= 0)
            {
                bitmap = Bitmap.CreateBitmap(1, 1, Bitmap.Config.Argb8888); // Single color bitmap will be created of 1x1 pixel
            }
            else
            {
                bitmap = Bitmap.CreateBitmap(drawable.IntrinsicWidth, drawable.IntrinsicHeight, Bitmap.Config.Argb8888);
            }

            Canvas canvas = new Canvas(bitmap);

            drawable.Bounds = new Rect(0, 0, canvas.Width, canvas.Height);
            drawable.Draw(canvas);
            return(BitmapDescriptorFactory.FromBitmap(bitmap));
        }
        /// <summary>
        /// Updates the image of a pin
        /// </summary>
        /// <param name="pin">The forms pin</param>
        /// <param name="markerOptions">The native marker options</param>
        async Task UpdateImageAsync(MarkerOptions markerOptions)
        {
            BitmapDescriptor bitmap;

            try
            {
                if (Pin.Image != null)
                {
                    bitmap = BitmapDescriptorFactory.FromBitmap(await Pin.Image.ToBitmap(_context));
                }
                else
                {
                    if (Pin.DefaultPinColor != Xamarin.Forms.Color.Default)
                    {
                        var hue = Pin.DefaultPinColor.ToAndroid().GetHue();
                        bitmap = BitmapDescriptorFactory.DefaultMarker(System.Math.Min(hue, 359.99f));
                    }
                    else
                    {
                        bitmap = BitmapDescriptorFactory.DefaultMarker();
                    }
                }
            }
            catch (System.Exception)
            {
                bitmap = BitmapDescriptorFactory.DefaultMarker();
            }
            markerOptions.SetIcon(bitmap);
        }
Exemple #12
0
        void SetMap()
        {
            var currentLocation = GetGPSLocation();

            try
            {
                MarkerOptions markerOpt = new MarkerOptions();
                markerOpt.SetPosition(new LatLng(currentLocation.Latitude, currentLocation.Longitude));

                var metrics = Resources.DisplayMetrics;
                var wScreen = metrics.WidthPixels;

                Bitmap bmp       = BitmapFactory.DecodeResource(Resources, Resource.Drawable.pin_me);
                Bitmap newBitmap = ScaleDownImg(bmp, wScreen / 10, true);
                markerOpt.SetIcon(BitmapDescriptorFactory.FromBitmap(newBitmap));

                RunOnUiThread(() =>
                {
                    markerMyLocation = mMapView.AddMarker(markerOpt);
                });

                SetMapPosition(new LatLng(currentLocation.Latitude, currentLocation.Longitude));

                SetNearestEventMarkers(currentLocation);
            }
            catch (Exception err)
            {
                Toast.MakeText(this, err.ToString(), ToastLength.Long).Show();
            }
        }
        public void AddFromBitmap(View view)
        {
            if (hMap == null)
            {
                return;
            }
            if (null != overlay)
            {
                overlay.Remove();
            }
            Log.Debug(TAG, "AddFromBitmap: ");
            Drawable vectorDrawable = ResourcesCompat.GetDrawable(Resources, Resource.Drawable.niuyouguo, null);
            Bitmap   bitmap         = Bitmap.CreateBitmap(vectorDrawable.IntrinsicWidth, vectorDrawable.IntrinsicHeight,
                                                          Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(bitmap);

            vectorDrawable.SetBounds(0, 0, canvas.Width, canvas.Height);
            vectorDrawable.Draw(canvas);
            GroundOverlayOptions options = new GroundOverlayOptions().Position(MapUtils.FRANCE2, 50, 50)
                                           .InvokeImage(BitmapDescriptorFactory.FromBitmap(bitmap));

            overlay = hMap.AddGroundOverlay(options);
            CameraPosition cameraPosition = new
                                            CameraPosition.Builder().Target(MapUtils.FRANCE2).Zoom(18).Bearing(0f).Tilt(0f).Build();
            CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);

            hMap.MoveCamera(cameraUpdate);
        }
Exemple #14
0
        private BitmapDescriptor GetPinIcon(PinType type)
        {
            if (type == PinType.Generic)
            {
                if (UserPin != null)
                {
                    return(UserPin);
                }

                var drawableResource = Context.Resources.GetDrawable("UserLocation.png");
                UserPin = BitmapDescriptorFactory.FromBitmap(((BitmapDrawable)drawableResource).Bitmap);
                return(UserPin);
            }
            else
            {
                if (WasherPin != null)
                {
                    return(WasherPin);
                }

                var drawableResource = Context.Resources.GetDrawable("CitoPin.png");
                WasherPin = BitmapDescriptorFactory.FromBitmap(((BitmapDrawable)drawableResource).Bitmap);
                return(WasherPin);
            }
        }
Exemple #15
0
        private BitmapDescriptor getRegularPinDescriptor()
        {
            try {
                // var myIcon = new Google.MarkerImage("images/marker-icon.png", null, null, null, new google.maps.Size(21, 30));
                var px = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, MARKER_AREA_DP, Resources.DisplayMetrics);

                // Create a Bitmap to draw on
                using (var bitmap = Bitmap.CreateBitmap(px, px, Bitmap.Config.Argb8888)) {
                    // Create a canvas to draw on
                    using (var canvas = new Canvas(bitmap)) {
                        // Load additional Drawables to draw on top of the circle
                        using (var pin = ContextCompat.GetDrawable(Context, Resource.Drawable.ico_pin)) {
                            pin.SetBounds((int)(px * 0.1f), (int)(px * 0.1f), (int)(px * 0.7f), px);
                            pin.Draw(canvas);
                        }
                    }

                    return(BitmapDescriptorFactory.FromBitmap(bitmap));
                }
            } catch (Exception e) {
                if (e.StackTrace != null)
                {
                    DebugHelper.newMsg(TAG, e.StackTrace);
                }
            }

            return(null);
        }
Exemple #16
0
        protected override MarkerOptions CreateMarker(Pin pin)
        {
            if (pin is CirclePin)
            {
                //create an overlay circle, and add to map
                var circleOptions = new CircleOptions();
                circleOptions.InvokeCenter(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
                circleOptions.InvokeRadius(PublishedData.PinOverlayRadius);
                circleOptions.InvokeFillColor(0X66FF0000);
                circleOptions.InvokeStrokeColor(0X66FF0000);
                circleOptions.InvokeStrokeWidth(0);
                Circle circle = NativeMap.AddCircle(circleOptions);
                (pin as CirclePin).Overlay = circle;
            }

            // marker,or pin.
            var marker = new MarkerOptions();

            marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
            marker.Anchor(0.5f, 0.5f);// set anchor to to middle of icon
            marker.SetTitle(pin.Label);
            marker.SetSnippet(pin.Address);
            Bitmap imageBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.pin);
            Bitmap resizedIcon = Bitmap.CreateScaledBitmap(imageBitmap, 50, 50, false);

            marker.SetIcon(BitmapDescriptorFactory.FromBitmap(resizedIcon));

            return(marker);
        }
        private void UpdatePins()
        {
            var mapTile = (MapTile)Element;

            NativeMap.Clear();

            var pinItems = mapTile.PinList;

            foreach (var pinItem in pinItems)
            {
                var imageBytes = pinItem.PrimaryCategory.GetIconThemeBytes();
                var icon       = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);

                var marker = new MarkerOptions();
                marker.SetPosition(new LatLng(pinItem.Latitude, pinItem.Longitude));
                marker.SetSnippet(pinItem.Id);
                marker.SetIcon(BitmapDescriptorFactory.FromBitmap(icon));

                NativeMap.AddMarker(marker);
            }

            if (LocationMarkerOptions.Position != null)
            {
                LocationMarker = NativeMap.AddMarker(LocationMarkerOptions);
            }

            UpdateLocationPinPosition();
        }
Exemple #18
0
            //public void OnClusterItemUpdated(Person person, Marker marker)
            //{
            //    // Same implementation as onBeforeClusterItemRendered() (to update cached markers)
            //    marker.SetIcon(getItemIcon(person));
            //    marker.Title = person.Name;
            //}

            /**
             * Get a descriptor for a single person (i.e., a marker outside a cluster) from their
             * profile photo to be used for a marker icon
             *
             * @param person person to return an BitmapDescriptor for
             * @return the person's profile photo as a BitmapDescriptor
             */
            private BitmapDescriptor getItemIcon(Person person)
            {
                mImageView.SetImageResource(person.profilePhoto);
                Bitmap icon = mIconGenerator.MakeIcon();

                return(BitmapDescriptorFactory.FromBitmap(icon));
            }
Exemple #19
0
        /// <summary>
        /// Updates the image on a marker
        /// </summary>
        /// <param name="pin">The forms pin</param>
        /// <param name="marker">The native marker</param>
        private async Task UpdateImage(TKCustomMapPin pin, Marker marker)
        {
            BitmapDescriptor bitmap;

            try
            {
                if (pin.Image != null)
                {
                    bitmap = BitmapDescriptorFactory.FromBitmap(await pin.Image.ToBitmap(this.Context));
                }
                else
                {
                    if (pin.DefaultPinColor != Color.Default)
                    {
                        var hue = pin.DefaultPinColor.ToAndroid().GetHue();
                        bitmap = BitmapDescriptorFactory.DefaultMarker(hue);
                    }
                    else
                    {
                        bitmap = BitmapDescriptorFactory.DefaultMarker();
                    }
                }
            }
            catch (Exception)
            {
                bitmap = BitmapDescriptorFactory.DefaultMarker();
            }
            marker.SetIcon(bitmap);
        }
            protected override void OnBeforeClusterRendered(ICluster p0, MarkerOptions p1)
            {
                List <Drawable> photos = new List <Drawable>(System.Math.Min(4, p0.Size));
                int             width  = dimension;
                int             height = dimension;

                foreach (var person in p0.Items)
                {
                    if (photos.Count == 4)
                    {
                        return;
                    }
                    var      p        = person as Person;
                    Drawable drawable = context.GetDrawable(p.Photo);
                    drawable.SetBounds(0, 0, width, height);
                    photos.Add(drawable);
                }

                MultiDrawable multiDrawable = new MultiDrawable(photos);

                multiDrawable.SetBounds(0, 0, width, height);
                clusterImageView.SetImageDrawable(multiDrawable);
                Bitmap icon = clusterIconGenerator.MakeIcon(p0.Size.ToString());

                p1.SetIcon(BitmapDescriptorFactory.FromBitmap(icon));
            }
Exemple #21
0
        internal static BitmapDescriptor ToNative(this XImage image)
        {
            switch (image.Source)
            {
            default:
                return(null);

            case BaiduMaps.ImageSource.File:
                //return BitmapDescriptorFactory.FromFile(image.FileName);
                return(BitmapDescriptorFactory.FromPath(image.FileName));

            case ImageSource.Bundle:
                return(BitmapDescriptorFactory.FromAsset(image.BundleName));

            case ImageSource.Resource:
            {
                //Resource.Drawable.q10660 not include .mp3
                //int rsid = (int)typeof(Resource.Drawable).GetField(image.ResourceName).GetValue(null);
                //return BitmapDescriptorFactory.FromResource(rsid);
                //var rsid = Xamarin.Forms.Platform.Android.ResourceManager.g(image.ResourceId);
                return(BitmapDescriptorFactory.FromResource(image.ResourceId));
            }

            case ImageSource.Stream:
                return(BitmapDescriptorFactory.FromBitmap(BitmapFactory.DecodeStream(image.Stream)));
            }
        }
Exemple #22
0
        public void DrawArrow(LatLng StartLocation, LatLng EndLocation)
        {
            if (mMarker != null)
            {
                mMarker.Remove();
            }

            matrix = new Matrix();

            if (EndLocation != null && StartLocation != null)
            {
                var Deg = CalcBearing(StartLocation, EndLocation);
                matrix.PostRotate(float.Parse(Deg.ToString()));
                bmRotate = Bitmap.CreateBitmap(bmArrow, 0, 0, bmArrow.Width, bmArrow.Height, matrix, true);

                bmDescriptor = BitmapDescriptorFactory.FromBitmap(bmRotate);

                mkOptions = new MarkerOptions();
                mkOptions.SetIcon(bmDescriptor);
                mkOptions.SetPosition(StartLocation);
                mkOptions.Anchor(0.5f, 0.5f);
                mMarker = map.AddMarker(mkOptions);

                bmRotate.Recycle();
                bmRotate = null;

                ////groundOverlayOptions = new GroundOverlayOptions()
                //groundOverlayOptions = new GroundOverlayOptions()
                //    .Position(StartLocation, bmArrow.Width, bmArrow.Height)
                //    .InvokeImage(bmDescriptor)
                //    .InvokeZIndex(5);
                //myOverlay = map.AddGroundOverlay(groundOverlayOptions);
                //ListArrow.Add(myOverlay);
            }
        }
Exemple #23
0
        private BitmapDescriptor GetCustomBitmapDescriptor(string iconName, int resourceID)
        {
            BitmapDescriptor icon;

            using (Paint paint = new Paint(PaintFlags.AntiAlias))
            {
                using (Rect bounds = new Rect())
                {
                    using (baseBitmap = BitmapFactory.DecodeResource(Resources, resourceID))
                    {
                        bitmap = baseBitmap.Copy(Bitmap.Config.Argb8888, true);

                        paint.GetTextBounds(iconName, 0, iconName.Length, bounds);

                        float x = bitmap.Width / 2.0f;
                        float y = (bitmap.Height - bounds.Height()) / 2.0f - bounds.Top;

                        Canvas canvas = new Canvas(bitmap);

                        canvas.DrawText(iconName, x, y, paint);

                        icon = BitmapDescriptorFactory.FromBitmap(bitmap);

                        bitmap.Dispose();
                        baseBitmap.Dispose();
                    }
                    bounds.Dispose();
                }
                paint.Dispose();
            }
            return(icon);
        }
Exemple #24
0
        private async Task HandleGroundOverlayForTile(TileInfo tileInfo)
        {
            if (SharedOverlay.IsVisible)
            {
                int       virtualTileSize = Extensions.SKMapExtensions.MercatorMapSize >> tileInfo.Zoom;
                int       xPixelsStart    = tileInfo.X * virtualTileSize;
                int       yPixelsStart    = tileInfo.Y * virtualTileSize;
                double    zoomScale       = SKMapCanvas.MapTileSize / (double)virtualTileSize;
                Rectangle mercatorSpan    = new Rectangle(xPixelsStart, yPixelsStart, virtualTileSize, virtualTileSize);
                SKMapSpan tileSpan        = mercatorSpan.ToGps();

                if (tileSpan.FastIntersects(SharedOverlay.GpsBounds))
                {
                    SKBitmap         bitmap                  = DrawTileToBitmap(tileSpan, zoomScale);
                    BitmapDescriptor bitmapDescriptor        = BitmapDescriptorFactory.FromBitmap(bitmap.ToBitmap());
                    TaskCompletionSource <object> drawingTcs = new TaskCompletionSource <object>();

                    Console.WriteLine($"Refreshing ground tile at ({tileInfo.X}, {tileInfo.Y}) for zoom level {tileInfo.Zoom} ({zoomScale}) with GPS bounds {tileSpan}");

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        GroundOverlay overlay;

                        lock (_GroundOverlays)
                        {
                            overlay = _GroundOverlays.FirstOrDefault(o => (o.Tag as TileInfo)?.Equals(tileInfo) ?? false);
                        }

                        if (overlay == null)
                        {
                            GroundOverlayOptions overlayOptions = new GroundOverlayOptions().PositionFromBounds(tileSpan.ToLatLng())
                                                                  .InvokeImage(bitmapDescriptor);

                            overlay     = _NativeMap.AddGroundOverlay(overlayOptions);
                            overlay.Tag = tileInfo;

                            lock (_GroundOverlays)
                            {
                                _GroundOverlays.Add(overlay);
                            }
                        }
                        else if ((overlay.Tag as TileInfo)?.NeedsRedraw ?? false)
                        {
                            overlay.SetImage(bitmapDescriptor);
                        }

                        drawingTcs.TrySetResult(null);
                    });

                    await drawingTcs.Task.ConfigureAwait(false);

                    ReleaseOverlayBitmap(bitmap);
                }
                else
                {
                    Console.WriteLine($"Ground tile at ({tileInfo.X}, {tileInfo.Y}) for zoom level {tileInfo.Zoom} already exists");
                }
            }
        }
        async Task SetMapStationPins(Station[] stations, float alpha = 1)
        {
            var stationsToUpdate = stations.Where(station =>
            {
                Marker marker;
                var stats = station.BikeCount + "|" + station.EmptySlotCount;
                if (existingMarkers.TryGetValue(station.Id, out marker))
                {
                    if (marker.Snippet == stats && !showedStale)
                    {
                        return(false);
                    }
                    marker.Remove();
                }
                return(true);
            }).ToArray();

            var pins = await Task.Run(() => stationsToUpdate.ToDictionary(station => station.Id, station =>
            {
                var w = 24.ToPixels();
                var h = 40.ToPixels();
                if (station.Locked)
                {
                    return(pinFactory.GetClosedPin(w, h));
                }
                else if (!station.Installed)
                {
                    return(pinFactory.GetNonInstalledPin(w, h));
                }
                var ratio = (float)TruncateDigit(station.BikeCount / ((float)station.Capacity), 2);
                return(pinFactory.GetPin(ratio,
                                         station.BikeCount,
                                         w, h,
                                         alpha: alpha));
            }));

            foreach (var station in stationsToUpdate)
            {
                var pin = pins[station.Id];

                var snippet = station.BikeCount + "|" + station.EmptySlotCount;
                if (station.Locked)
                {
                    snippet = string.Empty;
                }
                else if (!station.Installed)
                {
                    snippet = "not_installed";
                }

                var markerOptions = new MarkerOptions()
                                    .SetTitle(station.Id + "|" + station.Street + "|" + station.Name)
                                    .SetSnippet(snippet)
                                    .SetPosition(new Android.Gms.Maps.Model.LatLng(station.Location.Lat, station.Location.Lon))
                                    .SetIcon(BitmapDescriptorFactory.FromBitmap(pin));
                existingMarkers[station.Id] = map.AddMarker(markerOptions);
            }
        }
Exemple #26
0
        public void OnMapReady(GoogleMap googleMap)
        {
            this.googleMap = googleMap;

            // Register events
            googleMap.CameraChange += GoogleMap_CameraChange;
            googleMap.MarkerClick  += GoogleMap_MarkerClick;
            googleMap.MapClick     += GoogleMap_MapClick;

            // Set initial zoom level
            CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngZoom(new LatLng(43.608340, 3.877086), 12);

            googleMap.MoveCamera(cameraUpdate);

            // Add polylines
            foreach (Line line in TramUrWayApplication.Lines)
            {
                foreach (Route route in line.Routes)
                {
                    PolylineOptions polyline = new PolylineOptions().InvokeWidth(5).Visible(line.Type == LineType.Tram);
                    Color           color    = Utils.GetColorForLine(Activity, line);

                    polyline = polyline.InvokeColor(color.ToArgb());

                    foreach (Step step in route.Steps.Take(route.Steps.Length - 1))
                    {
                        foreach (TrajectoryStep trajectoryStep in step.Trajectory)
                        {
                            LatLng latLng = new LatLng(trajectoryStep.Position.Latitude, trajectoryStep.Position.Longitude);
                            polyline = polyline.Add(latLng);
                        }
                    }

                    routeLines.Add(route, googleMap.AddPolyline(polyline));
                }
            }

            // Prepare line icons
            float    density         = Resources.DisplayMetrics.Density;
            Drawable drawable        = Resources.GetDrawable(Resource.Drawable.train);
            Drawable drawableOutline = Resources.GetDrawable(Resource.Drawable.train_glow);

            foreach (Line line in TramUrWayApplication.Lines)
            {
                Bitmap bitmap = Bitmap.CreateBitmap((int)(IconSize * density), (int)(IconSize * density), Bitmap.Config.Argb8888);
                Canvas canvas = new Canvas(bitmap);
                Color  color  = Utils.GetColorForLine(Activity, line);

                drawableOutline.SetBounds(0, 0, (int)(IconSize * density), (int)(IconSize * density));
                drawableOutline.Draw(canvas);

                drawable.SetColorFilter(color, PorterDuff.Mode.SrcIn);
                drawable.SetBounds(0, 0, (int)(IconSize * density), (int)(IconSize * density));
                drawable.Draw(canvas);

                lineIcons[line] = BitmapDescriptorFactory.FromBitmap(bitmap);
            }
        }
Exemple #27
0
        void GetLocationss()
        {
            WebService webService = new WebService();
            var        Donus      = webService.OkuGetir("locations");

            if (Donus != null)
            {
                var aa = Donus.ToString();
                Locationss = Newtonsoft.Json.JsonConvert.DeserializeObject <List <HaritaListeDataModel> >(Donus.ToString());
                if (Locationss.Count > 0)
                {
                    //Locationss.ForEach(item => item.coordinateX = 40.9932879);
                    //Locationss.ForEach(item => item.coordinateY = 29.1506936);
                    this.Activity.RunOnUiThread(() => {
                        for (int i = 0; i < Locationss.Count; i++)
                        {
                            MapUtils mapUtils = new MapUtils();
                            Android.Graphics.Bitmap bitmap = mapUtils.createStoreMarker(this.Activity, false);

                            BitmapDescriptor image = BitmapDescriptorFactory.FromBitmap(bitmap);

                            if (_map != null)
                            {
                                MarkerOptions markerOpt1 = new MarkerOptions();
                                markerOpt1.SetPosition(new LatLng(Locationss[i].coordinateX, Locationss[i].coordinateY));
                                markerOpt1.SetTitle(i.ToString());
                                markerOpt1.SetIcon(image);
                                //markerOpt1.Visible(MapDataModel1[i].IsShow);
                                var EklenenMarker = _map.AddMarker(markerOpt1);
                                //MapDataModel1[i].IlgiliMarker = EklenenMarker;
                            }
                        }

                        if (Locationss.Count > 0)
                        {
                            ListeyiFragmentCagir();
                            CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngZoom(new LatLng(StartLocationCall.UserLastLocation.Latitude, StartLocationCall.UserLastLocation.Longitude), 20);
                            _map.MoveCamera(cameraUpdate);
                        }
                        ShowLoading.Hide();
                    });
                }
                else
                {
                    AlertHelper.AlertGoster("Popüler lokasyon bulunamadı...", this.Activity);
                    ShowLoading.Hide();
                }
            }
            else
            {
                ShowLoading.Hide();
            }
            this.Activity.RunOnUiThread(delegate()
            {
                GelenBase1.ButonKullanimDuzenle(true);
            });
        }
Exemple #28
0
 public void SetIcon(View view)
 {
     if (null != mBeijing)
     {
         Bitmap           bitmap           = BitmapFactory.DecodeResource(Resources, Resource.Drawable.badge_tr);
         BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.FromBitmap(bitmap);
         mBeijing.SetIcon(bitmapDescriptor);
     }
 }
Exemple #29
0
        private void addIcon(IconGenerator iconFactory, string text, LatLng position)
        {
            MarkerOptions markerOptions = new MarkerOptions();

            markerOptions.SetIcon(BitmapDescriptorFactory.FromBitmap(iconFactory.MakeIcon(text)));
            markerOptions.SetPosition(position);
            markerOptions.Anchor(iconFactory.AnchorU, iconFactory.AnchorV);

            getMap().AddMarker(markerOptions);
        }
        private void MarkPolice(DateTime date, LatLng pos)
        {
            var markerOption = new MarkerOptions().SetPosition(pos);

            markerOption.SetTitle(date.ToString());
            var bmDescriptor = BitmapDescriptorFactory.FromBitmap(resizeMapIcons(2130837627, _iconSize, _iconSize));

            markerOption.SetIcon(bmDescriptor);
            _googleMap.AddMarker(markerOption);
        }