Beispiel #1
0
        private Drawing RenderTile(IProjection projection, Rect currentTile, Extent mapArea)
        {
            var degrees  = CalculateDegreeLines(mapArea.ZoomLevel);
            var tileArea = projection.ToGeoArea(currentTile, mapArea);

            var drawing = new DrawingGroup();

            Geo.SetArea(drawing, tileArea);

            var linePen = new Pen(Brushes.Red, 1);

            linePen.Freeze();

            using (var context = drawing.Open())
            {
                context.PushClip(new RectangleGeometry(currentTile));

                var outerRect = projection.ToRect(projection.World, mapArea);
                context.DrawRectangle(null, linePen, outerRect);

                for (var lat = 0.0; lat <= projection.World.NorthEast.Latitude; lat += degrees)
                {
                    var start = projection.ToPoint(new GeoPoint(lat, projection.World.NorthEast.Longitude), mapArea);
                    var end   = projection.ToPoint(new GeoPoint(lat, projection.World.NorthWest.Longitude), mapArea);

                    context.DrawLine(linePen, start, end);

                    if (lat <= 0)
                    {
                        continue;
                    }

                    start = projection.ToPoint(new GeoPoint(-lat, projection.World.NorthEast.Longitude), mapArea);
                    end   = projection.ToPoint(new GeoPoint(-lat, projection.World.NorthWest.Longitude), mapArea);

                    context.DrawLine(linePen, start, end);
                }

                for (var lon = 0.0; lon <= projection.World.NorthEast.Longitude; lon += degrees)
                {
                    var start = projection.ToPoint(new GeoPoint(projection.World.NorthEast.Latitude, lon), mapArea);
                    var end   = projection.ToPoint(new GeoPoint(projection.World.SouthEast.Latitude, lon), mapArea);

                    context.DrawLine(linePen, start, end);

                    if (lon <= 0)
                    {
                        continue;
                    }

                    start = projection.ToPoint(new GeoPoint(projection.World.NorthEast.Latitude, -lon), mapArea);
                    end   = projection.ToPoint(new GeoPoint(projection.World.SouthEast.Latitude, -lon), mapArea);

                    context.DrawLine(linePen, start, end);
                }

                context.Pop();
            }

            drawing.Freeze();
            return(drawing);
        }