ThinkGeo.com    |     Documentation    |     Premium Support

Changing map brightness during night shift

Is it possible to change brightness or used colors when OpenStreetMap layer is used? It is required by car drivers and night shift staff.

Hi Piotr,

The code as below shows how to replace a color to black just like the screen shot shows:

 private void DisplayMap_Load(object sender, EventArgs e)
    {
        winformsMap1.MapUnit = GeographyUnit.Meter;
        winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

        OpenStreetMapLayer layer = new OpenStreetMapLayer();

        // This code change the color
        layer.ColorMappings.Clear();
        layer.ColorMappings.Add(GeoColor.FromArgb(255, 242, 239, 233), GeoColors.Black);
        // Code end


        LayerOverlay worldMapKitDesktopOverlay = new LayerOverlay();
        worldMapKitDesktopOverlay.Layers.Add(layer);
        winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);

        winformsMap1.CurrentExtent = new RectangleShape(-2000000, 2000000, 2000000, -2000000);

        winformsMap1.Refresh();
    }

Regards,

Don

Thank you, unfortunately when I put your code into my project base on Desktop Edition the ColorMappings collection printed in red and compilation gives error.

Hi Piotr,

Please download our latest development edition 9.0.x.0.

Regards,

Don

The collection is now visible - thank you.
I’ve try to make it by procedure like follow:

 private void SetDark()
    {
        if (MyDark)
        {               
            OsmLayer.ColorMappings.Clear();
            OsmLayer.ColorMappings.Add(GeoColor.FromArgb(255, 242, 239, 233), GeoColors.Black);        
        }
        else
        {
            OsmLayer.ColorMappings.Clear();
            OsmLayer.ColorMappings = StandardColorMappings;
        }
    }

The StandardColorMappings was taken from initialization part:

 OsmLayer = new OpenStreetMapLayer
        {
            TileCache =
                new FileBitmapTileCache(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                                        Path.DirectorySeparatorChar + "DgtTileCache" + Path.DirectorySeparatorChar,
                    "OSM")
                {
                    TileAccessMode = TileAccessMode.ReadOnly,
                    ImageFormat = TileImageFormat.Png
                },
            WebProxy = (WebProxy) init.WebProxy
        };
        OsmLayer.WebProxy.Credentials = init.Credential;
        // This code change the color
        StandardColorMappings=OsmLayer.ColorMappings;
        OsmOverlay = new LayerOverlay();
        OsmOverlay.Layers.Add(OsmLayer);

Problem is that there is no setter for OsmLayer.ColorMappings - how to came back to default colors?

Hi Piotr,

I think layer.ColorMappings.Clear(); is what you need.

Regards,

Don

Hi Don - in practice with OSM as a background map it not working for me. Please have a look on this picture:

Two pictures on the top comes form WPF Map Suite. At the bottom the original currently used mode for map used at a dark room.

Regards
Piotr

Hi Piotr,

Usually, if a property is Collection or Dictionary type, we just public it as “Get”, but keep “Set” as private. Compared with “Set” directly, it’s easy to control by the class, to restore the style, you just need to clear the dictionnary and restore the preserved back one by one. Hope it helps.

BTW, seems like it’s failed to show the picture, would you please help confirm or re-upload it?

Thanks,
Johnny

I’ve enclosed picture again. I notice that ColorMapping is accessible only in OSM but not visible in general (TileServer).

Hi Piotr,

Thanks for your screen shots, I can view that now.

So is your question that you can make OSM as background works in DesktopEditon but cannot make that works in WPFEdition? Because I remembered you said it works for you last time.

And in fact the ColorMapping is works for all the layers(sub classes which inherit fromlayer class), it’s not only work for OSM layer. Have you met the other type layer which don’t works for it?

Regards,

Don