예제 #1
0
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            ImageSource result = null;

            if (Source != null)
            {
                IResourceLocator resLocator = Mvx.IoCProvider.Resolve <IResourceLocator>();

                if (resLocator == null || resLocator.ResourcesAssembly == null || !resLocator.HasPath(ResourceKeys.ImagesKey))
                {
                    Debug.WriteLine("Resource info not set for images");
                }
                else
                {
                    string resourceFullName = resLocator.GetResourcePath(ResourceKeys.ImagesKey, Source);

#if DEBUG
                    string[] assemblyResourceNames = resLocator.ResourcesAssembly.GetManifestResourceNames();

                    if (!assemblyResourceNames.Contains(resourceFullName))
                    {
                        Debug.WriteLine($"Trying to bind image from resource {resourceFullName}, but it wasn't found in asembly {resLocator.ResourcesAssembly.FullName}");
                    }
#endif

                    try
                    {
                        result = ImageSource.FromResource(resourceFullName, resLocator.ResourcesAssembly);
                    }
                    catch (Exception)
                    {
                        // Simply return null for unfound resources
                    }
                }
            }

            return(result);
        }
예제 #2
0
        public override void DrawOnMap(SKMapCanvas canvas, SKMapSpan canvasMapRect, double zoomScale)
        {
            SKPaint paint = new SKPaint();

            paint.IsAntialias = true;
            paint.StrokeWidth = 1;
            paint.Color       = Color.Fuchsia.ToSKColor();

            if (canvasMapRect.Center.Latitude > 0)
            {
                canvas.DrawLine(new Position(canvasMapRect.Center.Latitude + canvasMapRect.LatitudeDegrees, canvasMapRect.Center.Longitude),
                                new Position(canvasMapRect.Center.Latitude - canvasMapRect.LatitudeDegrees,
                                             canvasMapRect.Center.Longitude + canvasMapRect.LongitudeDegrees),
                                paint);
                canvas.DrawLine(new Position(canvasMapRect.Center.Latitude - canvasMapRect.LatitudeDegrees,
                                             canvasMapRect.Center.Longitude + canvasMapRect.LongitudeDegrees),
                                new Position(canvasMapRect.Center.Latitude - canvasMapRect.LatitudeDegrees,
                                             canvasMapRect.Center.Longitude - canvasMapRect.LongitudeDegrees),
                                paint);
                canvas.DrawLine(new Position(canvasMapRect.Center.Latitude - canvasMapRect.LatitudeDegrees,
                                             canvasMapRect.Center.Longitude - canvasMapRect.LongitudeDegrees),
                                new Position(canvasMapRect.Center.Latitude + canvasMapRect.LatitudeDegrees, canvasMapRect.Center.Longitude),
                                paint);
            }
            else
            {
                canvas.DrawLine(new Position(canvasMapRect.Center.Latitude - canvasMapRect.LatitudeDegrees, canvasMapRect.Center.Longitude),
                                new Position(canvasMapRect.Center.Latitude + canvasMapRect.LatitudeDegrees,
                                             canvasMapRect.Center.Longitude + canvasMapRect.LongitudeDegrees),
                                paint);
                canvas.DrawLine(new Position(canvasMapRect.Center.Latitude + canvasMapRect.LatitudeDegrees,
                                             canvasMapRect.Center.Longitude + canvasMapRect.LongitudeDegrees),
                                new Position(canvasMapRect.Center.Latitude + canvasMapRect.LatitudeDegrees,
                                             canvasMapRect.Center.Longitude - canvasMapRect.LongitudeDegrees),
                                paint);
                canvas.DrawLine(new Position(canvasMapRect.Center.Latitude + canvasMapRect.LatitudeDegrees,
                                             canvasMapRect.Center.Longitude - canvasMapRect.LongitudeDegrees),
                                new Position(canvasMapRect.Center.Latitude - canvasMapRect.LatitudeDegrees, canvasMapRect.Center.Longitude),
                                paint);
            }

            paint.Style       = SKPaintStyle.Stroke;
            paint.StrokeWidth = 10;
            paint.StrokeCap   = SKStrokeCap.Round;
            paint.StrokeJoin  = SKStrokeJoin.Round;
            paint.Color       = Color.Red.ToSKColor();
            SKMapPath zonePath = canvas.CreateEmptyMapPath();

            zonePath.MoveTo((float)(baseBounds.Center.Latitude - baseBounds.LatitudeDegrees), (float)baseBounds.Center.Longitude);
            zonePath.LineTo((float)(baseBounds.Center.Latitude + baseBounds.LatitudeDegrees), (float)(baseBounds.Center.Longitude + baseBounds.LongitudeDegrees));
            zonePath.LineTo((float)(baseBounds.Center.Latitude + baseBounds.LatitudeDegrees), (float)(baseBounds.Center.Longitude - baseBounds.LongitudeDegrees));
            zonePath.Close();

            canvas.DrawPath(zonePath, paint);

            paint.Color = Color.Green.MultiplyAlpha(0.5).ToSKColor();
            Size    currentScaleStrokeArea = SKMapCanvas.PixelsToMapSizeAtScale(new Size(5, 5), baseBounds.Center, zoomScale);
            MapSpan insetBounds            = new MapSpan(baseBounds.Center,
                                                         baseBounds.LatitudeDegrees - currentScaleStrokeArea.Height,
                                                         baseBounds.LongitudeDegrees - currentScaleStrokeArea.Width);

            canvas.DrawRect(insetBounds, paint);

            paint.StrokeWidth = 1;
            paint.Color       = Color.Black.ToSKColor();
            canvas.DrawRect(baseBounds, paint);

            paint.Color = Color.Black.ToSKColor();
            canvas.DrawRect(GpsBounds, paint);

            IResourceLocator resLocator = Mvx.IoCProvider.Resolve <IResourceLocator>();
            string           resPath    = resLocator.GetResourcePath(ResourceKeys.ImagesKey, "symbol_logo.svg");
            SKSvg            logoSvg    = new SKSvg();

            logoSvg.Load(resLocator.ResourcesAssembly.GetManifestResourceStream(resPath));
            canvas.DrawPicture(logoSvg.Picture, baseBounds.Center, new Size(100, 100));
        }