示例#1
0
        private async void LoadSampleFile()
        {
            var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/sample.svg"));

            using (var fileStream = await file.OpenReadAsync())
            {
                svgDocument = await CanvasSvgDocument.LoadAsync(canvasControl, fileStream);

                canvasControl.Invalidate();
            }
        }
示例#2
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            db = new MapTilesDatabase();
            db.InitFromResource(MapTilesDatabase.PolandCustomMapBase);

            //MAP
            map.MapTapped += Map_MapTapped;
            map.Center     = new Geopoint(new BasicGeoposition()
            {
                Longitude = 21.006114275336859, Latitude = 52.231777083350494, Altitude = 163.6815999513492
            });
            map.ZoomLevel = 16;

            InitMapRouter();


            Console.SetOut(new ControlWriter(textOutput));

            win2dCanvas.PointerWheelChanged += (s, args) =>
            {
                var point = args.GetCurrentPoint(win2dCanvas);
                //System.Diagnostics.Debug.WriteLine($"{point.Properties.MouseWheelDelta}");
                tileScale       += tileScale * (point.Properties.MouseWheelDelta * tileScaleFactor);
                tileScale        = Math.Max(0, Math.Min(10, tileScale));
                canvasScalePoint = new System.Numerics.Vector2((float)point.Position.X, (float)point.Position.Y);
                win2dCanvas.Invalidate();
            };

            win2dCanvas.PointerPressed += (s, args) =>
            {
                panWithPointer = true;
                if (args.GetCurrentPoint(null).Properties.IsRightButtonPressed)
                {
                    canvasOffset = new System.Numerics.Vector2(0, 0);
                    tileScale    = 1f;
                    win2dCanvas.Invalidate();
                }
            };

            win2dCanvas.PointerMoved += (s, args) =>
            {
                if (panWithPointer)
                {
                    var cp = args.GetCurrentPoint(null);
                    if (lastPoint == null)
                    {
                        lastPoint = cp;
                    }
                    canvasOffset = new System.Numerics.Vector2(canvasOffset.X + (float)(cp.Position.X - lastPoint.Position.X), canvasOffset.Y + (float)(cp.Position.Y - lastPoint.Position.Y));
                    lastPoint    = cp;
                    win2dCanvas.Invalidate();
                }
            };

            win2dCanvas.PointerReleased += (s, args) =>
            {
                panWithPointer = false;
                lastPoint      = null;
            };

            win2dCanvas.DpiScale = 1;

            icons = new Dictionary <string, CanvasSvgDocument>();
            StorageFolder appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            StorageFolder assets             = await appInstalledFolder.GetFolderAsync("Icons");

            var files = await assets.GetFilesAsync();

            foreach (var f in files)
            {
                var shortName = System.IO.Path.GetFileNameWithoutExtension(f.Name).Split(".").Last();
                using (var stream = await f.OpenAsync(FileAccessMode.Read)) {
                    CanvasSvgDocument svg = await CanvasSvgDocument.LoadAsync(win2dCanvas, stream);

                    icons.Add(shortName, svg);
                }
            }
            ;
        }