public void TransformTile(RefreshArguments arguments)
 {
     foreach (var drawnTile in Sublayers.OfType <DeepZoomTileCAlayer>())
     {
         drawnTile.Position = new CGPoint(drawnTile.Position.X + arguments.OffsetX,
                                          drawnTile.Position.Y + arguments.OffsetY);
     }
 }
        private void PinchGestureRecognizerHandler(UIPinchGestureRecognizer gestureRecognizer)
        {
            Stopwatch sw = Stopwatch.StartNew();

            RefreshArguments arguments = CollectArguments(gestureRecognizer);

            if (middlePoint.Equals(CGPoint.Empty))
            {
                if (gestureRecognizer.NumberOfTouches <= 1)
                {
                    return;
                }
                CGPoint point1 = gestureRecognizer.LocationOfTouch(0, containerView);
                CGPoint point2 = gestureRecognizer.LocationOfTouch(1, containerView);
                nfloat  x      = point1.X - point2.X;
                nfloat  y      = point1.Y - point2.Y;

                middlePoint = new CGPoint(point1.X + x, point1.Y + y);
            }

            if (tileSize == 0)
            {
                zoomLevel = arguments.ZoomLevel;
                tileSize  = arguments.TileSize;

                extentWidth  = containerView.CurrentExtent.Width;
                extentHeight = containerView.CurrentExtent.Height;
            }

            arguments.Scale = gestureRecognizer.Scale;

            arguments.ZoomLevel = zoomLevel * gestureRecognizer.Scale;
            arguments.TileSize  = (int)(tileSize * gestureRecognizer.Scale);
            txtZoomLevel.Text   = arguments.ZoomLevel.ToString();
            txtTileSize.Text    = arguments.TileSize.ToString();

            nfloat newLeft   = middlePoint.X - gestureRecognizer.Scale * middlePoint.X;
            nfloat newTop    = middlePoint.Y - gestureRecognizer.Scale * middlePoint.Y;
            nfloat newWidth  = extentWidth * gestureRecognizer.Scale;
            nfloat newHeight = extentHeight * gestureRecognizer.Scale;

            containerView.CurrentExtent = new CGRect(newLeft, newTop, newWidth, newHeight);
            containerView.RefreshZoomTileView(arguments);

            if (gestureRecognizer.State == UIGestureRecognizerState.Ended)
            {
                middlePoint  = CGPoint.Empty;
                zoomLevel    = 0.0f;
                tileSize     = 0;
                extentWidth  = 0.0f;
                extentHeight = 0.0f;
            }

            sw.Stop();
            GestureTimeMonitorAction(sw.ElapsedMilliseconds);
        }
Example #3
0
        private void TransformTile(RefreshArguments arguments)
        {
            foreach (var drawnTile in Subviews.OfType <DeepZoomTileView>())
            {
                if (arguments.Scale == 0.0f)
                {
                    drawnTile.Center = new CGPoint(drawnTile.Center.X + arguments.OffsetX, drawnTile.Center.Y + arguments.OffsetY);
                }
                else
                {
                    nfloat left   = (nfloat)Math.Ceiling((drawnTile.Frame.X - currentExtent.X));
                    nfloat top    = (nfloat)Math.Ceiling((drawnTile.Frame.Y - currentExtent.Y));
                    nfloat width  = drawnTile.TileWidth;
                    nfloat height = drawnTile.TileHeight;

                    drawnTile.Frame = new CGRect(left, top, width, height);
                }
            }
        }
        private RefreshArguments CollectArguments(UIGestureRecognizer e)
        {
            RefreshArguments arguments = new RefreshArguments();

            arguments.ZoomLevel = double.Parse(txtZoomLevel.Text);
            arguments.TileSize  = int.Parse(txtTileSize.Text);

            CGPoint location = e.LocationInView(containerView);

            if (startPoint.Equals(CGPoint.Empty))
            {
                startPoint = location;
            }

            arguments.OffsetX = location.X - startPoint.X;
            arguments.OffsetY = location.Y - startPoint.Y;

            startPoint = location;
            return(arguments);
        }
        private void PanGestureRecognizerHandler(UIPanGestureRecognizer gestureRecognizer)
        {
            Stopwatch        sw        = Stopwatch.StartNew();
            RefreshArguments arguments = CollectArguments(gestureRecognizer);

            nfloat x = containerView.CurrentExtent.X - arguments.OffsetX;
            nfloat y = containerView.CurrentExtent.Y - arguments.OffsetY;

            containerView.CurrentExtent = new CGRect(new CGPoint(x, y), containerView.CurrentExtent.Size);

            containerView.RefreshZoomTileView(arguments);

            if (gestureRecognizer.State == UIGestureRecognizerState.Ended)
            {
                startPoint = CGPoint.Empty;
            }

            sw.Stop();
            GestureTimeMonitorAction(sw.ElapsedMilliseconds);
        }
        public void RefreshZoomTileView(RefreshArguments arguments)
        {
            CGPoint defaultCenter = new CGPoint(Frame.Width * .5f, Frame.Height * .5f);

            TileMatrix tileMatrix = new TileMatrix(arguments.TileSize, arguments.TileSize, defaultCenter, arguments.ZoomLevel);
            IEnumerable <TileMatrixCell> drawingTiles = tileMatrix.GetTileMatrixCells(currentExtent);

            Dictionary <string, DeepZoomTileCAlayer> drawnTiles = new Dictionary <string, DeepZoomTileCAlayer>();

            foreach (var currentTile in Sublayers.OfType <DeepZoomTileCAlayer>())
            {
                string key = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", currentTile.ZoomLevel, currentTile.ColumnIndex, currentTile.RowIndex);
                drawnTiles[key] = currentTile;

                if (currentTile.Frame.X > currentExtent.X + currentExtent.Width ||
                    currentTile.Frame.Y > currentExtent.Y + currentExtent.Height ||
                    currentTile.Frame.X + currentTile.Frame.Width < currentExtent.X ||
                    currentTile.Frame.Y + currentTile.Frame.Height < currentExtent.Y)
                {
                    currentTile.RemoveFromSuperLayer();;
                    currentTile.Dispose();
                }
            }
            TransformTile(arguments);

            foreach (var drawingTile in drawingTiles)
            {
                string key = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", arguments.ZoomLevel, drawingTile.Column, drawingTile.Row);

                if (!drawnTiles.ContainsKey(key))
                {
                    DeepZoomTileCAlayer tileView = new DeepZoomTileCAlayer();
                    tileView.RowIndex    = drawingTile.Row;
                    tileView.ColumnIndex = drawingTile.Column;
                    tileView.ZoomLevel   = arguments.ZoomLevel;
                    tileView.TileHeight  = tileView.TileWidth = arguments.TileSize;
                    tileView.Frame       = drawingTile.CellExtent;
                    AddSublayer(tileView);
                }
            }
        }
        private void RefreshTileView()
        {
            Stopwatch sw = Stopwatch.StartNew();

            RefreshArguments arguments = new RefreshArguments();

            arguments.ZoomLevel         = double.Parse(txtZoomLevel.Text);
            arguments.TileSize          = int.Parse(txtTileSize.Text);
            containerView.CurrentExtent = new CGRect(0, 0, View.Frame.Width, View.Frame.Height);

            foreach (var tileView in containerView.Subviews.OfType <DeepZoomTileView>())
            {
                tileView.RemoveFromSuperview();
                tileView.Dispose();
            }

            for (int i = 0; i < 10; i++)
            {
                containerView.RefreshZoomTileView(arguments);
            }

            sw.Stop();
            lblRedrawResult.Text = string.Format("Redraw: {0} ms", sw.ElapsedMilliseconds / 10);
        }
Example #8
0
        public void RefreshZoomTileView(RefreshArguments arguments)
        {
            CGPoint defaultCenter = new CGPoint(Frame.Width * .5f, Frame.Height * .5f);

            TileMatrix tileMatrix = new TileMatrix(arguments.TileSize, arguments.TileSize, defaultCenter, arguments.ZoomLevel);
            IEnumerable <TileMatrixCell> drawingTiles = tileMatrix.GetTileMatrixCells(currentExtent);

            Dictionary <string, DeepZoomTileView> drawnTiles = new Dictionary <string, DeepZoomTileView>();

            foreach (var currentTile in Subviews.OfType <DeepZoomTileView>())
            {
                string key = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", currentTile.ZoomLevel, currentTile.ColumnIndex, currentTile.RowIndex);
                if (currentTile.Frame.X > currentExtent.Width ||
                    currentTile.Frame.Y > currentExtent.Height ||
                    currentTile.Frame.X + currentTile.Frame.Width < 0 ||
                    currentTile.Frame.Y + currentTile.Frame.Height < 0 ||
                    currentTile.ZoomLevel != arguments.ZoomLevel)
                {
                    currentTile.RemoveFromSuperview();
                    currentTile.Dispose();
                    //if (tileViewCaches.Count >= 100)
                    //{
                    //    string lastKey = tileViewCaches.Last().Key;
                    //    tileViewCaches[lastKey].RemoveFromSuperview();
                    //    tileViewCaches[lastKey].Dispose();
                    //    tileViewCaches.Remove(lastKey);
                    //}
                    //if (!tileViewCaches.ContainsKey(key))
                    //{
                    //    currentTile.Hidden = true;
                    //    tileViewCaches.Add(key, currentTile);
                    //}
                }
                else
                {
                    drawnTiles[key] = currentTile;
                }
            }

            TransformTile(arguments);

            foreach (var drawingTile in drawingTiles)
            {
                string key = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", arguments.ZoomLevel, drawingTile.Column, drawingTile.Row);

                if (!drawnTiles.ContainsKey(key))
                {
                    if (tileViewCaches.ContainsKey(key))
                    {
                        tileViewCaches[key].Hidden = false;
                        tileViewCaches.Remove(key);
                    }
                    else
                    {
                        DeepZoomTileView tileView = new DeepZoomTileView();
                        tileView.RowIndex    = drawingTile.Row;
                        tileView.ColumnIndex = drawingTile.Column;
                        tileView.ZoomLevel   = arguments.ZoomLevel;
                        tileView.TileHeight  = tileView.TileWidth = arguments.TileSize;
                        tileView.Frame       = drawingTile.CellExtent;
                        AddSubview(tileView);
                    }
                }
            }
        }