コード例 #1
0
        /// <summary>
        /// Standard constructor of OsmData
        /// </summary>
        public OsmData() {    
            fileInfo = new FileInfo(OSMFILE);
            xmlSource = new XmlOsmStreamSource(fileInfo.OpenRead());

            nodes = new Dictionary<long, OsmSharp.Osm.Node>();
            buildings = new List<Building>();
            landuses = new List<Landuse>();

            /* Declare the colors of the brushes*/

            // Create Wallbrush
            WallTexture texture = new WallTexture(100, 1);
            Bitmap bitmap = texture.DrawTexture();

            using (MemoryStream memory = new MemoryStream())
            {
                bitmap.Save(memory, ImageFormat.Png);
                memory.Position = 0;
                bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = memory;
                bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();
            }

            Rect rect = new Rect(0, 0, bitmapImage.PixelWidth, bitmapImage.PixelHeight);
            WALLBRUSH = new ImageBrush(bitmapImage);
            WALLBRUSH.Viewport = rect;
            WALLBRUSH.ViewportUnits = BrushMappingMode.Absolute;
            WALLBRUSH.Stretch = Stretch.None;
            WALLBRUSH.AlignmentX = AlignmentX.Left;
            WALLBRUSH.AlignmentY = AlignmentY.Top;
            WALLBRUSH.TileMode = TileMode.Tile;


            // Create GrassBrush
            DiamondSquare textureGrass = new DiamondSquare(1, 256, 256);
            Bitmap bitmapGrass = textureGrass.getPoints("green");

            using (MemoryStream memory = new MemoryStream())
            {
                bitmapGrass.Save(memory, ImageFormat.Png);
                memory.Position = 0;
                bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = memory;
                bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();
            }

            Rect rectGrass = new Rect(0, 0, bitmapImage.PixelWidth, bitmapImage.PixelHeight);
            GRASSBRUSH = new ImageBrush(bitmapImage);
            GRASSBRUSH.Viewport = rectGrass;
            GRASSBRUSH.ViewportUnits = BrushMappingMode.Absolute;
            GRASSBRUSH.Stretch = Stretch.None;
            GRASSBRUSH.AlignmentX = AlignmentX.Left;
            GRASSBRUSH.AlignmentY = AlignmentY.Top;
            GRASSBRUSH.TileMode = TileMode.Tile;

            // Define rest of brushes
            SURFACEBRUSH = new SolidColorBrush(Colors.Black);
            LANDUSECOMMERCIALBRUSH = new SolidColorBrush(Colors.LightPink);
            LANDUSECOSTRUCIONBRUSH = new SolidColorBrush(Colors.DarkOliveGreen);
            LANDUSEFARMLANDBRUSH = new SolidColorBrush(Colors.LightYellow);
            LANDUSEFORESTBRUSH = new SolidColorBrush(Colors.LightGreen);
            LANDUSEGARAGESBRUSH = new SolidColorBrush(Colors.Gray);
            LANDUSEGRASSBRUSH = new SolidColorBrush(Colors.LawnGreen);
            LANDUSEINDUSTRIALBRUSH = new SolidColorBrush(Colors.MediumPurple);
            LANDUSERAILWAYBRUSH = new SolidColorBrush(Colors.Black);
            LANDUSERESIDENTIALBRUSH = new SolidColorBrush(Colors.WhiteSmoke);
            LANDUSEDEFAULTBRUSH = new SolidColorBrush(Colors.Orange);

            getBounds();                // declares the object map
            getNodes();                 // fills the dictonary nodes
            getBuildingsAndLanduses();  // fills the lists buildings and landuses
        }
コード例 #2
0
        /// <summary>
        /// Returns the brush for the background
        /// </summary>
        /// <returns>ImageBrush for the background</returns>
        public ImageBrush getBackgroundBrush()
        {
            DiamondSquare background = new DiamondSquare(0.7, 256, 256);
            Bitmap bitmap = background.getPoints("blue");

            ImageBrush brush = new ImageBrush();
            BitmapImage bitmapImage = new BitmapImage();

            using (MemoryStream memory = new MemoryStream())
            {
                bitmap.Save(memory, ImageFormat.Png);
                memory.Position = 0;
                bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = memory;
                bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();
            }

            brush.ImageSource = bitmapImage;

            return brush;
        }