Using an image as background of sharpmap

Mar 23, 2011 at 2:58 AM
Edited Mar 23, 2011 at 2:59 AM

Hi guys,

I just wonder how can I use an image (extension jpg, png....) to display on a map as a background ? I tried to use an image in ImageButton but it didn't display.

Can you give me some advice or I have to do another way ?

Thanks and best regards.

Coordinator
Mar 23, 2011 at 9:06 AM

You can use:

  • GdalRasterLayer for file based raster/image data. You need to reference the image though
  • WMSLayer for background image from a WMS server
  • TileLayer for a background image from a tile service like openstreetmap or bing maps.

See the WinFormSamples project for examples for their usage.

Hth FObermaier

Mar 28, 2011 at 10:54 AM
Edited Mar 28, 2011 at 10:55 AM

Hi FObermaier, I tried to use this code in MapHelper.cs:

 

public static Map InitializeMapGdal(Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        //Initialize a new map of size 'imagesize'
        Map map = new Map(size);

        //Set up the gdal layer
        LayerGroup g = new LayerGroup("OS");
        g.SRID = 27700;
        //D:\Raster\Ordnance Survey\OS Street View SM\data\sm
        System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath(@"~\App_Data\Gdal"));
        foreach (System.IO.FileInfo fi in di.GetFiles("*.tif"))
        {
            try
            {
                SharpMap.Layers.GdalRasterLayer layer = 
                    new SharpMap.Layers.GdalRasterLayer(
                        fi.Name, HttpContext.Current.Server.MapPath(@"~\App_Data\Gdal\" + fi.Name));
                //layer.SRID = 27700;
                g.Layers.Add(layer);
            }
            catch (TypeInitializationException ex)
            {
                if (ex.GetType() == typeof(TypeInitializationException))
                    throw new Exception(
                        "Please copy the umanaged dll's into your bin folder from javascript:window.location.href='http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions';.");
            }
        }
        map.Layers.Add(g);
        map.ZoomToExtents();

        HttpContext.Current.Trace.Write("Map initialized");
        return map;
    }

but It still displayed error, even though I had gdal_csharp.dll in my web bin folder:

Please copy the umanaged dll's into your bin folder from javascript:window.location.href='http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions';. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Exception: Please copy the umanaged dll's into your bin folder from javascript:window.location.href='http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions';.

Source Error: 


Line 548:            {
Line 549:                if (ex.GetType() == typeof(TypeInitializationException))
Line 550:                    throw new Exception(
Line 551:                        "Please copy the umanaged dll's into your bin folder from javascript:window.location.href='http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions';.");
Line 552:            }
 

Source File: ....\Trunk\DemoWebSite\App_Code\MapHelper.cs    Line: 550 


I also went to

 

http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions 

to copy FwTools 1.2.0 and install it, but it didn't take any effect.

How can I do ? Which dll I have to copy in this link?

Thanks.
Coordinator
Mar 28, 2011 at 11:13 AM

hello namserious,

Hth FObermaier

Mar 28, 2011 at 1:36 PM

It worked, thanks FObermaier.

Mar 30, 2011 at 4:03 AM

Hi FObermaier,

I have one more question.

How can I use these dlls directly not via Webconfig ? Because when I added them into Bin folder of DemoWebsite, my image did not  appear.

Thanks.