GetMap() public method

Renders the map to an image
public GetMap ( ) : System.Drawing.Image
return System.Drawing.Image
示例#1
1
        /// <summary>
        /// Creates an instance of this class
        /// </summary>
        public MagnifierTool(MapBox parentMapBox) 
            : base("Magnifier", "A tool to magnify the portion of the map below the cursor")
        {
            _parentMapBox = parentMapBox;
            _parentMapBox.MapChanged += HandleMapChanged;
            Map = _parentMapBox.Map;

            MagnificationFactor = 1.10;

            Offset = new Size(5,5);

            _magnified = new PictureBox();
            _magnified.Size = new Size(75, 75);
            _magnified.BorderStyle = BorderStyle.FixedSingle;
            _magnified.Visible = false;

            _parentMapBox.Controls.Add(_magnified);

            Map = _parentMapBox.Map;
            _map = Map.Clone();
            _map.Size = _magnified.Size;
            _map.Zoom = _map.Size.Width*(Map.Envelope.Width/Map.Size.Width) / _magnification;
            _map.Center = _map.Center;
            _magnified.Image = _map.GetMap();

            Enabled = true;

            var ms = Assembly.GetExecutingAssembly().GetManifestResourceStream("WinFormSamples.Magnifier.cur");
            if (ms != null)
                Cursor = new Cursor(ms);
        }
示例#2
0
    /// <summary>
    /// Creates the map, inserts it into the cache and sets the ImageButton Url
    /// </summary>
    private void CreateMap()
    {
        System.Drawing.Image img = myMap.GetMap();
        string imgID             = SharpMap.Web.Caching.InsertIntoCache(1, img);

        imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);
    }
示例#3
0
        private static void TestMaps(string name, Map m, Map mD)
        {
            Assert.NotNull(mD);

            Assert.AreEqual(m.Size, mD.Size);
            Assert.AreEqual(m.Layers.Count, mD.Layers.Count);
            var c = new LayerTest.VectorLayerEqualityComparer();
            for (var i = 0; i < m.Layers.Count; i++)
            {
                Assert.IsTrue(c.Equals((VectorLayer)m.Layers[i], 
                                       (VectorLayer)mD.Layers[i]), 
                                       "Layer {0}, '{1}' Differs at {2}",
                                       i, m.Layers[i].LayerName, string.Join(", ", c.DifferAt));
            }

            Assert.AreEqual(m.PixelAspectRatio, mD.PixelAspectRatio);
            Assert.AreEqual(m.PixelHeight, mD.PixelHeight);
            Assert.AreEqual(m.PixelWidth, mD.PixelWidth);
            Assert.AreEqual(m.PixelSize, mD.PixelSize);

            Assert.AreEqual(m.BackColor, mD.BackColor);
            Assert.IsTrue(m.Center.Equals(mD.Center));
            Assert.IsTrue(m.GetExtents().Equals(mD.GetExtents()));
            Assert.IsTrue(m.Envelope.Equals(mD.Envelope));

            Assert.AreEqual(m.Decorations.Count, mD.Decorations.Count);
            Assert.AreEqual(m.SRID, mD.SRID);
            Assert.AreEqual(m.Zoom, mD.Zoom);

            Assert.DoesNotThrow(() => m.GetMap().Save(name + "-S.bmp"));
            Assert.DoesNotThrow(() => mD.GetMap().Save(name + "-D.bmp"));
        }
示例#4
0
        public void TestPlainPolygonSymbolizer()
        {
            ShapeFile provider = new ShapeFile(
                "..\\..\\..\\WinFormSamples\\GeoData\\World\\countries.shp", true);
            PolygonalVectorLayer l = new PolygonalVectorLayer("Countries", provider);
            l.Symbolizer = new ModifiedBasicPolygonSymbolizer
                {
                    Fill = new HatchBrush(
                            HatchStyle.WideDownwardDiagonal, 
                            Color.Red /*,
                            System.Drawing.Color.LightPink*/),
                    UseClipping = false,
                    //Outline = System.Drawing.Pens.AliceBlue
                };

            Map m = new Map(new Size(1440, 1080)) { BackColor = Color.Cornsilk };
            m.Layers.Add(l);

            m.ZoomToExtents();

            Stopwatch sw = new Stopwatch();
            Image img = m.GetMap();
            
            sw.Start();
            img = m.GetMap();
            img.Save("PolygonSymbolizer-1.bmp", ImageFormat.Bmp);
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds));

            l.Symbolizer = new BasicPolygonSymbolizer()
            {
                Fill = new HatchBrush(
                        HatchStyle.WideDownwardDiagonal,
                        Color.Red/*,
                        System.Drawing.Color.LightPink*/),
                UseClipping = false,
                //Outline = System.Drawing.Pens.AliceBlue
            };

            sw.Reset(); sw.Start();
            img = m.GetMap();
            img.Save("PolygonSymbolizer-2.bmp", ImageFormat.Bmp);
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds));
        
        }
示例#5
0
    /// <summary>
    /// Creates the map, inserts it into the cache and sets the ImageButton Url
    /// </summary>
    private void GenerateMap()
    {
        //Save the current mapcenter and zoom in the viewstate
        ViewState.Add("mapCenter", myMap.Center);
        ViewState.Add("mapZoom", myMap.Zoom);
        System.Drawing.Image img = myMap.GetMap();
        string imgID             = SharpMap.Web.Caching.InsertIntoCache(1, img);

        imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);
    }
示例#6
0
        /// <summary>
        /// Refreshes the mapControl
        /// </summary>
        public override void Refresh()
        {
            try {
                if (_Map != null)
                {
                    _Map.Size = ClientSize;
                    if (_Map.Layers == null || _Map.Layers.Count == 0)
                    {
                        m_Image = null;
                    }
                    else
                    {
                        Cursor c = Cursor;
                        try {
                            Cursor  = Cursors.WaitCursor;
                            m_Image = _Map.GetMap();
                        } finally {
                            Cursor = c;
                        }
                    }

                    if (m_Image != null && _legend != null)
                    {
                        if (_legend.IsVisible)
                        {
                            _legend.Draw(m_Image);
                        }
                    }

                    base.Refresh();

                    if (MapRefreshed != null)
                    {
                        MapRefreshed(this, null);
                    }
                }
            } catch (Exception ex) {
                // ignore
                Logger.Debug(ex.ToString());
            }
        }
示例#7
0
        public void TestMapDecorationTest()
        {
            var m = new Map(new Size(780, 540)) {BackColor = Color.White};
            var p = new GeometryProvider(new List<SharpMap.Geometries.Geometry>());
            var pts = new [] {new GeoPoint(0, 0), new GeoPoint(779, 539)};
            var ls = new SharpMap.Geometries.LineString(new List<GeoPoint>(pts));
            p.Geometries.Add(ls);
            m.Layers.Add(new VectorLayer("t",p));
            m.ZoomToExtents();

            m.Decorations.Add(new TestDecoration
                                  {
                                      Anchor = MapDecorationAnchor.LeftTop,
                                      BorderColor = Color.Green,
                                      BackgroundColor = Color.LightGreen,
                                      BorderWidth = 2,
                                      Location = new Point(10, 10),
                                      BorderMargin = new Size(5, 5),
                                      RoundedEdges = true,
                                      Opacity = 0.6f
                                  });

            m.Decorations.Add(new TestDecoration
            {
                Anchor = MapDecorationAnchor.RightTop,
                BorderColor = Color.Red,
                BackgroundColor = Color.LightCoral,
                BorderWidth = 2,
                Location = new Point(10, 10),
                BorderMargin = new Size(5, 5),
                RoundedEdges = true,
                Opacity = 0.2f
            });

            m.Decorations.Add(new ScaleBar
            {
                Anchor = MapDecorationAnchor.Default,
                BorderColor = Color.Blue,
                BackgroundColor = Color.CornflowerBlue,
                BorderWidth = 2,
                Location = new Point(10, 10),
                BorderMargin = new Size(5, 5),
                RoundedEdges = true,
                BarWidth = 4,
                ScaleText =ScaleBarLabelText.RepresentativeFraction,
                NumTicks = 2,
                Opacity = 1f
            });
            var bmp = m.GetMap();
            bmp.Save("TestMapDecorationTest.bmp");
        }
示例#8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int    Width   = 0;
        int    Height  = 0;
        double centerX = 0;
        double centerY = 0;
        double Zoom    = 0;

        string[] Layer;

        //Parse request parameters
        if (!int.TryParse(Request.Params["WIDTH"], out Width))
        {
            throw(new ArgumentException("Invalid parameter"));
        }
        if (!int.TryParse(Request.Params["HEIGHT"], out Height))
        {
            throw (new ArgumentException("Invalid parameter"));
        }
        if (!double.TryParse(Request.Params["ZOOM"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out Zoom))
        {
            throw (new ArgumentException("Invalid parameter"));
        }
        if (!double.TryParse(Request.Params["X"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out centerX))
        {
            throw (new ArgumentException("Invalid parameter"));
        }
        if (!double.TryParse(Request.Params["Y"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out centerY))
        {
            throw (new ArgumentException("Invalid parameter"));
        }

        //Params OK
        SharpMap.Map map = InitializeMap(new System.Drawing.Size(Width, Height));

        map.Center = new GeoAPI.Geometries.Coordinate(centerX, centerY);
        map.Zoom   = Zoom;

        //Generate map
        System.Drawing.Bitmap img = (System.Drawing.Bitmap)map.GetMap();

        //Stream the image to the client
        Response.ContentType = "image/png";
        System.IO.MemoryStream MS = new System.IO.MemoryStream();
        img.Save(MS, System.Drawing.Imaging.ImageFormat.Png);

        // tidy up
        img.Dispose();
        byte[] buffer = MS.ToArray();
        Response.OutputStream.Write(buffer, 0, buffer.Length);
    }
示例#9
0
        public void TestBasicLineSymbolizer()
        {
            ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\roads.shp", false);
            VectorLayer l = new VectorLayer("roads", p);
            //l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5);
            l.Style.Line = new Pen(Color.Gold, 1);
            l.Style.EnableOutline = false;
            Map m = new Map(new Size(1440, 1080)) { BackColor = Color.Cornsilk };
            m.Layers.Add(l);

            m.ZoomToExtents();

            Stopwatch sw = new Stopwatch();
            sw.Start();
            m.GetMap();

            sw.Stop();
            Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
            sw.Reset();
            sw.Start();
            Image bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("NDSRoads1.bmp");


            CachedLineSymbolizer cls = new CachedLineSymbolizer();
            //cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5) });
            cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Gold, 1) });

            l.Style.LineSymbolizer = cls;
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("NDSRoads2.bmp");

        }
示例#10
0
    /// <summary>
    /// Creates the map, inserts it into the cache and sets the ImageButton Url
    /// </summary>
    private void GenerateMap()
    {
        //Save the current mapcenter and zoom in the viewstate
        ViewState.Add("mapCenter", myMap.Center);
        ViewState.Add("mapZoom", myMap.Zoom);
        ViewState.Add("currentProj", ddlProjection.SelectedValue);
        //Render the map
        System.Drawing.Image img = myMap.GetMap();
        string imgID             = SharpMap.Web.Caching.InsertIntoCache(1, img);

        imgMap.ImageUrl  = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);
        litEnvelope.Text = myMap.Envelope.Left.ToString("#.##") + "," + myMap.Envelope.Bottom.ToString("#.##") + " -> " +
                           myMap.Envelope.Right.ToString("#.##") + "," + myMap.Envelope.Top.ToString("#.##") + " (Projected coordinate system)";
    }
示例#11
0
        public void TestMapDecorationTest()
        {
            Map m = new Map(new Size(780, 540)) {BackColor = Color.White, SRID = 0};
            GeoPoint[] pts = new [] {new GeoPoint(0, 0), new GeoPoint(779, 539)};
            FeatureProvider p = new FeatureProvider(m.Factory.CreateLineString(pts));
            m.Layers.Add(new VectorLayer("t",p));
            m.ZoomToExtents();

            m.Decorations.Add(new TestDecoration
                                  {
                                      Anchor = MapDecorationAnchor.LeftTop,
                                      BorderColor = Color.Green,
                                      BackgroundColor = Color.LightGreen,
                                      BorderWidth = 2,
                                      Location = new Point(10, 10),
                                      BorderMargin = new Size(5, 5),
                                      RoundedEdges = true,
                                      Opacity = 0.6f
                                  });

            m.Decorations.Add(new TestDecoration
            {
                Anchor = MapDecorationAnchor.RightTop,
                BorderColor = Color.Red,
                BackgroundColor = Color.LightCoral,
                BorderWidth = 2,
                Location = new Point(10, 10),
                BorderMargin = new Size(5, 5),
                RoundedEdges = true,
                Opacity = 0.2f
            });

            m.Decorations.Add(new ScaleBar
            {
                Anchor = MapDecorationAnchor.Default,
                BorderColor = Color.Blue,
                BackgroundColor = Color.CornflowerBlue,
                BorderWidth = 2,
                Location = new Point(10, 10),
                BorderMargin = new Size(5, 5),
                RoundedEdges = true,
                BarWidth = 4,
                ScaleText =ScaleBarLabelText.RepresentativeFraction,
                NumTicks = 2,
                Opacity = 1f
            });
            Image bmp = m.GetMap();
            bmp.Save("TestMapDecorationTest.bmp");
        }
示例#12
0
        public void TestGetMap()
        {
            var m = new Map(new Size(500, 300));
            m.BackColor = Color.White;

            var p = KmlProvider.FromKml(@"TestData\KML_Samples.kml");
            var l = new VectorLayer(p.ConnectionID, p);
            l.Theme = p.GetKmlTheme();

            m.Layers.Add(l);
            m.ZoomToExtents();
            m.Zoom *= 1.1;

            var img = m.GetMap();
            img.Save("KmlProviderImage.png", ImageFormat.Png);
        }
示例#13
0
        public void TestRender()
        {
            var style = new SharpMap.Styles.GroupStyle();
             var vStyle = new SharpMap.Styles.VectorStyle()
             {
                 Enabled = true,
                 PointColor = Brushes.Red,
                 PointSize = 6
             };
             style.AddStyle(vStyle);

             vStyle = new SharpMap.Styles.VectorStyle()
             {
                 Enabled = true,
                 PointColor = Brushes.White,
                 PointSize = 2
             };
             style.AddStyle(vStyle);

             Assert.AreEqual(2, style.Count);
             Assert.AreEqual(Color.Red, (style[0].PointColor as SolidBrush).Color);

             VectorLayer vLay = new VectorLayer("test");
             vLay.Style = style;

             vLay.DataSource = new SharpMap.Data.Providers.GeometryProvider("POINT(0 0)");

             Map m = new Map(new Size(11, 11));
             m.BackColor = Color.White;
             m.ZoomToBox(new GeoAPI.Geometries.Envelope(-5, 5, -5, 5));
             m.Layers.Add(vLay);
             var img = m.GetMap();

             //img.Save(@"c:\\temp\ren.png");

             Bitmap bmp = img as Bitmap;
             Color c1 = bmp.GetPixel(5, 5);
             Assert.AreEqual(Color.White.ToArgb(), c1.ToArgb());
             c1 = bmp.GetPixel(3, 5);
             Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb());
             c1 = bmp.GetPixel(7, 5);
             Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb());
             c1 = bmp.GetPixel(5, 3);
             Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb());
             c1 = bmp.GetPixel(5, 7);
             Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb());
        }
示例#14
0
 public void TestTransparency()
 {
     var tmpFile = GdiImageLayerTest.CreateImage(new Size(300, 300), new Point(10, 10));
     using(var l = new GdiImageLayer(tmpFile))
     using (var pl = new GdiImageLayerProxy<GdiImageLayer>(l, 0.3f))
     using (var m = new Map(new Size(450, 450)))
     {
         m.Layers.Add(pl);
         m.ZoomToExtents();
         using (var img = (Bitmap)m.GetMap())
         {
             var color = img.GetPixel(225, 225);
             Assert.LessOrEqual(Math.Abs((int)Math.Round(0.3f*255, MidpointRounding.AwayFromZero) - color.A),1);
         }
     }
     GdiImageLayerTest.DeleteTmpFiles(tmpFile);
 }
示例#15
0
 public void TestColorMap()
 {
     var tmpFile = GdiImageLayerTest.CreateImage(new Size(300, 300), new Point(10, 10));
     using (var l = new GdiImageLayer(tmpFile))
     using (var pl = new GdiImageLayerProxy<GdiImageLayer>(l, new ColorMap{OldColor = Color.Red, NewColor = Color.MistyRose}))
     using (var m = new Map(new Size(450, 450)))
     {
         m.Layers.Add(pl);
         m.ZoomToExtents();
         using (var img = (Bitmap)m.GetMap())
         {
             var color = img.GetPixel(225, 225);
             Assert.AreEqual(Color.MistyRose.ToArgb(), color.ToArgb());
         }
     }
     GdiImageLayerTest.DeleteTmpFiles(tmpFile);
 }
示例#16
0
    /// <summary>
    /// Creates the map, inserts it into the cache and sets the ImageButton Url
    /// </summary>
    private void GenerateMap()
    {
        //Save the current mapcenter and zoom in the viewstate
        ViewState.Add("mapCenter", myMap.Center);
        ViewState.Add("mapZoom", myMap.Zoom);
        //Render map

        System.Drawing.Image img;
        try
        {
            img = myMap.GetMap();
        }
        catch (SqlException ex)
        {
            throw new Exception(
                      "An error related to Sql occured. Ensure you have configured the database server correctly and updated the web.config file. See the readme in the MsSqlSpatialDemoDb folder.",
                      ex);
        }
        string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);

        imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);
    }
        public void ProcessRequest(HttpContext context)
        {
            // tile keys
            int x, y, z;

            //Parse request parameters
            if (!int.TryParse(context.Request.Params["x"], out x))
                throw (new ArgumentException("Invalid parameter"));
            if (!int.TryParse(context.Request.Params["y"], out y))
                throw (new ArgumentException("Invalid parameter"));
            if (!int.TryParse(context.Request.Params["z"], out z))
                throw (new ArgumentException("Invalid parameter"));
            string layer = context.Request.Params["layer"]; // not used here
            string style = context.Request.Params["style"]; // not used here

            // set response type to png
            context.Response.ContentType = "image/png";

            // check if already rendered, rendered tiles are cached within HttpContext
            string cacheKey = string.Format("Tile/{0}/{1}/{2}/{3}/{4}", layer, style, x, y, z);
            byte[] buffer = context.Cache[cacheKey] as byte[];
            if (buffer != null)
            {
                context.Response.OutputStream.Write(buffer, 0, buffer.Length);
                return;
            }

            // create a transparent sharpmap map with a size of 256x256
            using (var sharpMap = new Map(new Size(256, 256)) { BackColor = Color.Transparent })
            {
                // the map contains only one layer
                var countries = new VectorLayer("WorldCountries")
                {
                    // set tranform to WGS84->Spherical_Mercator
                    CoordinateTransformation = TransformToMercator(GeographicCoordinateSystem.WGS84),

                    // set the sharpmap provider for shape files as data source
                    DataSource = new ShapeFile(
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data") +
                        @"\world_countries_boundary_file_world_2002.shp"),

                    // use a dynamic style for thematic mapping
                    // the lambda also takes the map instance into account (to scale the border width)
                    Theme = new CustomTheme(row => GetPopDensStyle(sharpMap, row)),
                };

                // add the layer to the map
                sharpMap.Layers.Add(countries);

                // calculate the bbox for the tile key and zoom the map
                sharpMap.ZoomToBox(TileToMercatorAtZoom(x, y, z));

                // render the map image
                using (var img = sharpMap.GetMap())
                {
                    // stream the image to the client
                    using (var memoryStream = new MemoryStream())
                    {
                        // Saving a PNG image requires a seekable stream, first save to memory stream
                        // http://forums.asp.net/p/975883/3646110.aspx#1291641
                        img.Save(memoryStream, ImageFormat.Png);
                        buffer = memoryStream.ToArray();

                        // write response
                        context.Response.OutputStream.Write(buffer, 0, buffer.Length);

                        // add to cache
                        context.Cache[cacheKey] = buffer;
                    }
                }
            }
        }
示例#18
0
 public void GetMap_RenderLayerWithoutDatasource_ThrowException()
 {
     Map map = new Map();
     map.Layers.Add(new VectorLayer("Layer 1"));
     map.GetMap();
 }
示例#19
0
 public void GetMap_RenderEmptyMap_ThrowInvalidOperationException()
 {
     Map map = new Map(new Size(2, 1));
     map.GetMap();
 }
示例#20
0
        public void GetMap_GeometryProvider_ReturnImage()
        {
            Map map = new Map(new Size(400, 200));
            VectorLayer vLayer = new VectorLayer("Geom layer", CreateDatasource());
            vLayer.Style.Outline = new Pen(Color.Red, 2f);
            vLayer.Style.EnableOutline = true;
            vLayer.Style.Line = new Pen(Color.Green, 2f);
            vLayer.Style.Fill = Brushes.Yellow;
            map.Layers.Add(vLayer);

            VectorLayer vLayer2 = new VectorLayer("Geom layer 2", vLayer.DataSource);
            vLayer2.Style.SymbolOffset = new PointF(3, 4);
            vLayer2.Style.SymbolRotation = 45;
            vLayer2.Style.SymbolScale = 0.4f;
            map.Layers.Add(vLayer2);

            VectorLayer vLayer3 = new VectorLayer("Geom layer 3", vLayer.DataSource);
            vLayer3.Style.SymbolOffset = new PointF(3, 4);
            vLayer3.Style.SymbolRotation = 45;
            map.Layers.Add(vLayer3);

            VectorLayer vLayer4 = new VectorLayer("Geom layer 4", vLayer.DataSource);
            vLayer4.Style.SymbolOffset = new PointF(3, 4);
            vLayer4.Style.SymbolScale = 0.4f;
            vLayer4.ClippingEnabled = true;
            map.Layers.Add(vLayer4);

            map.ZoomToExtents();

            Image img = map.GetMap();
            Assert.IsNotNull(img);
            map.Dispose();
            img.Dispose();
        }
示例#21
0
        public override Texture LoadFile(QuadTile qt)
        {
            //获取切片的本地路径
            string filePath = GetLocalPath(qt);

            qt.ImageFilePath = filePath;

            Texture texture = null;
            string  ddsPath = filePath;

            //判断是否是DDS文件
            if (World.Settings.ConvertDownloadedImagesToDds)
            {
                ddsPath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".dds";
            }

            filePath = ddsPath;
            //判断磁盘上,是否有当前文件,若有,则直接读取,若没有,则重新加载
            if (!File.Exists(filePath))
            {
                //动态读取Tiff影像中的值
                SharpMap.Map map = new SharpMap.Map();
                for (int i = 0; i < Layers.Length; i++)
                {
                    SharpMap.Layers.VectorLayer shapeLayer = new SharpMap.Layers.VectorLayer(Path.GetFileNameWithoutExtension(Layers[i]));
                    shapeLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(Layers[i], true);
                    //设置Polygon的填充色,默认为透明
                    shapeLayer.Style.Fill = new SolidBrush(fillColor);
                    //设置Polygon的边框色
                    shapeLayer.Style.Outline       = outlineColor;
                    shapeLayer.Style.EnableOutline = true;
                    shapeLayer.Style.Line          = lineColor;
                    shapeLayer.SRID    = 4326;
                    shapeLayer.Enabled = true;
                    map.Layers.Add(shapeLayer);
                }
                //设置Map的背景色为透明色
                map.BackColor = System.Drawing.Color.Transparent;
                //图像的formate
                System.Drawing.Imaging.ImageCodecInfo imageEncoder = GetEncoderInfo(formate);
                //图片的大小
                map.Size = new System.Drawing.Size(m_textureSizePixels, m_textureSizePixels);
                //请求图像的范围
                string bboxString = "";
                bboxString = qt.West.ToString() + "," + qt.South.ToString() + "," + qt.East.ToString() + "," + qt.North.ToString();
                SharpMap.Geometries.BoundingBox bbox = this.ParseBBOX(bboxString);
                //判断图像的拉伸范围
                map.PixelAspectRatio = ((double)m_textureSizePixels / (double)m_textureSizePixels) / (bbox.Width / bbox.Height);
                map.Center           = bbox.GetCentroid();
                map.Zoom             = bbox.Width;
                //获得当前请求的图片
                System.Drawing.Image img = map.GetMap();
                if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                }
                //保存到本地磁盘
                img.Save(filePath);
            }
            //设置是否显示图片的无效值
            if (qt.QuadTileSet.HasTransparentRange)
            {
                texture = ImageHelper.LoadTexture(filePath, qt.QuadTileSet.ColorKey,
                                                  qt.QuadTileSet.ColorKeyMax);
            }
            else
            {
                texture = ImageHelper.LoadTexture(filePath, qt.QuadTileSet.ColorKey);
            }

            //判断,是否转化为dds文件
            if (World.Settings.ConvertDownloadedImagesToDds)
            {
                ConvertImage(texture, filePath);
            }
            //返回当前纹理
            return(texture);
        }
示例#22
0
 public Image GetMapImage()
 {
     return(_Map.GetMap());
 }
示例#23
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int    Width   = 0;
        int    Height  = 0;
        double centerX = 0;
        double centerY = 0;
        double Zoom    = 0;

        string[] Layer;

        //Parse request parameters
        if (!int.TryParse(Request.Params["WIDTH"], out Width))
        {
            throw(new ArgumentException("Invalid parameter"));
        }
        if (!int.TryParse(Request.Params["HEIGHT"], out Height))
        {
            throw (new ArgumentException("Invalid parameter"));
        }
        if (!double.TryParse(Request.Params["ZOOM"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out Zoom))
        {
            throw (new ArgumentException("Invalid parameter"));
        }
        if (!double.TryParse(Request.Params["X"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out centerX))
        {
            throw (new ArgumentException("Invalid parameter"));
        }
        if (!double.TryParse(Request.Params["Y"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out centerY))
        {
            throw (new ArgumentException("Invalid parameter"));
        }
        if (Request.Params["MAP"] == null)
        {
            throw (new ArgumentException("Invalid parameter"));
        }
        if (!string.IsNullOrEmpty(Request.Params["Layers"]))
        {
            Layer = Request.Params["Layers"].Split(new char[] { ',' });
        }
        else
        {
            throw (new ArgumentException("Invalid parameter"));
        }

        string colors     = Request.Params["Colors"];
        string colorsLine = Request.Params["ColorsLine"];

        //Params OK
        SharpMap.Map map = InitializeMap(Request.Params["MAP"], new System.Drawing.Size(Width, Height), colors, colorsLine);
        if (map == null)
        {
            throw (new ArgumentException("Invalid map"));
        }

        //toggle layers
        if (Layer[0] != "none")
        {
            for (int i = 0; i < Layer.Length; i++)
            {
                toggleLayer(Layer[i], map).Enabled = false;
            }
        }


        //Set visible map extents
        map.Center = new GeoAPI.Geometries.Coordinate(centerX, centerY);
        map.Zoom   = Zoom;



        //Generate map
        System.Drawing.Bitmap img = (System.Drawing.Bitmap)map.GetMap();

        //Stream the image to the client
        Response.ContentType = "image/png";
        System.IO.MemoryStream MS = new System.IO.MemoryStream();
        img.Save(MS, System.Drawing.Imaging.ImageFormat.Png);

        // tidy up
        img.Dispose();
        byte[] buffer = MS.ToArray();
        Response.OutputStream.Write(buffer, 0, buffer.Length);
    }
示例#24
0
        public void TestWarpedLineSymbolizer()
        {
            ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false);

            VectorLayer l = new VectorLayer("roads", p);

            CachedLineSymbolizer cls = new CachedLineSymbolizer();
            cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Gold, 2) });

            WarpedLineSymbolizeHander wls = new WarpedLineSymbolizeHander
                          {
                              Pattern =
                                  WarpedLineSymbolizer.
                                  GetGreaterSeries(3, 3),
                              Line = new Pen(Color.Firebrick, 1)
                              ,
                              Interval = 20
                          };
            cls.LineSymbolizeHandlers.Add(wls);
            l.Style.LineSymbolizer = cls;

            Map m = new Map(new Size(720, 540)) { BackColor = Color.Cornsilk };
            m.Layers.Add(l);

            m.ZoomToExtents();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Image bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads1.bmp");

            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
                                               {
                                                   Pattern =
                                                       WarpedLineSymbolizer.
                                                       GetTriangle(4, 0),
                                                   Line = new Pen(Color.Firebrick, 1),
                                                   Fill = new SolidBrush(Color.Firebrick)
                                                   ,
                                                   Interval = 10
                                               };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-0.bmp");

            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
            {
                Pattern =
                    WarpedLineSymbolizer.
                    GetTriangle(4, 1),
                Line = new Pen(Color.Firebrick, 1),
                Fill = new SolidBrush(Color.Firebrick)
                ,
                Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-1.bmp");
            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
            {
                Pattern =
                    WarpedLineSymbolizer.
                    GetTriangle(4, 2),
                Line = new Pen(Color.Firebrick, 1),
                Fill = new SolidBrush(Color.Firebrick)
                ,
                Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-2.bmp");

            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
            {
                Pattern =
                    WarpedLineSymbolizer.
                    GetTriangle(4, 3),
                Line = new Pen(Color.Firebrick, 1),
                Fill = new SolidBrush(Color.Firebrick)
                ,
                Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-3.bmp");


            //cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1];
            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
                                               {
                                                   Pattern =
                                                       WarpedLineSymbolizer.GetZigZag(4, 4),
                                                   Line = new Pen(Color.Firebrick, 1),
                                                   //Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
                                               };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads3.bmp");
        }
示例#25
0
        public void TestCachedLineSymbolizerInTheme()
        {
            ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false);

            VectorLayer l = new VectorLayer("roads", p);
            ClsTheme theme = new ClsTheme(l.Style);
            l.Theme = theme;

            Map m = new Map(new Size(720, 540)) { BackColor = Color.Cornsilk };
            m.Layers.Add(l);

            m.ZoomToExtents();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Image bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads1Theme.bmp");
        }