Coder Social home page Coder Social logo

Comments (7)

devemux86 avatar devemux86 commented on June 23, 2024

@stleusc thanks for the report.

The remove also changes the group pointers, so better not mix them.

We could just add the missing bindings from the add.

from vtm.

stleusc avatar stleusc commented on June 23, 2024

but should the group pointers NOT be updated?

Looking at public synchronized void add(int index, Layer layer) it seems it does bindings for 'groups'.
But mGroupList is not touched in that case.

I think there is something else missing regarding groups?!

from vtm.

devemux86 avatar devemux86 commented on June 23, 2024

but should the group pointers NOT be updated?

That's why the remove (used with or without groups) should not be used in regular set.
Just copy these lines from regular add.


The regular add(int index, Layer layer) and set(int index, Layer layer) override List methods
and do not use groups (can only use GroupLayer).

For groups must use the extra add(Layer layer, int group) method.

from vtm.

stleusc avatar stleusc commented on June 23, 2024

Guess I need to ask in a better way...

IF I plan to add a layer (no group) and then remove it, I would do the follwing:

add(index, layer):
remove(layer);

But that does modify the mGroupList on remove!

It seems liket that is not correct?!

I understand how I could make set(index, layer) work but if I just want to remove a layer that still seems to be incorrect or not?

Somehow the generic remove function needs to know if we are in need of messing with mGroupList. And that is NOT always the case.

from vtm.

devemux86 avatar devemux86 commented on June 23, 2024

But that does modify the mGroupList on remove!

No, the remove does not modify the mGroupList.

Anyway groups should either be used for all levels or not.
Using groups and add layers without group makes no sense.
Better not mix them.

from vtm.

stleusc avatar stleusc commented on June 23, 2024

I don't think we understand each other.... I try to explain better.

I want to be able to remove a layer, and at a later time, add a layer.

I call

    @Override
    public synchronized void add(int index, Layer layer) {
        if (mLayerList.contains(layer)) {
            log.warn("layer already exists");
            return;
        }

        // bind added layer
        if (layer instanceof UpdateListener)
            mMap.events.bind((UpdateListener) layer);
        if (layer instanceof InputListener)
            mMap.input.bind((InputListener) layer);
        // add zoom limit to tile manager
        if (layer instanceof ZoomLimiter.IZoomLimiter)
            ((ZoomLimiter.IZoomLimiter) layer).addZoomLimit();

        // bind added group layer
        if (layer instanceof GroupLayer) {
            GroupLayer groupLayer = (GroupLayer) layer;
            for (Layer gl : groupLayer.layers) {
                if (gl instanceof UpdateListener)
                    mMap.events.bind((UpdateListener) gl);
                if (gl instanceof InputListener)
                    mMap.input.bind((InputListener) gl);
                if (gl instanceof ZoomLimiter.IZoomLimiter)
                    ((ZoomLimiter.IZoomLimiter) gl).addZoomLimit();
            }
        }

        layer.setEnableHandler(mEnableHandler);
        mLayerList.add(index, layer);
        mDirtyLayers = true;
    }

and

    @Override
    public synchronized Layer remove(int index) {
        mDirtyLayers = true;

        Layer remove = mLayerList.remove(index);

        // unbind removed layer
        if (remove instanceof UpdateListener)
            mMap.events.unbind((UpdateListener) remove);
        if (remove instanceof InputListener)
            mMap.input.unbind((InputListener) remove);
        // remove zoom limit from tile manager
        if (remove instanceof ZoomLimiter.IZoomLimiter)
            ((ZoomLimiter.IZoomLimiter) remove).removeZoomLimit();

        // unbind removed group layer
        if (remove instanceof GroupLayer) {
            GroupLayer groupLayer = (GroupLayer) remove;
            for (Layer gl : groupLayer.layers) {
                if (gl instanceof UpdateListener)
                    mMap.events.unbind((UpdateListener) gl);
                if (gl instanceof InputListener)
                    mMap.input.unbind((InputListener) gl);
                if (gl instanceof ZoomLimiter.IZoomLimiter)
                    ((ZoomLimiter.IZoomLimiter) gl).removeZoomLimit();
            }
        }

~~~ FROM HERE
        // update layer group pointers
        for (Integer group : mGroupIndex.keySet()) {
            int pointer = mGroupIndex.get(group);
            if (pointer > index)
                mGroupIndex.put(group, pointer - 1);
        }
~~~ TO HERE

        remove.setEnableHandler(null);
        return remove;
    }

Why does the second function contain the portion marked? Does that NOT mess with mGroupIndex?

You said early on, I should NOT call remove followed by an add.
I am confused... I am not using groups. Just those 2 functions.

Does this make more sense now?

from vtm.

devemux86 avatar devemux86 commented on June 23, 2024

Why does the second function contain the portion marked? Does that NOT mess with mGroupIndex?

If layers size changes, the group index should be updated. And like already mentioned:

Anyway groups should either be used for all levels or not.
Using groups and add layers without group makes no sense.
Better not mix them.

So if not using groups there is no problem.
And if using groups, must use them for all layers.

I said we should not call remove / add inside the set,
but just copy the relevant section.

from vtm.

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.