コード例 #1
0
ファイル: VirtualEarthMap.cs プロジェクト: DeCarabas/mlsfu
        protected override Size MeasureOverride(Size constraint)
        {
            Children.Clear();
            //VisualOperations.GetChildren(this).Clear();

            if (double.IsPositiveInfinity(constraint.Width)) { constraint.Width = 500; }
            if (double.IsPositiveInfinity(constraint.Height)) { constraint.Height = 500; }

            double optimalRows = constraint.Height / (double)VETSHelper.TileSizePixels;
            double optimalColumns = constraint.Width / (double)VETSHelper.TileSizePixels;

            int neededRows = (int)(Math.Ceiling(optimalRows + 1.0));
            int neededColumns = (int)(Math.Ceiling(optimalColumns + 1.0));

            WorldCoordinate upperLeft = new WorldCoordinate() { Latitude = CornerLatitude, Longitude = CornerLongitude };

            var pixels = Translator.CoordinateToPixels(upperLeft);
            int tileX, tileY;
            VirtualEarthTileSystem.PixelXYToTileXY((int)pixels.X, (int)pixels.Y, out tileX, out tileY);
            TileCoordinate tileStart = new TileCoordinate(tileX, tileY);

            Dictionary<TileCoordinate, UIElement> oldDisplays = displays;
            displays = new Dictionary<TileCoordinate, UIElement>();

            int maxTiles = VETSHelper.MaxTiles(ZoomLevel);

            for (int y = tileStart.Y; y < Math.Min(tileStart.Y + neededRows, maxTiles); y++)
            {
                for (int x = tileStart.X; x < Math.Min(tileStart.X + neededColumns, maxTiles); x++)
                {
                    TileCoordinate cur = new TileCoordinate(x, y);
                    UIElement child = null;
                    if (!oldDisplays.ContainsKey(cur))
                    {
                        child = CreateChild(cur);
                        if (child != null)
                        {
                            displays[cur] = child;
                        }
                    }
                    else
                    {
                        child = displays[cur] = oldDisplays[cur];
                    }

                    if (child != null)
                    {
                        Children.Add(child);
                        //VisualOperations.GetChildren(this).Add(child);
                        child.Measure(constraint);
                    }
                }
            }
            if (workQueue.Count > 0)
            {
                workQueue.Dequeue().BeginInvoke(null, null);
            }

            return constraint;
        }
コード例 #2
0
ファイル: VirtualEarthViewer.cs プロジェクト: DeCarabas/mlsfu
        UIElement CreateChild(TileCoordinate tile)
        {
            string ft;
            ft = ".jpg";
            string ms = "a";
            switch (MapStyle)
            {
                case MapStyle.Roads:
                    ms = "r";
                    ft = ".png";
                    break;
                case MapStyle.Satalite:
                    ms = "a";
                    ft = ".jpg";
                    break;
                case MapStyle.Both:
                    ms = "h";
                    ft = ".jpg";
                    break;
            }
            string qk = VirtualEarthTileSystem.TileXYToQuadKey(tile.X, tile.Y, ZoomLevel);
            string fullpath = "http://r0.ortho.tiles.virtualearth.net/tiles/" + ms + qk + ft + "?g=1";
            Image img = new Image();
            img.Stretch = Stretch.None;
            img.Height = img.Width = VETSHelper.TileSizePixels;
            img.SnapsToDevicePixels = true;
            SetImageSource(img, fullpath);

            int absX, absY;
            VirtualEarthTileSystem.TileXYToPixelXY(tile.X, tile.Y, out absX, out absY);
            Point absolute = new Point(absX, absY);
            WorldCoordinate wc = Translator.PixelsToCoordinates(absolute);
            SetLatitude(img, wc.Latitude);
            SetLongitude(img, wc.Longitude);
            return img;
        }