Select to view content in your preferred language

Changing where clause for createQuery()

1183
11
08-08-2023 09:21 PM
Charan
by
New Contributor III

Hi everyone, I'm trying to download statistics for a drawn buffer. I'm able to do that but if I change my year (the where clause) instead of downloading the data for the new year, it keeps using the same year. For instance, if I select 2020, it will download the data statistics using 2020 year but then if I switch to the 2021 year it still downloads 2020. 

 

 

let querycentroids = layer.createQuery();
querycentroids.spatialRelationship = "contains";
querycentroids.geometry = buffgra.geometry;
$(".chosen-benchmark")
    .chosen()
    .change(function () {
      var option = [$("#YearSource").val()];
      var result = "'" + option.join("','") + "'";
      querycentroids.where="year IN (" + result + ")"
      if ($(".chosen-benchmark").val() == 'Toronto') {
        console.log('Toronto')
        if ($(".chosen-year").val() == '2020') {
          console.log('works')
          document.getElementById("report").onclick = () => {
          downloadData(Toronto_2020,option)

          }
        }
        else if ($(".chosen-year").val() == '2021') {
          console.log('works2021')          
          document.getElementById("report").onclick = () => {
          downloadData(Toronto_2021,option)

          }
        }
        else if ($(".chosen-year").val() == '2022') {
          console.log('works2022')          
          document.getElementById("report").onclick = () => {
          downloadData(Toronto_2022,option)

          }
        }
        $(".chosen-year")
        .chosen()
        .change(function () {
          var yearoptions2 = [$("#YearSource").val()];
          var yearresult2 = "'" + yearoptions2.join("','") + "'";
          querycentroids.where="year IN (" + yearresult2 + ")"

          if ($(".chosen-year").val() == '2020') {
            console.log('2020')
            document.getElementById("report").onclick = () => {
              downloadData(Toronto_2020,yearoptions2)

            }
          }
          else if ($(".chosen-year").val() == '2021') {
            console.log('2021')
            document.getElementById("report").onclick = () => {
              downloadData(Toronto_2021,yearoptions2)

            }
          }
          else if ($(".chosen-year").val() == '2022') {
            console.log('2022')
            document.getElementById("report").onclick = () => {
              downloadData(Toronto_2022,yearoptions2)

            }
          }
        })
      }
      else if ($(".chosen-benchmark").val() == 'BC') {
        //// same stuff

      }
    });

  });

 

 

@UndralBatsukh @JoelBennett @KenBuja 

0 Kudos
11 Replies
KenBuja
MVP Esteemed Contributor

You should put this in a separate question. And it's quite an ask to review this much coding. It's better to create a small example that illustrates the problem

0 Kudos
Charan
by
New Contributor III

Hi @KenBuja I had created a new question, could you please check it out

 

0 Kudos