示例#1
0
        /// <summary>
        /// Gets image by service.
        /// </summary>
        /// <param name="extent">Map area extent.</param>
        /// <param name="width">Image width.</param>
        /// <param name="height">Image height.</param>
        /// <param name="dpi">Image DPI.</param>
        /// <returns>Getted image.</returns>
        private MapImage _GetImage(EnvelopeN extent, int width, int height, int dpi)
        {
            Debug.Assert(null != extent);
            Debug.Assert(0 < width);
            Debug.Assert(0 < height);
            Debug.Assert(0 < dpi);

            MapImage mapImage = null;

            try
            {
                var imgdDisplay = new ImageDisplay();
                imgdDisplay.ImageHeight = height;
                imgdDisplay.ImageWidth  = width;
                imgdDisplay.ImageDPI    = dpi;

                _imgDescription.ImageDisplay   = imgdDisplay;
                _mapDescription.MapArea.Extent = extent;

                mapImage = _mapService.ExportMapImage(_mapDescription, _imgDescription);
            }
            catch (Exception ex)
            {
                if (ex is AuthenticationException || ex is CommunicationException)
                {
                    _serviceInWorkedState = false;
                }

                throw; // exception
            }

            _imgDescription.ImageDisplay = null;

            return(mapImage);
        }
示例#2
0
        void window_Closed(object sender, EventArgs e)
        {
            String URL = window.getURL();
            Debug.WriteLine("URL: " + URL);

            Location location = new Location();

            if (this.mainPage.mainMap.TryViewportPointToLocation(this.mouseEvent.ViewportPoint, out location))
            {
                /* Success */
                Debug.WriteLine("Point (" + location.Longitude + "," + location.Latitude + ")");

                MapImage image = new MapImage(URL);
                Debug.WriteLine("yabai: " + URL);
                image.setLocation(location);
                image.draw(mainPage.mainMap);

                this.mapData = image;
            }
            else
            {
                /* Fails */
                Debug.WriteLine("Something wrong has happened in converting viewport to location.");
            }
        }
示例#3
0
        public LuaMapImage AddImage(LuaPoint geoPoint, String path, String icon, float width)
        {
            MapImage mi = null;

            if (icon != null)
            {
                LuaStream ls = LuaResource.GetResource(path, icon);
                if (ls != null && ls.GetStream() != null)
                {
                    BitmapImage bi = new BitmapImage();
                    bi.SetSource(
#if NETFX_CORE
                        new MemoryRandomAccessStream((Stream)ls.GetStream())
#else
                        (Stream)ls.GetStream()
#endif
                        );
                    mi = new MapImage(bi);
                    mi.setDimensions(width);
                    mi.setPosition(geoPoint.ToPoint());
                }
            }
            else
            {
                Log.e("LGMapView", "Image is needed for LuaMapImage");
            }

            if (mi != null)
            {
                LuaMapImage lmi = new LuaMapImage(mi);
                return(lmi);
            }
            return(null);
        }
示例#4
0
        private void HighlightSelectedLines(DataGridView activeDataGridView, MapImage activeMap)
        {
            List <Geometry> geomsToHighlight = new List <Geometry>();

            // Create the new "ToHighlight" vector layer and remove the old one from the map.
            VectorLayer toHighlight  = new VectorLayer("HighlightedLines");
            int         iRemoveIndex = activeMap.Map.Layers.FindIndex(delegate(SharpMap.Layers.ILayer layer) { return(layer.LayerName == "HighlightedLines"); });

            if (iRemoveIndex > -1)
            {
                activeMap.Map.Layers.RemoveAt(iRemoveIndex);
            }

            // Loop through the selected values only and add them to the geom collection to highlight.
            // Then add that layer to the map.
            foreach (DataGridViewRow linestringToHighlight in activeDataGridView.SelectedRows)
            {
                if (linestringToHighlight.Cells["LINESTRING"].Value != null && linestringToHighlight.Cells["LINESTRING"].Value.ToString() != "")
                {
                    Geometry geomToHighlight = Geometry.GeomFromText(linestringToHighlight.Cells["LINESTRING"].Value.ToString());
                    geomToHighlight.Color  = Color.Cyan;
                    geomToHighlight.Width_ = 5;
                    geomsToHighlight.Add(geomToHighlight);
                }
            }
            toHighlight.DataSource = new GeometryProvider(geomsToHighlight);
            activeMap.Map.Layers.Insert(0, toHighlight);
            activeMap.Refresh();
            activeMap.Map.ZoomToExtents();
        }
        /// <summary>
        /// 删除元素
        /// </summary>
        /// <param name="map"></param>
        /// <param name="tree"></param>
        /// <param name="cmd"></param>
        private void DeleteObject(MapImage map, MyTree tree, string[] cmd)
        {
            if (cmd.Length != 4)
            {
                return;
            }
            decimal  layerid    = GetId(cmd[2]);
            decimal  objectid   = GetId(cmd[3]);
            TreeNode layernode  = FindLayer(tree.Nodes[0], layerid);
            TreeNode objectnode = FindObject(layernode, layerid, objectid);

            if (objectnode == null)
            {
                return;
            }
            //取得当前图层
            VectorLayer layer = layernode.Tag as VectorLayer;

            //如果有当前选择区域,则从图层中删除
            if (map.NeedSave && layer.NeedSave)
            {
                MapDBClass.DeleteObject(map.Map.MapId, layerid, objectid, layer.Type);
            }
            ((GeometryProvider)layer.DataSource).Geometries.Remove(objectnode.Tag as Geometry);
            tree.Nodes.Remove(objectnode);
        }
示例#6
0
        public FdoMapPreviewPresenter(IFdoMapView view, MapImage mimg)
        {
            _view                 = view;
            _mapImage             = mimg;
            _mapImage.MouseMove  += new MapImage.MouseEventHandler(MapMouseMove);
            _mapImage.MapQueried += new MapImage.MapQueryHandler(OnMapQueried);

            switch (_mapImage.ActiveTool)
            {
            case MapImage.Tools.Pan:
                _view.PanChecked = true;
                break;

            case MapImage.Tools.Query:
                _view.SelectChecked = true;
                break;

            case MapImage.Tools.ZoomIn:
                _view.ZoomInChecked = true;
                break;

            case MapImage.Tools.ZoomOut:
                _view.ZoomOutChecked = true;
                break;
            }
        }
        static void Main(string[] args)
        {
            SampleServer6.USA_MapServer mapservice = new SampleServer6.USA_MapServer();
            String defaultMapName = mapservice.GetDefaultMapName();

            Console.WriteLine("Map name: " + defaultMapName + "\n");

            MapServerInfo  mapinfo = mapservice.GetServerInfo(defaultMapName);
            MapDescription mapdesc = mapinfo.DefaultMapDescription;
            ImageType      imgtype = new ImageType();

            imgtype.ImageFormat     = esriImageFormat.esriImagePNG;
            imgtype.ImageReturnType = esriImageReturnType.esriImageReturnURL;
            ImageDisplay imgdisp = new ImageDisplay();

            imgdisp.ImageHeight = 500; //pixels
            imgdisp.ImageWidth  = 500; //pixels
            imgdisp.ImageDPI    = 96;
            ImageDescription imgdesc = new ImageDescription();

            imgdesc.ImageDisplay = imgdisp;
            imgdesc.ImageType    = imgtype;
            MapImage mapimg = mapservice.ExportMapImage(mapdesc, imgdesc);

            Console.WriteLine("Output URL:" + mapimg.ImageURL);
            Console.ReadLine();
        }
示例#8
0
        protected override void OnClick()
        {
            var bufZonesLayer = new BufZonesLayer {
                IsAVR = m_MapImage.Parent is AvrMapControl
            };

            if (bufZonesLayer.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var eidssUserBufZoneLayer = UserDbLayersManager.CreateBufZoneLayer(bufZonesLayer.ZoneLayerName,
                                                                                       bufZonesLayer.Description,
                                                                                       bufZonesLayer.PivotalLayer);
                    //MapImage.Map.Layers.Add(eidssUserBufZoneLayer);

                    if (OnCreateBufZone != null)
                    {
                        OnCreateBufZone(new KeyValuePair <Guid, string>(eidssUserBufZoneLayer.LayerDbGuid,
                                                                        eidssUserBufZoneLayer.LayerName));
                    }
                    //MapControl.RefreshContent();
                    MapImage.Refresh();
                    //ZoneLayerStorage.UpdateZoneLayerDict(); //not need more
                }
                catch (Exception ex)
                {
                    ErrorForm.ShowError(ex);
                }
            }
        }
示例#9
0
        private void DrawTerminalSegments(System.Drawing.Point prevPoint, System.Drawing.Point curPoint)
        {
            if (m_Points.Count == 2)
            {
                var graph = MapImage.CreateGraphics();
                graph.DrawLine(new Pen(Color.Black), m_Points[0], m_Points[1]);
            }

            if (curPoint != System.Drawing.Point.Empty)
            {
                ControlPaint.DrawReversibleLine(MapImage.PointToScreen(curPoint), MapImage.PointToScreen(m_Points[0]),
                                                Color.Black);
                if (m_Points.Count > 1)
                {
                    ControlPaint.DrawReversibleLine(MapImage.PointToScreen(curPoint),
                                                    MapImage.PointToScreen(m_Points[m_Points.Count - 1]), Color.Black);
                }
            }

            if (prevPoint != System.Drawing.Point.Empty)
            {
                ControlPaint.DrawReversibleLine(MapImage.PointToScreen(prevPoint), MapImage.PointToScreen(m_Points[0]),
                                                Color.Black);
                if (m_Points.Count > 1)
                {
                    ControlPaint.DrawReversibleLine(MapImage.PointToScreen(prevPoint),
                                                    MapImage.PointToScreen(m_Points[m_Points.Count - 1]), Color.Black);
                }
            }
        }
示例#10
0
        public void MarkDrone(int x, int y)
        {
            const int droneRadius = 2;

            int maxX = (x + droneRadius < Map.Width) ? x + droneRadius : Map.Width;
            int minX = (x - droneRadius > 0) ? x - droneRadius : 0;
            int maxY = (y + droneRadius < Map.Height) ? y + droneRadius : Map.Height;
            int minY = (y - droneRadius > 0) ? y - droneRadius : 0;

            int drawWidth   = maxX - minX;
            int drawHeight  = maxY - minY;
            int localStride = 4 * drawWidth;

            byte[] editArea = new byte[localStride * drawHeight];

            for (int i = 0; i < editArea.Length; i++)
            {
                editArea[i] = 000;
            }

            MapImage.WritePixels(
                new Int32Rect(minX, minY, drawWidth, drawHeight),
                editArea,
                localStride,
                0
                );

            MapImagePane.Source = MapImage;
        }
示例#11
0
        public void OpenExecuted()
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter           = "Image files (*.tif)|*.tif|All Files (*.*)|*.*";
            fileDialog.RestoreDirectory = true;
            if (fileDialog.ShowDialog() == true)
            {
                //CanvasView.Children.Clear();

                gdalReader = new GDALReader();
                gdalReader.Open(fileDialog.FileName);
                MapImage mapImage = gdalReader.GetMapImageInfo();

                if (mapImages.Count == 0)
                {
                    canvasBoundary = mapImage.ImageBoundary;

                    mapImages.Add(mapImage);
                    Init();
                    FitCanvas();
                }
                else
                {
                    if (!AddImage(mapImage))
                    {
                        MessageBox.Show("좌표계가 없어 이미지를 추가 할 수 없습니다.");
                        return;
                    }
                }

                EventAggregator.ImageOpenEvent.Publish(mapImage);
            }
        }
示例#12
0
 public Point ScreenToImage(MapImage mapImage, Point point)
 {
     return(new Point()
     {
         X = point.X / mapImage.ViewWidth * mapImage.ImageWidth,
         Y = point.Y / mapImage.ViewHeight * mapImage.ImageHeight
     });
 }
示例#13
0
 public Form1()
 {
     InitializeComponent();
     g = MapImage.CreateGraphics();
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
     pen             = new Pen(drawcolor, 3);
     pen.StartCap    = pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
 }
示例#14
0
        public void Constructor_CorrectSizeIsSet(int width, int height)
        {
            var image = new MapImage(width, height);

            Assert.That(image,
                Has.Property(nameof(image.Width)).EqualTo(width)
                .And.Property(nameof(image.Height)).EqualTo(height));
        }
示例#15
0
 /// <summary>
 /// 更改地图名称
 /// </summary>
 /// <param name="map"></param>
 /// <param name="tree"></param>
 /// <param name="cmd"></param>
 private void ChangeMapName(MapImage map, MyTree tree, string[] cmd)
 {
     if (cmd.Length != 3)
     {
         return;
     }
     tree.Nodes[0].Text = cmd[2];
 }
示例#16
0
    protected override void Awake()
    {
        base.Awake();
        bool ok = contentPointPrefab ?? true;

        Debug.Assert(ok, "Teleport point not inited!");
        _saver  = FindObjectOfType <Saver>();
        _mapImg = GetComponentInChildren <MapImage>();
    }
示例#17
0
 public FdoMapPreview()
 {
     InitializeComponent();
     img      = new MapImage();
     img.Map  = new Map();
     img.Dock = DockStyle.Fill;
     mapContentPanel.Controls.Add(img);
     _presenter = new FdoMapPreviewPresenter(this, img);
 }
示例#18
0
        private void DrawPolygon()
        {
            if (m_Points.Count < 2)
            {
                return;
            }
            var graph = MapImage.CreateGraphics();

            graph.DrawLines(new Pen(Color.Black), m_Points.ToArray());
        }
示例#19
0
        public GameMap MapCreation(UInt16 MapWidth, UInt16 MapHeight, UInt16 LevelsCount, UInt16 WallsCountOnWalledCells, double WalledCellProbability)
        {
            GameMap game = null;
            Map     map;

            Random rand = new Random();

            try
            {
                MapImage image         = new MapImage(MapImageType.Bmp, null);
                MapPlace place         = new MapPlace(image, (float)0.8);
                MapWall  destroyedWall = new MapWall(image, MapDirection.North, 200);
                MapWall  wall          = new MapWall(image, MapDirection.North, 200);
                Dictionary <MapDirection, MapWall> walls = new Dictionary <MapDirection, MapWall>();

                if (WallsCountOnWalledCells > 0)
                {
                    walls.Add(MapDirection.North, wall);
                }
                if (WallsCountOnWalledCells > 1)
                {
                    walls.Add(MapDirection.South, wall);
                }
                if (WallsCountOnWalledCells > 2)
                {
                    walls.Add(MapDirection.West, wall);
                }
                if (WallsCountOnWalledCells > 3)
                {
                    walls.Add(MapDirection.East, wall);
                }

                bool isWall      = false;
                int  probability = (int)Math.Round(WalledCellProbability * 100.0);

                map = new Map(LevelsCount, new MapSize(MapWidth, MapHeight));
                for (int z = 0; z < map.LevelsCount; z++)
                {
                    for (int x = 0; x < map.Size.Width; x++)
                    {
                        for (int y = 0; y < map.Size.Height; y++)
                        {
                            isWall = rand.Next(0, 100) < probability;
                            map.Levels[z].Cells[x, y] = new MapCell(place, isWall ? walls : null);
                        }
                    }
                }
                game = new GameMap(new MapState(map));
            }
            catch
            {
            }

            return(game);
        }
示例#20
0
        public void ExportImage(string outputDir)
        {
            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }

            var filePath = Path.Combine(outputDir, $"{Name}.png");

            MapImage.Save(filePath, ImageFormat.Png);
        }
示例#21
0
        //マップチップを読み取る
        public Bitmap GetMapChip(int spno)
        {
            // 座標を読み取り.
            var mcpoint = SpliteCell(spno);
            // 座標とサイズを格納.
            Rectangle rect = new Rectangle(mcpoint.X, mcpoint.Y, MapChip, MapChip);
            // 座標とサイズからコピーを作成.
            Bitmap bmpNew = MapImage.Clone(rect, MapImage.PixelFormat);

            // コピーを返す.
            return(bmpNew);
        }
示例#22
0
        public void UpdateMapImage(Mission mission)
        {
            var scene    = mission.Scene;
            var newImage = new ImageRGBA(BitmapWidth, BitmapHeight);

            SampleTerrainHeight(scene, newImage, BitmapWidth, BitmapHeight, MapBoundMin.x, MapBoundMin.y, Resolution);
            SampleBoundaries(mission, newImage, BitmapWidth, BitmapHeight, MapBoundMin.x, MapBoundMin.y, Resolution);

            MapImage   = newImage;
            MapTexture = MapImage.CreateTexture();
            IsValid    = true;
        }
        public MainWindow()
        {
            InitializeComponent();

            StartupResourceLoader.Init();

            m_mapImage = new MapImage();
            Loaded += MainWindow_Loaded;
            Closed += MainWindow_Closed;

            m_isInputActive = true;
        }
示例#24
0
        public void SetTile_CorrectTileIsSet(int x, int y)
        {
            var image = new MapImage(100, 15);
            var expected = XType.Wall;

            image.SetTile(new Point(x, y), expected);

            Assert.That(image[x, y],
                Has.Property(nameof(Tile.Type)).EqualTo(expected));
            Assert.That(image, Has.Exactly(1)
                .With.Property(nameof(Tile.Type)).EqualTo(expected));
        }
示例#25
0
 public void TestConversion()
 {
     try
     {
         byte[]      data  = new byte[] { 1, 2, 3, 4, 5 };
         MapImage    tile  = new MapImage(MapImageType.Bmp, data);
         MapImageWPF image = new MapImageWPF(tile);
     }
     catch (Exception ex)
     {
         Assert.IsInstanceOfType(ex, typeof(InvalidDataException));
     }
 }
示例#26
0
        void MapImage_MouseDown(SharpMap.Geometries.Point worldPos, MouseEventArgs e)
        {
            if (m_TargetLayerGuid == Guid.Empty)
            {
                return;
            }

            if (!m_IsMoveMode)
            {
                var area      = GIS_V4.Utils.GeometryUtils.PointToArea(worldPos, 3, MapImage.Map.PixelWidth);
                var fds       = new FeatureDataSet();
                var zoneLayer = UserDbLayersManager.GetUserLayer(m_TargetLayerGuid);
                zoneLayer.DataSource.ExecuteIntersectionQuery(area.GetBoundingBox(), fds);

                if (fds.Tables.Count <= 0)
                {
                    m_SelectedFeature = null;
                    return;
                }

                if (fds.Tables[0].Rows.Count <= 0)
                {
                    m_SelectedFeature = null;
                    MapImage.RefreshFromCache();
                    return;
                }

                m_SelectedFeature = fds.Tables[0][0];

                MapImage.RefreshFromCache();
            }
            else
            {
                //tool in move mode
                if (e.Button == MouseButtons.Left)
                {
                    //start shifting on mouse move
                    m_IsShifting    = true;
                    m_ShiftBeginPnt = worldPos;
                    m_LastShiftPnt  = new SharpMap.Geometries.Point(worldPos.X, worldPos.Y);
                }
            }

            if (m_SelectedFeature != null && e.Button == MouseButtons.Right)
            {
                if (m_SelectedFeature.Geometry.GetBoundingBox().Contains(worldPos))
                {
                    m_CMenu.Show(MapImage, e.Location);
                }
            }
        }
示例#27
0
        void ReleaseDesignerOutlets()
        {
            if (MapImage != null)
            {
                MapImage.Dispose();
                MapImage = null;
            }

            if (MapLabel != null)
            {
                MapLabel.Dispose();
                MapLabel = null;
            }
        }
示例#28
0
        public MapImage GetMapImageInfo()
        {
            MapImage mapImage      = new MapImage(GetHeaderInfo(), filePath);
            Boundary ImageBoundary = null;

            if (GeometryControl.GetImageBoundary(dataset, out double minX, out double minY, out double maxX, out double maxY))
            {
                ImageBoundary = new Boundary(minX, minY, maxX, maxY, 0, 0);
            }

            mapImage.ImageBoundary = ImageBoundary;

            return(mapImage);
        }
示例#29
0
        public static MapImageDTO ToObjectDTOTranfer(MapImage mapImage)
        {
            return(new MapImageDTO
            {
                BitmapMapsStream = mapImage.BitmapMapsStream,
                Latitude = mapImage.Latitude,
                Longitude = mapImage.Longitude,
                GetMaker = mapImage.GetMaker,
                Zoom = mapImage.Zoom,

                Width = mapImage.Width,
                Height = mapImage.Height
            });
        }
示例#30
0
        /// <summary>
        /// 元素名称变更
        /// </summary>
        /// <param name="map"></param>
        /// <param name="tree"></param>
        /// <param name="cmd"></param>
        private void ChangeObjectName(MapImage map, MyTree tree, string[] cmd)
        {
            if (cmd.Length != 5)
            {
                return;
            }
            TreeNode node = FindObject(tree.Nodes[0], GetId(cmd[2]), GetId(cmd[3]));

            if (node == null)
            {
                return;
            }
            node.Text = cmd[4];
        }
示例#31
0
        /// <summary>
        /// 图层名称变更
        /// </summary>
        /// <param name="map"></param>
        /// <param name="tree"></param>
        /// <param name="cmd"></param>
        private void ChangeLayerName(MapImage map, MyTree tree, string[] cmd)
        {
            if (cmd.Length != 4)
            {
                return;
            }
            TreeNode node = FindLayer(tree.Nodes[0], GetId(cmd[2]));

            if (node == null)
            {
                return;
            }
            node.Text = cmd[3];
        }
示例#32
0
        void m_MapImage_MouseUp(SharpMap.Geometries.Point worldPos, MouseEventArgs imagePos)
        {
            if (m_IsShifting && m_IsMoveMode && imagePos.Button == MouseButtons.Left)
            {
                //stop shifting
                m_IsShifting = false;
                //save last shift-position into buffer zone

                var zone = m_BufZoneLayer.FeatureRowToStruct(m_SelectedFeature);

                var deltaX = worldPos.X - m_ShiftBeginPnt.X;
                var deltaY = worldPos.Y - m_ShiftBeginPnt.Y;

                if (zone.Radius > 0)
                {
                    //circle
                    zone.Center.X = zone.Center.X + deltaX;
                    zone.Center.Y = zone.Center.Y + deltaY;

                    zone.Geometry = GIS_V4.Utils.GeometryUtils.CreateBuffer(zone.Center, zone.Radius);

                    m_BufZoneLayer.UpdateZone(zone);

                    m_SelectedFeature.Geometry      = zone.Geometry;
                    m_SelectedFeature["dblCenterX"] = zone.Center.X;
                    m_SelectedFeature["dblCenterY"] = zone.Center.Y;
                }
                else
                {
                    //polygon
                    if (m_SelectedFeature.Geometry is Polygon)
                    {
                        var geom = (Polygon)m_SelectedFeature.Geometry;

                        //foreach (var vertex in geom.ExteriorRing.Vertices)
                        //{
                        //    vertex.X = vertex.X + deltaX;
                        //    vertex.Y = vertex.Y + deltaY;
                        //}
                        zone.Geometry = new Polygon(geom.ExteriorRing);

                        m_SelectedFeature.Geometry = zone.Geometry;
                        m_BufZoneLayer.UpdateZone(zone);
                    }
                }

                MapImage.Refresh();
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            StartupResourceLoader.Init();


            m_mapImage = new MapImage();
            Loaded    += MainWindow_Loaded;
            Closed    += MainWindow_Closed;


            m_frameTimer = Stopwatch.StartNew();

            m_isInputActive = true;
        }
示例#34
0
        public Business_Objects.MapImage GetMapImages(double lat, double lng, int zoom, int width, int height, string maker)
        {
            MapImage mapImage = new MapImage(lat, lng, zoom, width, height, maker);
            Bitmap   bitmap   = new Bitmap((int)(width), (int)(height));

            bitmap = (Bitmap)GoogleMapCore.GoogleMapsShared.GetMapImage(mapImage.Latitude, mapImage.Longitude, mapImage.Zoom, mapImage.Width, mapImage.Height, mapImage.GetMaker);

            using (MemoryStream tempStream = new MemoryStream())
            {
                bitmap.Save(tempStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                mapImage.BitmapMapsStream = new byte[tempStream.Length];
                tempStream.Position       = 0;
                tempStream.Read(mapImage.BitmapMapsStream, 0, (int)tempStream.Length);
            }
            return(mapImage);
        }
示例#35
0
 public void DrawMap(MapImage map)
 {
     var gameInfoEnumerator = Messages.GetGameInfo().GetEnumerator();
     for (int y = 0; y < map.Height; y++)
     {
         for (int x = 0; x < map.Width; x++)
         {
             Console.ForegroundColor = SetColor(map[x, y].Type);
             Console.Write(GetImage(map[x, y].Type));
         }
         if (gameInfoEnumerator.MoveNext())
         {
             Console.Write(Messages.GameStatusSpace + gameInfoEnumerator.Current);
         }
         Console.WriteLine();
     }
 }
        /// <summary>
        /// Creates UIElement for stop.
        /// </summary>
        /// <param name="stop">Stop as source.</param>
        /// <param name="mapImage">Map image.</param>
        /// <param name="fillingBrush">Filling brush.</param>
        /// <returns>Created element fro stop.</returns>
        private UIElement _CreateStopUIElement(Stop stop,
                                               MapImage mapImage,
                                               SolidColorBrush fillingBrush)
        {
            Debug.Assert(null != stop);
            Debug.Assert(null != mapImage);
            Debug.Assert(null != fillingBrush);

            UIElement element = null;
            if (stop.AssociatedObject is Order)
            {
                SysWindows.Point position =
                    _ConvertPoint(stop.MapLocation.Value,
                                  (EnvelopeN)mapImage.Extent,
                                  mapImage.ImageWidth,
                                  mapImage.ImageHeight);

                var stopSymbolBox = new SymbolControl(_sequenceSymbolTemplate);
                stopSymbolBox.Margin = new Thickness(position.X, position.Y, 0, 0);
                stopSymbolBox.SequenceNumber = stop.OrderSequenceNumber.Value.ToString();
                stopSymbolBox.Fill = fillingBrush;

                element = stopSymbolBox;
            }

            else if (stop.AssociatedObject is Location)
            {
                SysWindows.Point position =
                    _ConvertPoint(stop.MapLocation.Value,
                                  (EnvelopeN)mapImage.Extent,
                                  mapImage.ImageWidth,
                                  mapImage.ImageHeight);

                var control = new SysControls.Control();
                control.Template = _stopSymbolTemplate;
                control.Margin = new Thickness(position.X, position.Y, 0, 0);

                element = control;
            }

            // else Do nothing

            return element;
        }
        /// <summary>
        /// Creates image from canvas with map background.
        /// </summary>
        /// <param name="mapImage">Map image.</param>
        /// <param name="canvas">Canvas to draw.</param>
        /// <returns>Created image.</returns>
        private Image _CreateImage(MapImage mapImage, SysControls.Canvas canvas)
        {
            Debug.Assert(null != mapImage);
            Debug.Assert(null != canvas);

            Image imageWithData = null;

            RenderTargetBitmap bmp = null;
            SysControls.Canvas outer = null;

            Image sourceImage = null;
            using (MemoryStream sourceStream = new MemoryStream((byte[])mapImage.ImageData))
                sourceImage = Image.FromStream(sourceStream);

            try
            {

                var bitmap = sourceImage as Bitmap;
                Debug.Assert(null != bitmap);
                ImageBrush imageBrush = _CreateImageBrush(bitmap);

                outer = new SysControls.Canvas();

                outer.Width = mapImage.ImageWidth;
                outer.Height = mapImage.ImageHeight;
                outer.Children.Add(canvas);
                outer.Background = (ImageBrush)imageBrush.GetCurrentValueAsFrozen();
                outer.Arrange(new Rect(0, 0, outer.Width, outer.Height));

                bmp = new RenderTargetBitmap((int)outer.Width,
                                             (int)outer.Height,
                                             mapImage.ImageDPI,
                                             mapImage.ImageDPI,
                                             PixelFormats.Pbgra32);
                bmp.Render(outer);

                var encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmp));

                using (MemoryStream stream = new MemoryStream())
                {
                    encoder.Save(stream);
                    imageWithData = Image.FromStream(stream);
                }
            }
            finally
            {   // Clear and dispose all used stuff
                if (outer != null)
                {
                    outer.UpdateLayout();
                    outer.Children.Clear();
                }

                canvas.UpdateLayout();
                foreach (object child in canvas.Children)
                {
                    var symbolControl = child as SymbolControl;
                    if (symbolControl != null)
                        symbolControl.Template = null;
                }
                canvas.Children.Clear();

                if (bmp != null)
                    bmp.Clear();

                if (sourceImage != null)
                    sourceImage.Dispose();
            }

            return imageWithData;
        }
示例#38
0
        private static MapImage GetMapPicture(IGameDungeon dungeon)
        {
            var image = new MapImage(dungeon.Width, dungeon.Height);

            for (int x = 0; x < dungeon.Width; x++)
                for (int y = 0; y < dungeon.Height; y++)
                {
                    var cell = dungeon[x, y];
                    image.SetTile(cell.Location, cell.Type);
                }

            image.SetTile(dungeon.Character.Location, dungeon.Character.Type);

            return image;
        }
 public static void SerializeMapImage(BinaryWriter Writer, MapImage Image)
 {
     if ((Image == null) || (Image.Data == null) || (Image.Data.Length == 0))
     {
         SerializeMapImageType(Writer, MapImageType.Null);
     }
     else
     {
         SerializeMapImageType(Writer, Image.Type);
         //SerializeMapSize(Writer, Image.Size);
         SerializeLength(Writer, Image.Data);
         if ((Image.Data != null) && (Image.Data.Length > 0))
             Writer.Write(Image.Data);
     }
 }
        /// <summary>
        /// Creates canvas with invalidated route and its stops.
        /// </summary>
        /// <param name="route">Route to draw.</param>
        /// <param name="sortedRouteStops">Sorted stops from route.</param>
        /// <param name="mapImage">Map image.</param>
        /// <returns>Canvas with invalidated route and its stops.</returns>
        private SysControls.Canvas _CreateRouteCanvas(Route route, IList<Stop> sortedRouteStops, MapImage mapImage)
        {
            Debug.Assert(null != route);
            Debug.Assert(null != mapImage);
            Debug.Assert(null != sortedRouteStops);

            // create canvas
            var canvas = new SysControls.Canvas();
            canvas.InvalidateVisual();
            canvas.Height = mapImage.ImageHeight;
            canvas.Width = mapImage.ImageWidth;

            // init route brush from route color
            System.Drawing.Color color = route.Color;
            var mediaColor =
                SysWindows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);
            var fillingBrush = new SolidColorBrush(mediaColor);

            // create and init route image
            SymbolControl routeBox = new SymbolControl(_routeSymbolTemplate);
            routeBox.Geometry = _CreatePath(route,
                                            sortedRouteStops,
                                            mapImage.Extent,
                                            mapImage.ImageWidth,
                                            mapImage.ImageHeight);
            routeBox.Fill = (SolidColorBrush)fillingBrush.GetCurrentValueAsFrozen();
            routeBox.HorizontalAlignment = HorizontalAlignment.Stretch;
            routeBox.VerticalAlignment = VerticalAlignment.Stretch;
            // draw route
            canvas.Children.Add(routeBox);

            // draw stops - from last to first (visual elements)
            int stopLastIndex = sortedRouteStops.Count - 1;
            for (int index = stopLastIndex; index >= 0; --index)
            {
                Stop stop = sortedRouteStops[index];
                if (!stop.MapLocation.HasValue)
                    continue; // skip empty

                bool isVisible = true;
                if (stop.AssociatedObject is Location)
                {
                    if (index == 0)
                    {
                        isVisible = _showLeadingStemTime;
                    }
                    else if (index == stopLastIndex)
                    {
                        isVisible = _showTrailingStemTime;
                    }
                    // else do nothing
                }

                if (isVisible)
                {
                    UIElement element = _CreateStopUIElement(stop, mapImage, fillingBrush);
                    if (element != null)
                        canvas.Children.Add(element);
                }
            }

            return canvas;
        }