Layers and Background Layers

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Jan 13, 2012 at 2:42 PM

Hi,

I have a MapBox with the BackgroundLayer set to a TileLayer. When I add any other layers to the Layers collection Shapefile or VectorLayer), you can no longer see the BackgroundLayer - it is just grey. I have tried setting the fill to transparent, but it still does not work. Is there any was to fix this without having to add my layer to BackgroundLayers? Ideally I would like to keep the collections separate.

Thanks,

Jamie

Coordinator
Jan 16, 2012 at 12:45 PM

You can add TileLayer to the ordinary Layers collcetion as well.

But I don't cannot reproduce your problem on my machine. The rendering in the background layer may take some time if you have set your proxy settings to autodetect.

Hth FObermaier

Jan 16, 2012 at 2:45 PM

Hi, 

Thanks for the reply.  If I add all layers to the background collection it works OK. Also, if I add all the layers to the Layers collection it works OK. I just wanted to keep the map layer and the other layers separate as the other layers will be updated regularly, so I can clear those layers and redraw them when needed. At present, I am just removing all layers other than the first layer in the list. Its not a big deal, I just wondered why if you add layers to the Layers Collection, you can no longer see the layers in the background collection.

Thanks,

Jamie

Coordinator
Jan 16, 2012 at 3:51 PM

You are using MapBox control?

Jan 16, 2012 at 5:09 PM

Yes, I was previously using a MapImage but have now changed to MapBox.

Coordinator
Jan 17, 2012 at 6:48 AM

The issue you are having is not related to the brutile proxy issue? Please check that you have disabled automatic detection of proxy settings.

Hth FObermaier

Jan 17, 2012 at 11:10 AM

I am using the latest version of BruTile, so I don't think the problem is the proxy issue. I have no problems displaying the tiles all in the same collection. It is only when the tiles are in the BackgroundLayer collection and Shapefiles are in a VectorLayer in the Layers collection.

Jamie

Coordinator
Jan 17, 2012 at 1:47 PM

You did compile it yourself? The released version and the one via NuGet still has that problem.

Jan 17, 2012 at 4:42 PM

Yes, I have compiled the source myself and am using that. I still get the problem though. I have just done an SVN update though and picked up new changes, so maybe my version was out of date. I will try and let you know.

Thanks,

Jamie

Jan 17, 2012 at 4:58 PM

Unfortunately the code update did not fix the problem. I will just continue how I am doing it at the moment with all layers in a single collection.

Thanks for your help,

Jamie

Editor
May 22, 2013 at 11:28 AM
Are there any updates on this?
Coordinator
May 22, 2013 at 6:05 PM
So, just to be clear, if you add both layers to the Layers-Colleciton, it works,
but if one of the layers are in the Layers collection and the other in the backgroundlayers collection it does not work?
Editor
May 22, 2013 at 6:49 PM
My current issue is this:

Just asynctilelayer in backgroundLayers - works fine, no missing tiles. Layer always drawing

Asynctilelyer in background layers and shapefile in layer - background layer never draws. Layer draws fine

Asynctilelayer in backgroundlayer and shapefile in variable layers - background draws ok, layer has no opacity, so is solid

Asynctilelayer in layers, shapefile in layers - background loads, but only draws some tiles, occasionally no tiles. Shapefile draws fine.

I think that is all the cases. The shapefile i used was a shp file extract from osm via geofrabrik, reprojected to 900913 in QGIS.

I can upload the shapefile if you give me instructions on where to put it

Thanks
Coordinator
May 22, 2013 at 9:25 PM
Use any of the online filesharing services like for example:
http://www.sendspace.com/
Editor
May 23, 2013 at 8:56 AM
OK, I uploaded the shapefile I'm using to here :

http://www.sendspace.com/file/8ibk9r

this is the code I'm using in the form load event;
  SharpMap.Map myMap = mapBox1.Map;


        var osmTileSource = new TileSource(new WebTileProvider(
new TmsRequest(new Uri("http://b.tile.openstreetmap.org"), "png"))//, new FileCache(@"c:\temp\BruTile", "png")
, new SphericalMercatorInvertedWorldSchema());
        mapBox1.Map.VariableLayers.Add(new SharpMap.Layers.TileAsyncLayer(
         osmTileSource, "OSM"));

        mapBox1.Map.BackColor = Color.WhiteSmoke; //Set background

        MyLayer2 = new SharpMap.Layers.VectorLayer("MyLayer2");

        MyLayer2.DataSource = new SharpMap.Data.Providers.ShapeFile("C:\\Users\\roberts\\Downloads\\surrey-latest\\landuse_google.shp", false, false, 900913);

        //Create the style for Land
        SharpMap.Styles.VectorStyle landStyle = new SharpMap.Styles.VectorStyle();
        Color c = Color.FromArgb(30, 255, 0, 0);
        Brush b = new SolidBrush(c);
        landStyle.Fill = b; // new SolidBrush(Color.FromArgb(20,15, 255, 15));


        MyLayer2.Style = landStyle;
        mapBox1.Map.VariableLayers.Add(MyLayer2);
I'm back at my desk now so can give a few more details. about the issue: This is what I'm getting.

Asynctilelayer in BackgroundLayers, Shapefile in Layers: Asynctilelayer never draws, shapefile draws with correct opacity;

Asynctilelayer in BackgroundLayers, Shapefile in VariableLayers: Asynctilelayer draws fine, shapefile has no opacity (ie is solid);

Asynctilelayer in Layers, Shapefile in Layers: Asynctilelayer draws intermittently, shapefile draws with correct opacity;

Asynctilelayer in Layers, Shapefile in VariableLayers: Asynctilelayer layer draws intermittenly, shapefile has no opacity (ie is solid);

Asynctilelayer in VariableLayers, Shapefile in VariableLayers: Asynctilelayer draws intermittently, shapefile draws with correct opacity;

When the shapefile draws with no opacity it is a little odd. the shapefile is rendered with opactity, as I can see where the polygons overlap, but it obliterates the background.

Thanks
Editor
May 23, 2013 at 9:01 AM
this was using the RC 3 verison too.
Coordinator
May 25, 2013 at 9:35 PM
Hi, I've analyzed this now.

There seems to be an issue when you set the Map backcolor, I will investigate this further.

This code works as expected, however, when you set the backcolor it does not work.
            SharpMap.Map myMap = mapBox1.Map;


            var osmTileSource = new OsmTileSource();
            var tl = new SharpMap.Layers.TileAsyncLayer(
             osmTileSource, "OSM");
            mapBox1.Map.BackgroundLayer.Add(tl);

            var MyLayer2 = new SharpMap.Layers.VectorLayer("MyLayer2");
            MyLayer2.DataSource = new SharpMap.Data.Providers.ShapeFile(@"C:\xxxxx\landuse_google.shp", false, false, 900913);

            //Create the style for Land
            SharpMap.Styles.VectorStyle landStyle = new SharpMap.Styles.VectorStyle();
            Color c = Color.FromArgb(100, 255, 0, 0);
            Brush b = new SolidBrush(c);
            landStyle.Fill = b; // new SolidBrush(Color.FromArgb(20,15, 255, 15));

            //MyLayer2.Style = landStyle;
            MyLayer2.Style.Fill = Brushes.Red;

            mapBox1.Map.Layers.Add(MyLayer2);

            mapBox1.Map.ZoomToBox(MyLayer2.Envelope);
            mapBox1.Refresh();
Coordinator
May 25, 2013 at 9:37 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.