示例#1
0
        private void GenerateTile(double startX, double startY, double initTileGap, int imageSize, int imageBuffer, string savePath, int z, int x, int y, string imageFormat)
        {
            try
            {
                // active map variable
                map.setSize(imageSize + (imageBuffer * 2), imageSize + (imageBuffer * 2));

                // 0/0/0 tile variables
                double startPointX = startX;
                double startPointY = startY;
                double initGap     = initTileGap; // inital distance between tiles, for level 0 is max meters - min meters

                // meta-buffer to fix labeling as a multiplier
                double buffer = 1 + ((double)imageBuffer / (double)imageSize);

                // find the spacing between each tile for level
                double gap = (initGap / Math.Pow(2, z));

                // buffer in meters for each level
                double buffermeters = (gap * buffer) - gap;

                // set map extents for tile x values
                map.extent.minx = (startPointX + (gap * x)) - buffermeters;
                map.extent.maxx = (startPointX + (gap * x) + gap) + buffermeters;

                // set map extents for tile y values
                map.extent.miny = (startPointY + (gap * y)) - buffermeters;
                map.extent.maxy = (startPointY + (gap * y) + gap) + buffermeters;

                // generate map image
                using (imageObj image = map.draw())
                {
                    Image mapImage;

                    byte[] img = image.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        mapImage = Image.FromStream(ms);
                        ms.Flush();

                        // clip buffer area off generated image
                        if (!(buffer == 0))
                        {
                            Rectangle cropRect = new Rectangle(imageBuffer, imageBuffer, imageSize, imageSize);
                            Bitmap    bmpImage = new Bitmap(mapImage);
                            Bitmap    bmpCrop  = bmpImage.Clone(cropRect, bmpImage.PixelFormat);
                            mapImage = (Image)(bmpCrop);
                        }

                        // save image to disk in TMS format location
                        System.IO.Directory.CreateDirectory(savePath + "\\" + z + "\\" + x);
                        if (imageFormat == "png")
                        {
                            mapImage.Save(savePath + "\\" + z + "\\" + x + "\\" + y + "." + imageFormat, ImageFormat.Png);
                        }
                        if (imageFormat == "jpg")
                        {
                            mapImage.Save(savePath + "\\" + z + "\\" + x + "\\" + y + "." + imageFormat, ImageFormat.Jpeg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionDump(ex);
            }
        }
示例#2
0
        /// <summary>
        /// refresh the map,can reread the origin mapfile
        /// </summary>
        /// <param name="reload"></param>
        public void refreshMap(bool reload)
        {
            if (_Map == null)
            {
                if (this.BackgroundImage != null)
                    this.BackgroundImage = null;
                return;
            }

            if (reload)
            {
                if (_Map != null)
                    _Map.Dispose();

                try
                {

                    //_TempMapfilePath = CreateTempMapfile(_MapfilePath);

                    _Map = new mapObj(_TempMapfilePath);
                    _Map.setSize(m_viewWidth, m_viewHeight);
                    _Map.extent.minx = m_Curextents.Left;
                    _Map.extent.maxx = m_Curextents.Right;
                    _Map.extent.miny = m_Curextents.Bottom;
                    _Map.extent.maxy = m_Curextents.Top;

                    drawImg2Mapcontrol();

                    //fire the mapreplaced event
                    if (this.OnMapReplaced != null)
                        OnMapReplaced(null, new EventArgs());
                }
                catch (Exception ex)
                {
                    if (ErrorOccured != null)
                        ErrorOccured(null, new MSErrorEventArgs(ex.Message));
                    closeMapfile();
                }
            }
            else
            {
                try
                {
                    _Map.setSize(m_viewWidth, m_viewHeight);

                    drawImg2Mapcontrol();

                    calculateNewScale();

                    m_Curextents = new Extent(_Map.extent.minx, _Map.extent.maxx, _Map.extent.miny, _Map.extent.maxy);

                    {
                        double geoWidth = Math.Abs(m_Curextents.Right - m_Curextents.Left);
                        double geoHeight = Math.Abs(m_Curextents.Top - m_Curextents.Bottom);

                        if (geoWidth == 0)
                        {
                            m_pixelPerProjectionX = 0;
                            m_inversePixelPerProjectionX = 0;
                        }
                        else
                        {
                            m_pixelPerProjectionX = m_viewWidth / geoWidth;
                            m_inversePixelPerProjectionX = 1.0 / m_pixelPerProjectionX;
                        }

                        if (geoHeight == 0)
                        {
                            m_pixelPerProjectionY = 0;
                            m_inversePixelPerProjectionY = 0;
                        }
                        else
                        {
                            m_pixelPerProjectionY = m_viewHeight / geoHeight;
                            m_inversePixelPerProjectionY = 1.0 / m_pixelPerProjectionY;
                        }
                    }

                    ChecktLayerState();
                }
                catch(Exception ex)
                {
                    MessageBox.Show("Error:" + ex.Message,"��ʾ");
                }

            }
        }