This project is read-only.

Ordering of layers.

May 9, 2012 at 6:20 AM


I want to order all the layers in MAP alphabetically.

I have seen map.layers.orderBY.. but not getting hoe to apply it.

plz give some code demo for same.

thank you.

May 9, 2012 at 8:11 PM

I've created a tutorial for you. You can follow the article or just paste the code below into a new class.

namespace DotSpatial.Plugins
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using DotSpatial.Controls;
    using DotSpatial.Controls.Header;
    public class SortLayersPlugin : Extension
        public override void Activate()
            App.HeaderControl.Add(new SimpleActionItem("Sort Layers", ButtonClick));
        public override void Deactivate()
        public void ButtonClick(object sender, EventArgs e)
            // Get a list of layers sorted alphabetically by LegendText.
            var newLayers = App.Map.Layers.OrderByDescending(l => l.LegendText).ToList();
            // Suspending events speeds our changes up and prevents redrawing multiple times.
            // The events will be called only once, when we call ResumeEvents().
            // By default, it appears some part of the layer is disposed when it is removed from the collection.
            // If we were to use App.Map.Layers.Clear(), we would stlil need to LockDispose on each layer.
            while (App.Map.Layers.Any())
                var layer = App.Map.Layers[0];
            // As we add each layer back in, in the correct order, we UnlockDispose so that the layer can be disposed
            // at the appropriate time.
            foreach (IMapLayer newLayer in newLayers)
May 10, 2012 at 10:10 AM

thanks a lot....

It is working properly.

Thank u.

May 13, 2012 at 3:34 AM

It very useful to see the example

<embed id="lingoes_plugin_object" type="application/lingoes-npruntime-capture-word-plugin" width="0" height="0" hidden="true"></embed>