Git Product home page Git Product logo

Comments (5)

patryksosinski avatar patryksosinski commented on May 13, 2024

Temporary fix:

Instead of inserting at specified idx, always insert at 0. It does not work for first level nodes so i ended up with quite ugly solution:

if (parentNode == me.getRootNode()) {
parentNode.appendChild(layerNode);
}else{
parentNode.insertChild(0, layerNode);
}

from geoext.

patryksosinski avatar patryksosinski commented on May 13, 2024

Ignore above fix. It works only when tree is initialy rendered and won't work when a layer is inserted at specified position later.

from geoext.

bentrm avatar bentrm commented on May 13, 2024

Thanks for your effort on this. Your description makes for some pretty good test cases that we should add as specs to related components. This will make it easier to fix this problem once and for all. I may have some time on the weekend to look into this. It would be even better if you could provide a PR. Even only some test cases would come a long way really. Anyway, thanks for your participation.

from geoext.

patryksosinski avatar patryksosinski commented on May 13, 2024

Hi bentrm,

I can provide PR and test cases but only after the weekend. If you have time now and don't want to wait i can give some hints of what i have learned.

I ended with solution that seems to work for me but i am not sure if it covers all the cases (i did some tests only for inverseLayerOrder). So here is what i did:

In LayersTree constructor i removed the inverseordering from Ext.each. That is why my previous code was not working for top level nodes.

Ext.each(collection.getArray(), function(layer) {
            me.addLayerNode(layer);
}, me);

Now i separated the initial tree creation and the tree modification caused by adding layers to map later by adding another parameter to addLayerNode:

addLayerNode:function(layerOrGroup, isInsert)

After introducing second parameter it is good idea to rewrite all the each function using addLayerNode like:
layerOrGroup.getLayers().forEach(me.addLayerNode, me);
as they pass idx as second parameter (it doesn't matter if we do boolean check though)

In addLayerNode method:

if (me.inverseLayerOrder) {
            if (isInsert === true) {
        var totalInGroup = group.getLayers().getLength();
                layerIdx = totalInGroup - layerIdx - 1;
        parentNode.insertChild(layerIdx, layerNode);
            }else{
                parentNode.insertChild(0, layerNode);
            }
        }

in case of inserting/adding layers to existing tree, current code works just fine, so i execute it if isInsert is set to true, oterwise (during tree initial build) layer should be always inserted at 0 :

And the last point, in method onLayerCollectionAdd i added isInsert set to true:
me.addLayerNode(layerOrGroup, true);

Again as i needed quick fix for inverseLayerOrder case i did not test if the code works for standardLayerOrder (bottom layer on top of tree). I can do some testing after the weekend and maybe come up with better solution.

from geoext.

patryksosinski avatar patryksosinski commented on May 13, 2024

The solution is much simpler than i originally thought. To fix the problem we have to iterate through array of layers backwards. This is already done this way, but only for direct children of root node.

from geoext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.