这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@damien-faivre
Copy link

Fixed by @tobwen in this issue 👉 #556

Handle transparency when merging
Comment on lines +468 to +478
transparent_layers = []
for layer in async_.imap(get_map_from_source, self.sources):
if layer[0] is not None:
layers.append(layer)
try:
transparent_layers.append(layer[0].image_opts.transparent)
except AttributeError:
transparent_layers.append(None)

if len(transparent_layers) > 0 and all(transparent_layers):
self.tile_mgr.image_opts.transparent = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
transparent_layers = []
for layer in async_.imap(get_map_from_source, self.sources):
if layer[0] is not None:
layers.append(layer)
try:
transparent_layers.append(layer[0].image_opts.transparent)
except AttributeError:
transparent_layers.append(None)
if len(transparent_layers) > 0 and all(transparent_layers):
self.tile_mgr.image_opts.transparent = True
all_transparent = True
for layer in async_.imap(get_map_from_source, self.sources):
if layer[0] is not None:
layers.append(layer)
if 'image_opts' in layer[0] and layer[0].image_opts.transparent:
all_transparent = all_transparent and layer[0].image_opts.transparent
else:
all_transparent = False
if all_transparent:
self.tile_mgr.image_opts.transparent = True

please check if this works. The code is a little clearer than using except.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember I wrote a test for this 2 years ago. I need to check my private repository... I remember that the bug was pretty annoying and except was my last resort. Is it okay to block this for up to 2 days so that I can find the test?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sure. If you could add a test or two that would be really great.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedbacks, and thanks again @tobwen for this code snippet. It works perfectly fine as is but we plan to test your suggestion Simon. Will let you know in a few days.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one was it: tobwen@cbc3cca

I hope I can test it tomorrow.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a try.

if 'image_opts' in layer[0] and layer[0].image_opts.transparent:

Gives me the following error :

TypeError: argument of type 'ImageSource' is not iterable

I fixed it with the following :

        all_transparent = True
        for layer in async_.imap(get_map_from_source, self.sources):
            if layer[0] is not None:
                layers.append(layer)
                try:
                    if not layer[0].image_opts.transparent:
                        all_transparent = False
                        break
                except AttributeError:
                    all_transparent = False
                    break

        if all_transparent:
            self.tile_mgr.image_opts.transparent = True

That works fine, I'll double check that with @damien-faivre and he should add this to this PR.

Copy link
Collaborator

@simonseyock simonseyock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants