[Gvsig_english] Issue with layer position when creating new layers

Flavio Pompermaier fla83tn at gmail.com
Wed May 5 11:50:13 CEST 2010


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 <fla83tn at 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?
>


More information about the Gvsig_internacional mailing list