This project is read-only.

How to change the layer position?

Dec 9, 2010 at 3:45 AM

I have added several layers to the Map. For example:

this.map1.layers.add(pointlayer); 1

this.map1.layers.add(linelayer);  2

this.map1.layers.add(polygonlayer);  3

Now I want to move the pointlayer to the location of 3.

I am a chinese,so You may not understand me.

In the mapwindow4,there is a method :mapwin.MoveLayer(pos1, pos2);

In the DotSpatial,how to  implement this method??



Dec 9, 2010 at 1:09 PM
Hi, You could do something like this:
        /// <summary>
        /// Moves the layer at nIndexFrom to the index position given as nIndexTo inside the Layer Collection
        /// </summary>
        /// <param name="self">The Layer Collection to use</param>
        /// <param name="nIndexFrom">Index of the item to move</param>
        /// <param name="nIntexTo">Index to move the item to</param>
        /// <returns>void</returns>
        public static void MoveTo(this IMapLayerCollection self, int nIndexFrom, int nIntexTo)
            IGroup grp = self.MapFrame as IGroup;
            ILayer lyr = self[nIndexFrom];
            grp.Insert(nIntexTo, lyr);

Dec 10, 2010 at 2:10 AM

Thanks !

But it doesn't work.

It shoule be added the follow lines:


grp.Insert(nIntexTo, lyr);