1

I´m using the groupedlayers with empty "dummy" layer groups that are only used to enable or disable filters for the GeoJSON layer when selected/unselected in the layers control. Layers DOI_A6SC, DOI_A6SC, DOI_SUBS, and DOI_SUCC include all markers.

How should I do it so that when selecting one or more layers (DOI_A6SC, DOI_A6SC, DOI_SUBS, DOI_SUCC), and one or more secondary layers, only the markers that have feature.properties.DOI_A6SC == '1' and feature.properties.PosteM_8 == '1', for example.

Example GeoJSON:

{
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -8.60581,
                    39.3752
                ]
            },
            "properties": {
                "Nemesis": "20DOI_SUBS012522",
                "Estado": "G",
                "CCO": "43",
                "ACL": "43PN02",
                "ACL_DESC": "(43PN02) ALQUEIDAO-CASEVEL",
                "Data_importacao": "2024-01-02 21:46:04",
                "TM_Estado_Interv": "[720-%[",
                "DOI_A6SC": "0",
                "DOI_A6CC": "0",
                "DOI_SUBS": "1",
                "DOI_SUBC": "0",
                "PosteM_7": "0",
                "PosteM_8": "1",
                "PosteM_9": "0",
                "PosteM_10": "1",
                "PosteM_12": "0",
                "PosteM_15": "0",
                "PosteB_8_450": "0",
                "PosteB_9_450": "0",
                "PosteB_9_800": "0",
                "PosteB_9_1200": "0",
                "PosteB_10_800": "0",
                "PosteB_10_1800": "0",
                "CVP_Redonda": "0",
                "NR1_D400": "0",
                "NR1_B125": "0",
                "NR2_D400": "0",
                "NR2_B125": "0",
                "NR3_D400": "0",
                "Trab_Fibra_Cabo": "0",
                "Trab_Cobre_Cabo": "0",
                "Trab_Fibra_Juntista": "0",
                "Trab_Cobre_Juntista": "0",
                "ValorProjeto": "1335.76",
                "TM_Estado": "1421,4",
                "Descricao_Orcamento": "(MJP) Rua da Fonte Santa – Alqueidão (39.37520 -8.60581).",
                "Descricao_Observacao": "Necessário também substituir 3 postes. O poste da caixa 0201057 é de 8 metros com espia e acessórios RAD. Os dois postes seguintes, na direção da caixa 0201056 são respetivamente de 8 metros e de 10 m"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -8.795743,
                    39.345886
                ]
            },
            "properties": {
                "Nemesis": "20DOI_SUBS018407",
                "Estado": "G",
                "CCO": "43",
                "ACL": "43TZ01",
                "ACL_DESC": "(43TZ01) TREMEZ",
                "Data_importacao": "2024-01-02 21:46:04",
                "TM_Estado_Interv": "[720-%[",
                "DOI_A6SC": "0",
                "DOI_A6CC": "0",
                "DOI_SUBS": "1",
                "DOI_SUBC": "0",
                "PosteM_7": "0",
                "PosteM_8": "0",
                "PosteM_9": "1",
                "PosteM_10": "0",
                "PosteM_12": "0",
                "PosteM_15": "0",
                "PosteB_8_450": "0",
                "PosteB_9_450": "0",
                "PosteB_9_800": "0",
                "PosteB_9_1200": "0",
                "PosteB_10_800": "0",
                "PosteB_10_1800": "0",
                "CVP_Redonda": "0",
                "NR1_D400": "0",
                "NR1_B125": "0",
                "NR2_D400": "0",
                "NR2_B125": "0",
                "NR3_D400": "0",
                "Trab_Fibra_Cabo": "0",
                "Trab_Cobre_Cabo": "0",
                "Trab_Fibra_Juntista": "0",
                "Trab_Cobre_Juntista": "0",
                "ValorProjeto": "179.71",
                "TM_Estado": "1411,2",
                "Descricao_Orcamento": "(GV) Estrada Outeiro da Cortiçada para Correias, Apoio FO72 (39.345886, -8.795743).",
                "Descricao_Observacao": "Proceder substituição de poste de 9 metros em mau estado  e apear cabo rad desativo"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -8.62243,
                    39.32372
                ]
            },
            "properties": {
                "Nemesis": "20DOI_SUBS023353",
                "Estado": "G",
                "CCO": "43",
                "ACL": "43AN02",
                "ACL_DESC": "(43AN02) VALE FIGUEIRA",
                "Data_importacao": "2024-01-02 21:46:04",
                "TM_Estado_Interv": "[720-%[",
                "DOI_A6SC": "0",
                "DOI_A6CC": "0",
                "DOI_SUBS": "0",
                "DOI_SUBC": "1",
                "PosteM_7": "0",
                "PosteM_8": "0",
                "PosteM_9": "1",
                "PosteM_10": "0",
                "PosteM_12": "0",
                "PosteM_15": "0",
                "PosteB_8_450": "0",
                "PosteB_9_450": "0",
                "PosteB_9_800": "0",
                "PosteB_9_1200": "0",
                "PosteB_10_800": "0",
                "PosteB_10_1800": "0",
                "CVP_Redonda": "0",
                "NR1_D400": "0",
                "NR1_B125": "0",
                "NR2_D400": "0",
                "NR2_B125": "0",
                "NR3_D400": "0",
                "Trab_Fibra_Cabo": "0",
                "Trab_Cobre_Cabo": "0",
                "Trab_Fibra_Juntista": "0",
                "Trab_Cobre_Juntista": "0",
                "ValorProjeto": "317.13",
                "TM_Estado": "1398,2",
                "Descricao_Orcamento": "(GV) Rua da Aroeira – Vale de Figueira (39.32372 -8.62243).",
                "Descricao_Observacao": "Necessário substituir poste 9 metros da caixa 0202052. Poste com duas espias, necessário substituir uma delas para que fique corretamente na bissetriz. Tensionar corretamente cabos RAL e apear cabos R"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -8.679285,
                    39.228387
                ]
            },
            "properties": {
                "Nemesis": "20DOI_SUBS042993",
                "Estado": "G",
                "CCO": "43",
                "ACL": "43ST01",
                "ACL_DESC": "(43ST01) SANTAREM",
                "Data_importacao": "2024-01-02 21:46:04",
                "TM_Estado_Interv": "[720-%[",
                "DOI_A6SC": "0",
                "DOI_A6CC": "1",
                "DOI_SUBS": "0",
                "DOI_SUBC": "0",
                "PosteM_7": "0",
                "PosteM_8": "0",
                "PosteM_9": "0",
                "PosteM_10": "0",
                "PosteM_12": "1",
                "PosteM_15": "0",
                "PosteB_8_450": "0",
                "PosteB_9_450": "0",
                "PosteB_9_800": "0",
                "PosteB_9_1200": "0",
                "PosteB_10_800": "0",
                "PosteB_10_1800": "0",
                "CVP_Redonda": "0",
                "NR1_D400": "0",
                "NR1_B125": "0",
                "NR2_D400": "0",
                "NR2_B125": "0",
                "NR3_D400": "0",
                "Trab_Fibra_Cabo": "0",
                "Trab_Cobre_Cabo": "0",
                "Trab_Fibra_Juntista": "0",
                "Trab_Cobre_Juntista": "0",
                "ValorProjeto": "190.71",
                "TM_Estado": "1358",
                "Descricao_Orcamento": "(AT) - Rua da Imaculada Conceição S/N – Santarém. Coordenadas: 39.228387, -8.679285",
                "Descricao_Observacao": "Substituir um poste de 9mt em mau estado de conservação (furado do Pica-pau)."
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -8.634911,
                    39.340345
                ]
            },
            "properties": {
                "Nemesis": "20DOI_SUBS048112",
                "Estado": "G",
                "CCO": "43",
                "ACL": "43AN02",
                "ACL_DESC": "(43AN02) VALE FIGUEIRA",
                "Data_importacao": "2024-01-02 21:46:04",
                "TM_Estado_Interv": "[720-%[",
                "DOI_A6SC": "1",
                "DOI_A6CC": "0",
                "DOI_SUBS": "0",
                "DOI_SUBC": "0",
                "PosteM_7": "0",
                "PosteM_8": "0",
                "PosteM_9": "0",
                "PosteM_10": "0",
                "PosteM_12": "0",
                "PosteM_15": "0",
                "PosteB_8_450": "1",
                "PosteB_9_450": "0",
                "PosteB_9_800": "0",
                "PosteB_9_1200": "0",
                "PosteB_10_800": "0",
                "PosteB_10_1800": "0",
                "CVP_Redonda": "0",
                "NR1_D400": "0",
                "NR1_B125": "0",
                "NR2_D400": "0",
                "NR2_B125": "0",
                "NR3_D400": "0",
                "Trab_Fibra_Cabo": "0",
                "Trab_Cobre_Cabo": "0",
                "Trab_Fibra_Juntista": "0",
                "Trab_Cobre_Juntista": "0",
                "ValorProjeto": "249.27",
                "TM_Estado": "1342,5",
                "Descricao_Orcamento": "(MJP) Tojosa (São Vicente do Paúl), nas coordenadas 39.340345 -8.634911",
                "Descricao_Observacao": "Necessário substituir poste de 8m que se encontra todo furado pelo pica pau. O poste em questão é o poste do PD AA01001 de 43AN02."
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -8.712596,
                    39.306305
                ]
            },
            "properties": {
                "Nemesis": "20DOI_SUBS060457",
                "Estado": "G",
                "CCO": "43",
                "ACL": "43RM01",
                "ACL_DESC": "(43RM01) ROMEIRA",
                "Data_importacao": "2024-01-02 21:46:04",
                "TM_Estado_Interv": "[720-%[",
                "DOI_A6SC": "1",
                "DOI_A6CC": "0",
                "DOI_SUBS": "0",
                "DOI_SUBC": "0",
                "PosteM_7": "0",
                "PosteM_8": "0",
                "PosteM_9": "1",
                "PosteM_10": "0",
                "PosteM_12": "0",
                "PosteM_15": "0",
                "PosteB_8_450": "0",
                "PosteB_9_450": "0",
                "PosteB_9_800": "1",
                "PosteB_9_1200": "0",
                "PosteB_10_800": "0",
                "PosteB_10_1800": "0",
                "CVP_Redonda": "0",
                "NR1_D400": "0",
                "NR1_B125": "0",
                "NR2_D400": "0",
                "NR2_B125": "0",
                "NR3_D400": "0",
                "Trab_Fibra_Cabo": "0",
                "Trab_Cobre_Cabo": "0",
                "Trab_Fibra_Juntista": "0",
                "Trab_Cobre_Juntista": "0",
                "ValorProjeto": "283.09",
                "TM_Estado": "1305,6",
                "Descricao_Orcamento": "(TA) Rua de S. Brás , Casais de S. Brás ,Coord: 39.306305, -8.712596",
                "Descricao_Observacao": "Traçado RAD antigo em postes de 8mt em que se verifica-se a necessidade de instalar um poste de madeira de 9mt em travessia de estrada, instalar 1 travessa, instalar 200mt de cabo Drop definitivamente passando pelo novo poste e apear poste desativado de 8"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -8.860203,
                    39.464981
                ]
            },
            "properties": {
                "Nemesis": "20DOI_SUBS081862",
                "Estado": "G",
                "CCO": "43",
                "ACL": "43AD03",
                "ACL_DESC": "(43AD03) ALCANEDE",
                "Data_importacao": "2024-01-02 21:46:04",
                "TM_Estado_Interv": "[720-%[",
                "DOI_A6SC": "0",
                "DOI_A6CC": "1",
                "DOI_SUBS": "0",
                "DOI_SUBC": "0",
                "PosteM_7": "0",
                "PosteM_8": "0",
                "PosteM_9": "0",
                "PosteM_10": "0",
                "PosteM_12": "0",
                "PosteM_15": "1",
                "PosteB_8_450": "0",
                "PosteB_9_450": "0",
                "PosteB_9_800": "0",
                "PosteB_9_1200": "0",
                "PosteB_10_800": "0",
                "PosteB_10_1800": "0",
                "CVP_Redonda": "0",
                "NR1_D400": "0",
                "NR1_B125": "0",
                "NR2_D400": "0",
                "NR2_B125": "0",
                "NR3_D400": "0",
                "Trab_Fibra_Cabo": "0",
                "Trab_Cobre_Cabo": "0",
                "Trab_Fibra_Juntista": "0",
                "Trab_Cobre_Juntista": "0",
                "ValorProjeto": "243.07",
                "TM_Estado": "1245,5",
                "Descricao_Orcamento": "(TA) Valverde - 39.464981, -8.860203",
                "Descricao_Observacao": "43AD01GP310 - JSO42 - Poste A2 - Poste de 9m degradado que é necessário substituir"
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -8.841953,
                    39.427161
                ]
            },
            "properties": {
                "Nemesis": "20DOI_SUBS118230",
                "Estado": "G",
                "CCO": "43",
                "ACL": "43AD01",
                "ACL_DESC": "(43AD01) ALCANEDE",
                "Data_importacao": "2024-01-02 21:46:04",
                "TM_Estado_Interv": "[720-%[",
                "DOI_A6SC": "0",
                "DOI_A6CC": "1",
                "DOI_SUBS": "0",
                "DOI_SUBC": "0",
                "PosteM_7": "0",
                "PosteM_8": "0",
                "PosteM_9": "0",
                "PosteM_10": "0",
                "PosteM_12": "0",
                "PosteM_15": "0",
                "PosteB_8_450": "0",
                "PosteB_9_450": "0",
                "PosteB_9_800": "0",
                "PosteB_9_1200": "0",
                "PosteB_10_800": "0",
                "PosteB_10_1800": "0",
                "CVP_Redonda": "0",
                "NR1_D400": "1",
                "NR1_B125": "0",
                "NR2_D400": "0",
                "NR2_B125": "0",
                "NR3_D400": "0",
                "Trab_Fibra_Cabo": "0",
                "Trab_Cobre_Cabo": "0",
                "Trab_Fibra_Juntista": "0",
                "Trab_Cobre_Juntista": "0",
                "ValorProjeto": "479.82",
                "TM_Estado": "1152,3",
                "Descricao_Orcamento": "(TA) Poste de PDO497, Rua da Piçarra, Mosteiros – Alcanede. Coordenadas: 39.427161, -8.841953 ",
                "Descricao_Observacao": "Necessário criar NS para substituir poste de 9mt podre por poste de 12mt, colocar o novo poste na via publica junto ao muro e instalar espia. Segue em anexo o orçamento."
            }
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -8.66215,
                    39.385651
                ]
            },
            "properties": {
                "Nemesis": "20DOI_SUBS127368",
                "Estado": "G",
                "CCO": "43",
                "ACL": "43PN01",
                "ACL_DESC": "(43PN01) PERNES",
                "Data_importacao": "2024-01-02 21:46:04",
                "TM_Estado_Interv": "[720-%[",
                "DOI_A6SC": "0",
                "DOI_A6CC": "0",
                "DOI_SUBS": "0",
                "DOI_SUBC": "1",
                "PosteM_7": "0",
                "PosteM_8": "0",
                "PosteM_9": "0",
                "PosteM_10": "0",
                "PosteM_12": "0",
                "PosteM_15": "0",
                "PosteB_8_450": "0",
                "PosteB_9_450": "0",
                "PosteB_9_800": "0",
                "PosteB_9_1200": "0",
                "PosteB_10_800": "0",
                "PosteB_10_1800": "0",
                "CVP_Redonda": "0",
                "NR1_D400": "0",
                "NR1_B125": "0",
                "NR2_D400": "1",
                "NR2_B125": "0",
                "NR3_D400": "0",
                "Trab_Fibra_Cabo": "0",
                "Trab_Cobre_Cabo": "0",
                "Trab_Fibra_Juntista": "0",
                "Trab_Cobre_Juntista": "0",
                "ValorProjeto": "164.42",
                "TM_Estado": "1134,4",
                "Descricao_Orcamento": "(TA) Rua Comendador José Gonçalves Pereira, 139 – Pernes: Coordenadas: 39.385651, -8.662150 ",
                "Descricao_Observacao": "Apear dois postes de madeira onde foram colocados tês postes de betão e passar cabo RAD para os novos postes."
            }
        }

JS:

var selectCondition = [];
var selectLayer = [];

for (var i = 0; i < 35; i++) {
    selectCondition[i] = false;
    selectLayer[i] = L.layerGroup();
    selectLayer[i].myId = i;
}

var baseMaps = {
    "OSM": osm,
    'Google Street': googleStreets,
    "Google Satellite": googleSat,
};

var mcg = L.markerClusterGroup.layerSupport({
    chunkedLoading: true,
    chunkInterval: 100,
    chunkProgress: updateProgressBar
})

var overlayMaps = {
    'Todos': {
        'DOI_A6SC':selectLayer[0],
        'DOI_A6CC':selectLayer[1],
        'DOI_SUBS':selectLayer[2],
        'DOI_SUBC':selectLayer[3],
    },
    'Postes': {
        'PosteM 7m': selectLayer[4],
        'PosteM 8m': selectLayer[5],
        'PosteM 9m': selectLayer[6],
        'PosteM 10m': selectLayer[7],
        'PosteM 12m': selectLayer[8],
        'PosteM 15m': selectLayer[9],
        'PosteB 8m 450Kg': selectLayer[10],
        'PosteB 9m 450Kg': selectLayer[11],
        'PosteB 9m 800Kg': selectLayer[12],
        'PosteB 9m 1200Kg': selectLayer[13],
        'PosteB 10m 800Kg': selectLayer[14],
        'PosteB 10m 1800Kg': selectLayer[15]
    },
    'CVP´s': {
        'CVP_Redonda': selectLayer[16],
        'NR1_D400': selectLayer[17],
        'NR1_B125': selectLayer[18],
        'NR2_D400': selectLayer[19],
        'NR2_B125': selectLayer[20],
        'NR3_D400': selectLayer[21],
        'NR3_B125': selectLayer[22]
    },
    'Tipo Trabalhos': {
        'Trabalhos Fibra Cabo': selectLayer[23],
        'Trabalhos Fibra Juntista': selectLayer[24],
        'Trabalhos Cobre Cabo': selectLayer[25],
        'Trabalhos Cobre Juntista': selectLayer[26]
    },
    'Antiguidade': {
            '[000-015[': selectLayer[27],
            '[015-030[': selectLayer[28],
            '[030-060[': selectLayer[29],
            '[060-120[': selectLayer[30],
            '[120-280[': selectLayer[31],
            '[280-360[': selectLayer[32],
            '[360-720[': selectLayer[33],
            '[720-%[': selectLayer[34]
        }
};
var options = {
    groupCheckboxes: false,
    collapsed: false
};

L.control.groupedLayers(baseMaps, overlayMaps, options).addTo(map);

var report = L.geoJSON(null, {
    filter: function(feature, layer) {
        var cond0 = ((feature.properties.DOI_A6SC == '1') && selectCondition[0]);
        var cond1 = ((feature.properties.DOI_A6CC == '1') && selectCondition[1]);
        var cond2 = ((feature.properties.DOI_SUBS == '1') && selectCondition[2]);
        var cond3 = ((feature.properties.DOI_SUBC == '1') && selectCondition[3]);
        var cond4 = ((feature.properties.PosteM_7 == '1') && selectCondition[4]);
        var cond5 = ((feature.properties.PosteM_8 == '1') && selectCondition[5]);
        var cond6 = ((feature.properties.PosteM_9 == '1') && selectCondition[6]);
        var cond7 = ((feature.properties.PosteM_10 == '1') && selectCondition[7]);
        var cond8 = ((feature.properties.PosteM_12 == '1') && selectCondition[8]);
        var cond9 = ((feature.properties.PosteM_15 == '1') && selectCondition[9]);
        var cond10 = ((feature.properties.PosteB_8_450 == '1') && selectCondition[10]);
        var cond11 = ((feature.properties.PosteB_9_450 == '1') && selectCondition[11]);
        var cond12 = ((feature.properties.PosteB_9_800 == '1') && selectCondition[12]);
        var cond13 = ((feature.properties.PosteB_9_1200 == '1') && selectCondition[13]);
        var cond14 = ((feature.properties.PosteB_10_800 == '1') && selectCondition[14]);
        var cond15 = ((feature.properties.PosteB_10_1800 == '1') && selectCondition[15]);
        var cond16 = ((feature.properties.CVP_Redonda == '1') && selectCondition[16]);
        var cond17 = ((feature.properties.NR1_D400 == '1') && selectCondition[17]);
        var cond18 = ((feature.properties.NR1_B125 == '1') && selectCondition[18]);
        var cond19 = ((feature.properties.NR2_D400 == '1') && selectCondition[19]);
        var cond20 = ((feature.properties.NR2_B125 == '1') && selectCondition[20]);
        var cond21 = ((feature.properties.NR3_D400 == '1') && selectCondition[21]);
        var cond22 = ((feature.properties.NR3_B125 == '1') && selectCondition[22]);
        var cond23 = ((feature.properties.Trab_Fibra_Cabo == '1') && selectCondition[23]);
        var cond24 = ((feature.properties.Trab_Fibra_Juntista == '1') && selectCondition[24]);
        var cond25 = ((feature.properties.Trab_Cobre_Cabo == '1') && selectCondition[25]);
        var cond26 = ((feature.properties.Trab_Cobre_Juntista == '1') && selectCondition[26]);
        var cond27 = ((feature.properties.TM_Estado_Interv == '[000-015[') && selectCondition[27]);
        var cond28 = ((feature.properties.TM_Estado_Interv == '[015-030[') && selectCondition[28]);
        var cond29 = ((feature.properties.TM_Estado_Interv == '[030-060[') && selectCondition[29]);
        var cond30 = ((feature.properties.TM_Estado_Interv == '[060-120[') && selectCondition[30]);
        var cond31 = ((feature.properties.TM_Estado_Interv == '[120-280[') && selectCondition[31]);
        var cond32 = ((feature.properties.TM_Estado_Interv == '[280-360[') && selectCondition[32]);
        var cond33 = ((feature.properties.TM_Estado_Interv == '[360-720[') && selectCondition[33]);
        var cond34 = ((feature.properties.TM_Estado_Interv == '[720-%[') && selectCondition[34]);
        return (cond0 || cond1 || cond2 || cond3 || cond4 || cond5 || cond6 || cond7 || cond8 || cond9 || cond10
            || cond11 || cond12 || cond13 || cond14 || cond15 || cond16 || cond17 || cond18 || cond19
            || cond20 || cond21 || cond22 || cond23 || cond24 || cond25 || cond26 || cond27 || cond28
            || cond29 || cond30 || cond31 || cond32 || cond33 || cond34);
    },
    pointToLayer: function (feature, latlng) {
        return new L.marker(latlng, {
            icon: myIcon, draggable: false});
    },
    onEachFeature: setPopup_nemesis_materiais
});

mcg.checkIn([
    report
]);

var geojsonData;
var url = './markers/markers.json';
fetch(url)
    .then(response => {
        return response.json();
    })
    .then(json => {
        geojsonData = json;
        map.addLayer(report);
        selectLayer[0].addTo(map);
        selectLayer[1].addTo(map);
        selectLayer[2].addTo(map);
        selectLayer[3].addTo(map);
        mcg.addTo(map);
    });

map.on('overlayadd', function(evt) {
    var i = evt.layer.myId;
    selectCondition[i] = true;
    report.clearLayers();
    report.addData(geojsonData);
});

map.on('overlayremove', function(evt) {
    var i = evt.layer.myId;
    selectCondition[i] = false;
    report.clearLayers();
    report.addData(geojsonData);
});

enter image description here

4
  • There is no code for using leaflet-groupedlayercontrol in your question. Please edit your question and add code of how are you trying to use this control. Also, what are mcg and selectLayer and where are these coming from? Please add relevant code.
    – TomazicM
    Commented Jan 12 at 20:50
  • Edited post. Thanks Commented Jan 14 at 10:22
  • Your sample GeoJSON data properties do not match with conditions in code. None of features has DOI_A6SC, DOI_A6CC, DOI_SUBS or DOI_SUBC property. They do have properties PostM_8, PostM_9, PostM_10, PostM_12, PostB_8_450 and PoseM_9, but these are not used in the code. Please edit your question and add sample GeoJSON data that matches conditions in your code.
    – TomazicM
    Commented Jan 14 at 13:20
  • Edited post. Thanks Commented Jan 14 at 14:39

1 Answer 1

0

If you call first four layers (Todos group) primary layers and the rest of them secondary layers, then individual marker is shown on the map if one of the following conditions is fulfilled:

  • it belongs to one of the selected primary layers and no secondary layer is selected;
  • it belongs to one of the selected secondary layers and no primary layer is selected;
  • it belongs to selected primary layer and selected secondary layer.

To test if any of primary or secondary layers is selected, two variables nSelectedA and nSelectedB that contain number of currently selected primary (A) and secondary (B) layers are used.

Relevant parts of the code could then look something like this:

nSelectedA = 0;
nSelectedB = 0;

var report = L.geoJSON(null, {
  filter: function(feature, layer) {
    var cond0 = ((feature.properties.DOI_A6SC == '1') && selectCondition[0]);
    var cond1 = ((feature.properties.DOI_A6CC == '1') && selectCondition[1]);
    var cond2 = ((feature.properties.DOI_SUBS == '1') && selectCondition[2]);
    var cond3 = ((feature.properties.DOI_SUBC == '1') && selectCondition[3]);
    var cond4 = ((feature.properties.PosteM_7 == '1') && selectCondition[4]);
    var cond5 = ((feature.properties.PosteM_8 == '1') && selectCondition[5]);
    var cond6 = ((feature.properties.PosteM_9 == '1') && selectCondition[6]);
    var cond7 = ((feature.properties.PosteM_10 == '1') && selectCondition[7]);
    var cond8 = ((feature.properties.PosteM_12 == '1') && selectCondition[8]);
    var cond9 = ((feature.properties.PosteM_15 == '1') && selectCondition[9]);
    var cond10 = ((feature.properties.PosteB_8_450 == '1') && selectCondition[10]);
    var cond11 = ((feature.properties.PosteB_9_450 == '1') && selectCondition[11]);
    var cond12 = ((feature.properties.PosteB_9_800 == '1') && selectCondition[12]);
    var cond13 = ((feature.properties.PosteB_9_1200 == '1') && selectCondition[13]);
    var cond14 = ((feature.properties.PosteB_10_800 == '1') && selectCondition[14]);
    var cond15 = ((feature.properties.PosteB_10_1800 == '1') && selectCondition[15]);
    var cond16 = ((feature.properties.CVP_Redonda == '1') && selectCondition[16]);
    var cond17 = ((feature.properties.NR1_D400 == '1') && selectCondition[17]);
    var cond18 = ((feature.properties.NR1_B125 == '1') && selectCondition[18]);
    var cond19 = ((feature.properties.NR2_D400 == '1') && selectCondition[19]);
    var cond20 = ((feature.properties.NR2_B125 == '1') && selectCondition[20]);
    var cond21 = ((feature.properties.NR3_D400 == '1') && selectCondition[21]);
    var cond22 = ((feature.properties.NR3_B125 == '1') && selectCondition[22]);
    var cond23 = ((feature.properties.Trab_Fibra_Cabo == '1') && selectCondition[23]);
    var cond24 = ((feature.properties.Trab_Fibra_Juntista == '1') && selectCondition[24]);
    var cond25 = ((feature.properties.Trab_Cobre_Cabo == '1') && selectCondition[25]);
    var cond26 = ((feature.properties.Trab_Cobre_Juntista == '1') && selectCondition[26]);
    var cond27 = ((feature.properties.TM_Estado_Interv == '[000-015[') && selectCondition[27]);
    var cond28 = ((feature.properties.TM_Estado_Interv == '[015-030[') && selectCondition[28]);
    var cond29 = ((feature.properties.TM_Estado_Interv == '[030-060[') && selectCondition[29]);
    var cond30 = ((feature.properties.TM_Estado_Interv == '[060-120[') && selectCondition[30]);
    var cond31 = ((feature.properties.TM_Estado_Interv == '[120-280[') && selectCondition[31]);
    var cond32 = ((feature.properties.TM_Estado_Interv == '[280-360[') && selectCondition[32]);
    var cond33 = ((feature.properties.TM_Estado_Interv == '[360-720[') && selectCondition[33]);
    var cond34 = ((feature.properties.TM_Estado_Interv == '[720-%[') && selectCondition[34]);
    var condition1 =  (cond0 || cond1 || cond2 || cond3);
    var condition2 =  (cond4 || cond5 || cond6 || cond7 || cond8 || cond9 || cond10
      || cond11 || cond12 || cond13 || cond14 || cond15 || cond16 || cond17 || cond18 || cond19
      || cond20 || cond21 || cond22 || cond23 || cond24 || cond25 || cond26 || cond27 || cond28
      || cond29 || cond30 || cond31 || cond32 || cond33 || cond34);
    var condition3 = (nSelectedA > 0);
    var condition4 = (nSelectedB > 0);
    var condition = (condition1 && !condition4) || (condition2 & !condition3) || (condition1 && condition2);
    return(condition);
  },
  pointToLayer: function (feature, latlng) {
    return L.marker(latlng, {
      draggable: false});
  },
  onEachFeature: setPopup_nemesis_materiais
});

map.on('overlayadd', function(evt) {
  var i = evt.layer.myId;
  selectCondition[i] = true;
  report.clearLayers();
  if (i <= 3)
    nSelectedA++;
  else {
    nSelectedB++;
  }
  report.addData(geojsonData);
});

map.on('overlayremove', function(evt) {
  var i = evt.layer.myId;
  selectCondition[i] = false;
  report.clearLayers();
  if (i <= 3)
    nSelectedA--;
  else {
    nSelectedB--;
  }
  report.addData(geojsonData);
});
4
  • I made the changes indicated, but it doesn't seem to work well. For example, when I select DOI_SUBS and DOI_SUBC and PosteM 8m, markers that do not have properties PosteM_8 == 1 appear. I did debugging but I didn't find the problem, can you help me? Thanks Commented Jan 15 at 18:48
  • Does this mean that if you select PosteM_8 and DOI_SUBS and DOI_SUBC, only those markers should appear that have either both PosteM_8 and DOI_SUBS set to 1 or both PosteM_8 and DOI_SUBC set to 1?
    – TomazicM
    Commented Jan 15 at 19:59
  • Yes, exactly. Thanks Commented Jan 15 at 20:38
  • See updated answer.
    – TomazicM
    Commented Jan 16 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.