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

Leaflet layer styling based on a rule #1020

Open
M0OJM opened this issue Jan 27, 2023 · 0 comments
Open

Leaflet layer styling based on a rule #1020

M0OJM opened this issue Jan 27, 2023 · 0 comments
Labels

Comments

@M0OJM
Copy link

M0OJM commented Jan 27, 2023

I am trying to get layers to have different styles based on the property of a numeric field.

In QGIS I am using Symbology - Rule based
I have used
Style A "Progress" = >10 and "Progress" <20
Style B "Progress" >=20 and "Progress" < 30 etc
Progress is an integer.

I have also tried
"Progress" BETWEEN 10 AND 20
"Progress" BETWEEN 20 AND 30

Both work fine in QGIS
In Leaflet the expression the result from the qgis2web expression evaluator
exp_LayerNameXX_13rule0_eval_expression(context) is not returning a value that gives the correct style for these ranges.
This results in some features beng styled with the the wrong style or the ELSE style if it is set.

        // Start of if blocks and style check logic
        if (exp_Layer_13rule0_eval_expression(context)) {
              return {
            pane: 'pane_Layer_13',
            opacity: 1,
            color: 'rgba(35,35,35,1.0)',
            dashArray: '',
            lineCap: 'butt',
            lineJoin: 'miter',
            weight: 2.0, 
            fill: true,
            fillOpacity: 1,
            fillColor: 'rgba(214,131,36,0.48627450980392156)',
            interactive: true,
        };
            }
            else if (exp_Layer_13rule1_eval_expression(context)) {
              return {
            pane: 'pane_Layer_13',

.........
fillColor: 'rgba(97,97,97,0.47058823529411764)',
interactive: true,
};
}
else if (exp_Layer_13rule2_eval_expression(context)) {
etc

Looking at the generated qgis2webexpressions.js

function exp_Layer_13rule1_eval_expression(context) {
// "Progress" > 2019

var feature = context.feature;

if (feature.properties) {
    return (feature.properties['Progress']  > 2019);
} else {
    return (feature['Progress']  > 2019);
}

}
function exp_Layer_13rule2_eval_expression(context) {
// "Progress" BETWEEN 2010 AND 2019

var feature = context.feature;

if (feature.properties) {
    return (feature.properties['Progress']  > 2019);
} else {
    return (feature['Progress']  > 2019);
}

}
function exp_Layer_13rule3_eval_expression(context) {
// "Progress" BETWEEN 2000 AND 2009

var feature = context.feature;

if (feature.properties) {
    return (feature.properties['Progress']  > 2019);
} else {
    return (feature['Progress']  > 2019);        2 and 3 return same result as Rule 1
}

}

if qgis2webexpressions.js is edited as below
function exp_Layer_13rule2_eval_expression(context) {
// "Progress" BETWEEN 2010 AND 2019

var feature = context.feature;

if (feature.properties) {
    return (feature.properties['Progress']  == 2010);
} else {
    return (feature['Progress']  == 2010);
}

}

This gives the correct styling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants