Re: [Gvsig_english] Issue with layer position when creating new layers

2010-05-05 Thread Flavio Pompermaier
Sorry but I have to correct my previous email:

when I add the layer I try to put it on the bottom of the TOC:
flayers.addLayer(0,createLayerInView(workLayer, projection));

2010/5/5 Flavio Pompermaier fla8...@gmail.com:
 Hi to all,
 I'm using gvSIG 1.9 revision 1253 and I have some trouble whit layer
 positioning.
 I have a list of layer to add on login and, if this layer is not
 present, I want to add it on the bottom of the toc and not on top as
 default.
 However, if I use Flayers.addLayer(0, layer) it is not added at the
 bottom of the toc..
 This is the code I use in my project (a simplified version):

       // 1 store layer position before addition
       for (MyLayer workLayer : workLayers) {
                String layerName = workLayer.getLayerNameI();
                int position = getLayerPostion(flayers, layerName);
                if (position = 0) {
                        layerPositions.put(layerName, position);
                }
        }

        //2 remove layer to add if present and then add
        for (MyLayer workLayer : workLayers) {
                String layerName = workLayer.getLayerNameI();
                /remove layer if it already exists
                FLayer alreadyExistingLayer = flayers.getLayer(layerName);
                if (alreadyExistingLayer != null) {
                        flayers.removeLayer(alreadyExistingLayer);
                }
                //and substitute with the new generated one
                flayers.addLayer(createLayerInView(workLayer, projection));
                log.debug(Layer substituted:  + 
 workLayer.getServiceLayerName());
        }

        // 3 reorder as before removing/adding (point 2)
        int numLayers = flayers.getLayersCount() - 1;
        for (MyLayer workLayer : workLayers) {
                String layerName = workLayer.getLayerNameI();
                Integer oldPosition = layerPositions.get(layerName);
                int currentPosition = getLayerPostion(flayers, layerName);
                if (oldPosition != null) {
                        flayers.moveTo(numLayers - currentPosition, numLayers -
                        oldPosition.intValue());
                }
        }


 and the function getLayerPostion():

       private static int getLayerPostion(FLayers flayers, String layerName) {
                for (int i = 0; i  flayers.getLayersCount(); i++) {
                        if (layerName.equals(flayers.getLayer(i).getName()))
                                return i;
                }
                return -1;
        }


 Any help?

___
Gvsig_internacional mailing list
Gvsig_internacional@listserv.gva.es
http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional


Re: [Gvsig_english] Issue with layer position when creating new layers

2010-05-05 Thread Antonio Falciano
Il 05/05/2010 11.46, Flavio Pompermaier ha scritto:
 Hi to all,
 I'm using gvSIG 1.9 revision 1253 and I have some trouble whit layer
 positioning.
 I have a list of layer to add on login and, if this layer is not
 present, I want to add it on the bottom of the toc and not on top as
 default.
 However, if I use Flayers.addLayer(0, layer) it is not added at the
 bottom of the toc..

Hi Flavio,
what are your gvSIG settings about layer ordering? Maybe you should
override this setting, using the DefaultOrderManager.

ciao
Antonio

-- 
Antonio Falciano
http://www.linkedin.com/in/antoniofalciano
___
Gvsig_internacional mailing list
Gvsig_internacional@listserv.gva.es
http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional


Re: [Gvsig_english] Issue with layer position when creating new layers

2010-05-05 Thread Flavio Pompermaier
Thanks Antonio for your reply.
Unfortunately I don't understand your suggestion..Should I create my
own OrderManager just to put new layers on the bottom of the TOC??
The strange thing is the possibility to call Flayers.addLayer(0,
layer) and ignoring the passed position paramenter...isn't it?

2010/5/5 Antonio Falciano afalci...@yahoo.it:
 Il 05/05/2010 11.46, Flavio Pompermaier ha scritto:
 Hi to all,
 I'm using gvSIG 1.9 revision 1253 and I have some trouble whit layer
 positioning.
 I have a list of layer to add on login and, if this layer is not
 present, I want to add it on the bottom of the toc and not on top as
 default.
 However, if I use Flayers.addLayer(0, layer) it is not added at the
 bottom of the toc..

 Hi Flavio,
 what are your gvSIG settings about layer ordering? Maybe you should
 override this setting, using the DefaultOrderManager.

 ciao
 Antonio

 --
 Antonio Falciano
 http://www.linkedin.com/in/antoniofalciano
 ___
 Gvsig_internacional mailing list
 Gvsig_internacional@listserv.gva.es
 http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional

___
Gvsig_internacional mailing list
Gvsig_internacional@listserv.gva.es
http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional


Re: [Gvsig_english] Issue with layer position when creating new layers

2010-05-05 Thread Antonio Falciano
Il 05/05/2010 13.31, Flavio Pompermaier ha scritto:
 Thanks Antonio for your reply. Unfortunately I don't understand your
 suggestion..Should I create my own OrderManager just to put new
 layers on the bottom of the TOC??

No, I was referring to the two different managers of layer ordering:
DefaultOrderManager and SmartOrderManager. Maybe, DefaultOrderManager is
not active in your case... so, if you take a look at
org.gvsig.layerLoadingOrder package, you will find something of your
interest.

Cheers,
Antonio

-- 
Antonio Falciano
http://www.linkedin.com/in/antoniofalciano
___
Gvsig_internacional mailing list
Gvsig_internacional@listserv.gva.es
http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional


Re: [Gvsig_english] Issue with layer position when creating new layers

2010-05-05 Thread Flavio Pompermaier
I have neither SmartOrderManager nor org.gvsig.layerLoadingOrder
package in my gvSIG version ...:(

2010/5/5 Antonio Falciano afalci...@yahoo.it:
 Il 05/05/2010 13.31, Flavio Pompermaier ha scritto:
 Thanks Antonio for your reply. Unfortunately I don't understand your
 suggestion..Should I create my own OrderManager just to put new
 layers on the bottom of the TOC??

 No, I was referring to the two different managers of layer ordering:
 DefaultOrderManager and SmartOrderManager. Maybe, DefaultOrderManager is
 not active in your case... so, if you take a look at
 org.gvsig.layerLoadingOrder package, you will find something of your
 interest.

 Cheers,
 Antonio

 --
 Antonio Falciano
 http://www.linkedin.com/in/antoniofalciano
 ___
 Gvsig_internacional mailing list
 Gvsig_internacional@listserv.gva.es
 http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional

___
Gvsig_internacional mailing list
Gvsig_internacional@listserv.gva.es
http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional


Re: [Gvsig_english] Issue with layer position when creating new layers

2010-05-05 Thread Antonio Falciano
Il 05/05/2010 15.12, Flavio Pompermaier ha scritto:
 I have neither SmartOrderManager nor org.gvsig.layerLoadingOrder
 package in my gvSIG version ...:(

Flavio, checkout this:
http://forge.osor.eu/plugins/scmsvn/viewcvs.php/trunk/extensions/extLayerLoadingOrder/?root=gvsig-desktop

ciao

 2010/5/5 Antonio Falcianoafalci...@yahoo.it:
 Il 05/05/2010 13.31, Flavio Pompermaier ha scritto:
 Thanks Antonio for your reply. Unfortunately I don't understand your
 suggestion..Should I create my own OrderManager just to put new
 layers on the bottom of the TOC??

 No, I was referring to the two different managers of layer ordering:
 DefaultOrderManager and SmartOrderManager. Maybe, DefaultOrderManager is
 not active in your case... so, if you take a look at
 org.gvsig.layerLoadingOrder package, you will find something of your
 interest.

 Cheers,
 Antonio

 --
 Antonio Falciano
 http://www.linkedin.com/in/antoniofalciano
 ___
 Gvsig_internacional mailing list
 Gvsig_internacional@listserv.gva.es
 http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional

 ___
 Gvsig_internacional mailing list
 Gvsig_internacional@listserv.gva.es
 http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional


-- 
Antonio Falciano
http://www.linkedin.com/in/antoniofalciano
___
Gvsig_internacional mailing list
Gvsig_internacional@listserv.gva.es
http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional


Re: [Gvsig_english] Issue with layer position when creating new layers

2010-05-05 Thread Francisco José Peñarrubia
Hi Flavio.

I didn't test your code, but maybe you are missing 
mapContext.beginAtomicEvent() and mapContext.endAtomicEvent().

I have something like this, and it works:

mc.getMapContext().beginAtomicEvent();
final FLayers mcLayers = mc.getMapContext().getLayers();
FLayers newGroup = 
mc.getMapContext().getNewGroupLayer(mcLayers);
newGroup.setProjection(mc.getProjection());
newGroup.setName(nom);

for (int i=0; i  shpLayers.size(); i++) {
ShpLegend aux = shpLayers.get(i);
FLyrVect lyr = (FLyrVect) LayerFactory.createLayer(nom + 
aux.shpName, gvSIG shp driver,
new File(dirShps.getPath() + 
File.separator + nom+
aux.shpName + .shp), 
mc.getProjection());
   
newGroup.addLayer(lyr);
loadLegend(lyr, aux.gvlName);
}
mcLayers.addLayer(newGroup);
mcLayers.moveTo(0, mcLayers.getLayersCount()-1);
mc.getMapContext().endAtomicEvent();

Hope it helps.

Best regards.

Fran Peñarrubia
www.scolab.es


Flavio Pompermaier escribió:
 Hi to all,
 I'm using gvSIG 1.9 revision 1253 and I have some trouble whit layer
 positioning.
 I have a list of layer to add on login and, if this layer is not
 present, I want to add it on the bottom of the toc and not on top as
 default.
 However, if I use Flayers.addLayer(0, layer) it is not added at the
 bottom of the toc..
 This is the code I use in my project (a simplified version):

// 1 store layer position before addition
for (MyLayer workLayer : workLayers) {
   String layerName = workLayer.getLayerNameI();
   int position = getLayerPostion(flayers, layerName);
   if (position = 0) {
   layerPositions.put(layerName, position);
   }
   }

 //2 remove layer to add if present and then add
   for (MyLayer workLayer : workLayers) {
   String layerName = workLayer.getLayerNameI();
   /remove layer if it already exists
   FLayer alreadyExistingLayer = flayers.getLayer(layerName);
   if (alreadyExistingLayer != null) {
   flayers.removeLayer(alreadyExistingLayer);
   }
   //and substitute with the new generated one
   flayers.addLayer(createLayerInView(workLayer, projection));
   log.debug(Layer substituted:  + 
 workLayer.getServiceLayerName());
   }

 // 3 reorder as before removing/adding (point 2)
 int numLayers = flayers.getLayersCount() - 1;
   for (MyLayer workLayer : workLayers) {
   String layerName = workLayer.getLayerNameI();
   Integer oldPosition = layerPositions.get(layerName);
   int currentPosition = getLayerPostion(flayers, layerName);
   if (oldPosition != null) {
   flayers.moveTo(numLayers - currentPosition, numLayers -
 oldPosition.intValue());
   }
   }


 and the function getLayerPostion():

private static int getLayerPostion(FLayers flayers, String layerName) {
   for (int i = 0; i  flayers.getLayersCount(); i++) {
   if (layerName.equals(flayers.getLayer(i).getName()))
   return i;
   }
   return -1;
   }


 Any help?
 ___
 Gvsig_internacional mailing list
 Gvsig_internacional@listserv.gva.es
 http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional
   

___
Gvsig_internacional mailing list
Gvsig_internacional@listserv.gva.es
http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional


Re: [Gvsig_english] Issue with layer position when creating new layers

2010-05-05 Thread Flavio Pompermaier
I tied to use your advice About mapContext.beginAtomicEvent() and
mapContext.endAtomicEvent() but it didn't help :(
By the way, thanks for the advice!

2010/5/5 Francisco José Peñarrubia fpena...@gmail.com:
 Hi Flavio.

 I didn't test your code, but maybe you are missing
 mapContext.beginAtomicEvent() and mapContext.endAtomicEvent().

 I have something like this, and it works:

            mc.getMapContext().beginAtomicEvent();
            final FLayers mcLayers = mc.getMapContext().getLayers();
            FLayers newGroup =
 mc.getMapContext().getNewGroupLayer(mcLayers);
            newGroup.setProjection(mc.getProjection());
            newGroup.setName(nom);

            for (int i=0; i  shpLayers.size(); i++) {
                ShpLegend aux = shpLayers.get(i);
                FLyrVect lyr = (FLyrVect) LayerFactory.createLayer(nom +
 aux.shpName, gvSIG shp driver,
                                new File(dirShps.getPath() +
 File.separator + nom+
                                        aux.shpName + .shp),
 mc.getProjection());

                newGroup.addLayer(lyr);
                loadLegend(lyr, aux.gvlName);
            }
            mcLayers.addLayer(newGroup);
            mcLayers.moveTo(0, mcLayers.getLayersCount()-1);
            mc.getMapContext().endAtomicEvent();

 Hope it helps.

 Best regards.

 Fran Peñarrubia
 www.scolab.es


 Flavio Pompermaier escribió:
 Hi to all,
 I'm using gvSIG 1.9 revision 1253 and I have some trouble whit layer
 positioning.
 I have a list of layer to add on login and, if this layer is not
 present, I want to add it on the bottom of the toc and not on top as
 default.
 However, if I use Flayers.addLayer(0, layer) it is not added at the
 bottom of the toc..
 This is the code I use in my project (a simplified version):

        // 1 store layer position before addition
        for (MyLayer workLayer : workLayers) {
               String layerName = workLayer.getLayerNameI();
               int position = getLayerPostion(flayers, layerName);
               if (position = 0) {
                       layerPositions.put(layerName, position);
               }
       }

         //2 remove layer to add if present and then add
       for (MyLayer workLayer : workLayers) {
               String layerName = workLayer.getLayerNameI();
               /remove layer if it already exists
               FLayer alreadyExistingLayer = flayers.getLayer(layerName);
               if (alreadyExistingLayer != null) {
                       flayers.removeLayer(alreadyExistingLayer);
               }
               //and substitute with the new generated one
               flayers.addLayer(createLayerInView(workLayer, projection));
               log.debug(Layer substituted:  + 
 workLayer.getServiceLayerName());
       }

         // 3 reorder as before removing/adding (point 2)
         int numLayers = flayers.getLayersCount() - 1;
       for (MyLayer workLayer : workLayers) {
               String layerName = workLayer.getLayerNameI();
               Integer oldPosition = layerPositions.get(layerName);
               int currentPosition = getLayerPostion(flayers, layerName);
               if (oldPosition != null) {
                       flayers.moveTo(numLayers - currentPosition, numLayers -
                         oldPosition.intValue());
               }
       }


 and the function getLayerPostion():

        private static int getLayerPostion(FLayers flayers, String layerName) 
 {
               for (int i = 0; i  flayers.getLayersCount(); i++) {
                       if (layerName.equals(flayers.getLayer(i).getName()))
                               return i;
               }
               return -1;
       }


 Any help?
 ___
 Gvsig_internacional mailing list
 Gvsig_internacional@listserv.gva.es
 http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional


 ___
 Gvsig_internacional mailing list
 Gvsig_internacional@listserv.gva.es
 http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional

___
Gvsig_internacional mailing list
Gvsig_internacional@listserv.gva.es
http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional