Example #1
0
        public override TileData LoadTile(MapTile tile)
        {
            Carto.Graphics.Bitmap tileBitmap1 = CreateBitmap(source1, tile);
            Carto.Graphics.Bitmap tileBitmap2 = CreateBitmap(source2, tile);
            if (tileBitmap1 == null || tileBitmap2 == null)
            {
                return(null);
            }

            UIImage image1 = BitmapUtils.CreateUIImageFromBitmap(tileBitmap1);
            UIImage image2 = BitmapUtils.CreateUIImageFromBitmap(tileBitmap2);

            CGSize size = new CGSize(image1.CGImage.Width, image2.CGImage.Height);

            UIGraphics.BeginImageContext(size);

            image1.Draw(new CGRect(0, 0, size.Width, size.Height));
            image2.Draw(new CGRect(0, 0, size.Width, size.Height));

            UIImage final = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            BinaryData data = BitmapUtils.CreateBitmapFromUIImage(final).CompressToInternal();

            return(new TileData(data));
        }
Example #2
0
        void AddPinTo(MapPos position)
        {
            // 1. Initialize a local vector data source
            LocalVectorDataSource vectorDataSource1 = new LocalVectorDataSource(BaseProjection);

            // Initialize a vector layer with the previous data source
            VectorLayer vectorLayer1 = new VectorLayer(vectorDataSource1);

            // Add the previous vector layer to the map
            MapView.Layers.Add(vectorLayer1);

            // Set visible zoom range for the vector layer
            vectorLayer1.VisibleZoomRange = new MapRange(0, 18);

            // Create marker style
            Carto.Graphics.Bitmap markerBitmap       = BitmapUtils.CreateBitmapFromUIImage(UIImage.FromFile("marker.png"));
            MarkerStyleBuilder    markerStyleBuilder = new MarkerStyleBuilder();

            markerStyleBuilder.Bitmap = markerBitmap;

            markerStyleBuilder.Size = 30;
            MarkerStyle sharedMarkerStyle = markerStyleBuilder.BuildStyle();

            // 3. Add marker
            MapPos markerPos = MapView.Options.BaseProjection.FromWgs84(position);
            Marker marker1   = new Marker(markerPos, sharedMarkerStyle);

            vectorDataSource1.Add(marker1);

            // Animate map to the marker
            MapView.SetFocusPos(markerPos, 1);
            MapView.SetZoom(12, 1);
        }
        public override TileData LoadTile(MapTile tile)
        {
            Carto.Graphics.Bitmap tileBitmap1 = CreateBitmap(source1, tile);
            Carto.Graphics.Bitmap tileBitmap2 = CreateBitmap(source2, tile);

            paint.TextSize = 18;
            paint.Color    = Color.Rgb(50, 50, 50);

            Bitmap image1 = BitmapUtils.CreateAndroidBitmapFromBitmap(tileBitmap1);
            Bitmap image2 = BitmapUtils.CreateAndroidBitmapFromBitmap(tileBitmap2);

            Canvas canvas = new Canvas(image1);

            canvas.DrawBitmap(image2, null, new Rect(0, 0, image1.Height, image1.Width), paint);

            // DrawFilter tile coordinates as text on map

            /*
             * string text = tile.Zoom + "/" + tile.X + "/" + tile.Y;
             * Rect bounds = new Rect();
             *
             * paint.GetTextBounds(text, 0, text.Length, bounds);
             * int x = (256 - bounds.Width()) / 2;
             * int y = (image1.Height + bounds.Height()) / 2;
             *
             * canvas.DrawText(text, x, y, paint);
             */

            BinaryData data = BitmapUtils.CreateBitmapFromAndroidBitmap(image1).CompressToInternal();

            return(new TileData(data));
        }
Example #4
0
 public override void OnMapRendered(Carto.Graphics.Bitmap bitmap)
 {
     if (ScreenCaptured != null)
     {
         ScreenshotEventArgs args = new ScreenshotEventArgs {
             Bitmap = bitmap
         };
         ScreenCaptured(this, args);
     }
 }
        public static void SetSourcesAndElements(this Routing Routing, Context context)
        {
            Carto.Graphics.Bitmap olmarker         = CreateBitmap(context, Resource.Drawable.olmarker);
            Carto.Graphics.Bitmap directionUp      = CreateBitmap(context, Resource.Drawable.direction_up);
            Carto.Graphics.Bitmap directionUpLeft  = CreateBitmap(context, Resource.Drawable.direction_upthenleft);
            Carto.Graphics.Bitmap directionUpRight = CreateBitmap(context, Resource.Drawable.direction_upthenright);

            Carto.Graphics.Color green = new Carto.Graphics.Color(Android.Graphics.Color.Green);
            Carto.Graphics.Color red   = new Carto.Graphics.Color(Android.Graphics.Color.Red);
            Carto.Graphics.Color white = new Carto.Graphics.Color(Android.Graphics.Color.White);

            Routing.SetSourcesAndElements(olmarker, directionUp, directionUpLeft, directionUpRight, green, red, white);
        }
Example #6
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            // Initialize a local vector data source
            LocalVectorDataSource source = new LocalVectorDataSource(BaseProjection);

            // Initialize a vector layer with the previous data source
            VectorLayer layer = new VectorLayer(source);

            // Add the previous vector layer to the map
            MapView.Layers.Add(layer);

            // Create marker style
            Android.Graphics.Bitmap androidMarkerBitmap = Android.Graphics.BitmapFactory.DecodeResource(Resources, Resource.Drawable.marker);
            Carto.Graphics.Bitmap   markerBitmap        = Carto.Utils.BitmapUtils.CreateBitmapFromAndroidBitmap(androidMarkerBitmap);

            MarkerStyleBuilder markerStyleBuilder = new MarkerStyleBuilder();

            markerStyleBuilder.Bitmap = markerBitmap;
            markerStyleBuilder.Size   = 30;
            MarkerStyle markerStyle = markerStyleBuilder.BuildStyle();

            // Add marker
            MapPos berlin = MapView.Options.BaseProjection.FromWgs84(new MapPos(13.38933, 52.51704));
            Marker marker = new Marker(berlin, markerStyle);

            source.Add(marker);

            // Add popup
            PopupStyleBuilder builder = new PopupStyleBuilder();

            builder.SetAttachAnchorPoint(0.5f, 0);
            PopupStyle popupStyle = builder.BuildStyle();

            BasicCustomPopupHandler popupHandler = new BasicCustomPopupHandler("custom popup");

            CustomPopup popup = new CustomPopup(marker, popupStyle, popupHandler);

            popup.SetAnchorPoint(-1, 0);
            source.Add(popup);

            // Animate map to the marker
            MapView.SetFocusPos(berlin, 1);
            MapView.SetZoom(12, 1);
        }
        public override Carto.DataSources.Components.TileData LoadTile(MapTile tile)
        {
            Carto.Graphics.Bitmap tileBitmap1 = CreateBitmap(source1, tile);
            Carto.Graphics.Bitmap tileBitmap2 = CreateBitmap(source2, tile);

            Bitmap image1 = BitmapUtils.CreateAndroidBitmapFromBitmap(tileBitmap1);
            Bitmap image2 = BitmapUtils.CreateAndroidBitmapFromBitmap(tileBitmap2);

            Canvas canvas = new Canvas(image1);

            canvas.DrawBitmap(image2, null, new Rect(0, 0, image1.Height, image1.Width), paint);

            BinaryData data = BitmapUtils.CreateBitmapFromAndroidBitmap(image1).CompressToInternal();

            return(new TileData(data));
        }
Example #8
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Add a pin marker to map
            // 1. Initialize a local vector data source
            LocalVectorDataSource vectorDataSource1 = new LocalVectorDataSource(BaseProjection);

            // Initialize a vector layer with the previous data source
            VectorLayer vectorLayer1 = new VectorLayer(vectorDataSource1);

            // Add the previous vector layer to the map
            MapView.Layers.Add(vectorLayer1);

            // Set visible zoom range for the vector layer
            vectorLayer1.VisibleZoomRange = new MapRange(0, 18);

            // Create marker style
            Bitmap androidMarkerBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.marker);

            Carto.Graphics.Bitmap markerBitmap = BitmapUtils.CreateBitmapFromAndroidBitmap(androidMarkerBitmap);

            MarkerStyleBuilder markerStyleBuilder = new MarkerStyleBuilder();

            markerStyleBuilder.Bitmap = markerBitmap;

            markerStyleBuilder.Size = 30;
            MarkerStyle sharedMarkerStyle = markerStyleBuilder.BuildStyle();

            // 3. Add marker
            //MapPos berlin = new MapPos(13.38933, 52.51704);
            MapPos tallinn = new MapPos(24.646469, 59.426939);

            MapPos markerPos = MapView.Options.BaseProjection.FromWgs84(tallinn);
            Marker marker1   = new Marker(markerPos, sharedMarkerStyle);

            vectorDataSource1.Add(marker1);

            // Animate map to the marker
            MapView.SetFocusPos(markerPos, 1);
            MapView.SetZoom(12, 1);
        }
Example #9
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);

            // Initialize a local vector data source
            LocalVectorDataSource source = new LocalVectorDataSource(BaseProjection);

            // Initialize a vector layer with the previous data source
            VectorLayer layer = new VectorLayer(source);

            // Add the previous vector layer to the map
            MapView.Layers.Add(layer);
            // Set visible zoom range for the vector layer
            layer.VisibleZoomRange = new MapRange(0, 18);

            // Create marker style
            Android.Graphics.Bitmap image        = Android.Graphics.BitmapFactory.DecodeResource(Resources, Resource.Drawable.marker);
            Carto.Graphics.Bitmap   markerBitmap = BitmapUtils.CreateBitmapFromAndroidBitmap(image);

            MarkerStyleBuilder builder = new MarkerStyleBuilder();

            builder.Bitmap = markerBitmap;
            builder.Size   = 30;
            MarkerStyle style = builder.BuildStyle();

            // Add marker
            MapPos berlin = BaseProjection.FromWgs84(new MapPos(13.38933, 52.51704));
            Marker marker = new Marker(berlin, style);

            source.Add(marker);

            // Animate map to the marker
            MapView.SetFocusPos(berlin, 1);
            MapView.SetZoom(12, 1);

            listener = new RenderListener(this, MapView);
            MapView.MapRenderer.CaptureRendering(listener, true);
        }
Example #10
0
        public override void OnMapRendered(Carto.Graphics.Bitmap bitmap)
        {
            if (!map.FocusPos.Equals(position))
            {
                position = map.FocusPos;
                number++;

                Android.Graphics.Bitmap image = BitmapUtils.CreateAndroidBitmapFromBitmap(bitmap);

                string folder   = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                string filename = number + "png";

                string path = Path.Combine(folder, filename);

                string message = null;

                try
                {
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        image.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, stream);
                    }
                }
                catch (Exception e) {
                    message = e.Message;
                }

                if (ScreenCaptured != null)
                {
                    ScreenshotEventArgs args = new ScreenshotEventArgs {
                        Path = path, Message = message
                    };
                    ScreenCaptured(this, args);
                }

                Share(path);
            }
        }
        void OnScreenCaptured(object sender, ScreenshotEventArgs e)
        {
            this.bitmap = e.Bitmap;

            if (((int)Build.VERSION.SdkInt) >= Marshmallow)
            {
                RequestPermissions(
                    new string[] { Android.Manifest.Permission.WriteExternalStorage, Android.Manifest.Permission.ReadExternalStorage },
                    RequestCode
                );
            }
            else {
                OnPermissionGranted();
            }
        }