Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polyline layer turns black after turning off all legend filters on custom colors #279

Closed
hupe13 opened this issue Nov 20, 2023 · 4 comments

Comments

@hupe13
Copy link
Contributor

hupe13 commented Nov 20, 2023

Hi Raruto,

the solution of this issue works with default themes and colors only. For custom colors like in your example with a custom theme it doesn't work.

The track is black, if preferCanvas is false and if I turn all legend filters off.
If I set preferCanvas to true, the color of the track is black from the beginning and does not change.

I think, I have to change something for opt.colors:

export const Colors = {
'lightblue': { area: '#3366CC', alpha: 0.45, stroke: '#3366CC' },
'magenta' : { area: '#FF005E' },
'yellow' : { area: '#FF0' },
'purple' : { area: '#732C7B' },
'steelblue': { area: '#4682B4' },
'red' : { area: '#F00' },
'lime' : { area: '#9CC222', line: '#566B13' }
};

L.extend(_.Colors, opts.colors || {});

How should I do that?

Thank you very much.

@hupe13
Copy link
Contributor Author

hupe13 commented Nov 20, 2023

Partially solved. An option in elevationControl like:

colors: {custom: { area: '#9CC222', line: '#FF0000' }},

But stroke-width is not correct yet.

@Raruto
Copy link
Owner

Raruto commented Nov 22, 2023

But stroke-width is not correct yet.

@hupe13 it might be that you need to use a different property name (not all css properties are mapped the same way on the js side):

/**
* Add some basic colors to leaflet canvas renderer (preferCanvas: true).
*/
_fixCanvasPaths() {
let oldProto = L.Canvas.prototype._fillStroke;
let control = this;
let theme = this.options.theme.split(' ')[0].replace('-theme', '');
let color = _.Colors[theme] || {};
L.Canvas.include({
_fillStroke(ctx, layer) {
if (control._layers.hasLayer(layer)) {
let options = layer.options;
options.color = color.line || color.area || theme;
options.stroke = !!options.color;
oldProto.call(this, ctx, layer);
if (options.stroke && options.weight !== 0) {
let oldVal = ctx.globalCompositeOperation || 'source-over';
ctx.globalCompositeOperation = 'destination-over'
ctx.strokeStyle = color.outline || '#FFF';
ctx.lineWidth = options.weight * 1.75;
ctx.stroke();
ctx.globalCompositeOperation = oldVal;
}
} else {
oldProto.call(this, ctx, layer);
}
}
});
},

@hupe13
Copy link
Contributor Author

hupe13 commented Nov 22, 2023

I have given up doing it this way. It's too complicated for me. I set prefercanvas back to false and it works as described here.

Thank you very much.

@hupe13 hupe13 closed this as completed Nov 22, 2023
@Raruto
Copy link
Owner

Raruto commented Nov 23, 2023

But stroke-width is not correct yet.

@hupe13 At first glance, color.outline should be the property you have been looking for:

ctx.strokeStyle = color.outline || '#FFF';

For more info:

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

No branches or pull requests

2 participants