Issue with GeoJSON filtering functionality in Leaflet causing geometry to malfunction

I have successfully used filter() to retrieve only Estate (UF) data from my country using Axios:

async created() {
    await axios.get('https://raw.githubusercontent.com/fititnt/gis-dataset-brasil/master/mesorregiao/geojson/mesorregiao.json')
      .then((response) => {
          const myUf = 'GO'
          const data = response.data.features.filter(item => item.properties.UF = myUf)
          console.log(response.data.features.filter(item => item.properties.UF = myUf))
          this.geojson = data;
        }
      )
  }

Everything is working fine, as I can see all the data in the log! However, when I display it on my page, all regions are colored. Is there any additional configuration that needs to be done?
I want to color only the specific regions that I filtered.
I couldn't find anything in the LeafLet or Vue-Leaflet documentation!

https://i.sstatic.net/5Czk1.png

As requested, here's a look at my code: In my data() method, where I call geojson in Vue

data() {
    return {
      zoom: 6.4,
      center: latLng(-15.7745457, -48.3575684),
      url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
      attribution:
        '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors | TRE-GO',
      geojson: null,
      fillColor: "#6a0dad",
    }
  },  

Here's my L-map component:

<l-map
      :zoom="zoom"
      :center="center"
      style="height: 500px; width: 100%"
    >
      <l-tile-layer
        :url="url"
        :attribution="attribution"
      />
      <l-geo-json :geojson="geojson"
                  :options-style="styleFunction"/>


    </l-map>

Answer №1

It seems that your filter function is not effectively filtering data due to an assignment (using 1 equal sign) rather than a comparison (using either 2 or 3 equal signs):

item => item.properties.UF = myUf

To fix this issue, you should update it to:

item => item.properties.UF === myUf

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to break apart a string of text without a regular pattern

Here is the data I am working with: Huawei Y7P Art-L28 (4/64gb) (AAAAAAAAAAAAAA) EXP:02/19/2020 Huawei Y9 prime 2019 (BBBBBBBBBBBBBBB) EXP:07/17/2019 Oppo A31 4gb/128gb (CCCCCCCCCCCCCCC) Vivo Y15 5000mah 4GB/64GB (1901) (DDDDDDDDDDDDDDD) EXP:06/14/2019 I ...

``Is there a way to redirect users when they click outside the modal-content in Bootstrap

I have a modal on my website that currently redirects to the homepage when the close button is clicked. However, I also want it to redirect to the homepage when clicking outside of the bootstrap modal, specifically targeting the ".modal-content" class. I ...

Transfer a set of characters from an array to a pointer of characters

I'm attempting to transfer a char[] array into a char* pointer. I have two data types: CHAR* dst and CHAR src[] My objective is to complete this task without relying on C++ constructs like new or delete. This essentially means that I am searching f ...

Resolving negative margin issues in Material UI components through detailed textual guidance

Having an issue with the paragraphs in material-ui components. The problem arises when the text exceeds the dimensions of the component, causing it to spill over as shown in the image below. <Grid container wrap="nowrap" css={[borde,{ ...

Regular expression that allows for the inclusion of whitespace before verifying a single character

I've been trying to figure out a search pattern online, but as a beginner, I'm having trouble verifying it. I'd appreciate an example, if possible. [Check for any white spaces] [one of the following characters: ':' '|&apos ...

What is the best way to deactivate select option(s) based on the JSON data retrieved through AJAX?

I am facing an issue with a dropdown menu that contains several options. My goal is to loop through these options and set the disabled attribute on specific ones based on the result of an Ajax call. https://i.sstatic.net/9k3f9.png This is what I am tryin ...

Display a modal when closing a tab using Vue.js

I'm attempting to display a confirmation popup when the page reloads or the user navigates outside of my website in Vue.js. I have already implemented the beforeRouteLeave function in my component, but it only works when navigating to another page wit ...

Unable to locate the AngularJS controller after attempting to paste the code

Currently enrolled in the AngularJS Mastery Course on Udemy, I encountered an odd issue that has left me scratching my head. The code provided seems to function flawlessly for most users, except for a select few. index.html <html lang="en" ng-app=&apo ...

Are there any Java alternatives comparable to PHP arrays with non-numeric keys?

How can we convert this PHP array to Java? HashMap<String, String> user = new HashMap<>(); user.put("name", "John"); user.put("email", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92f8fdfafcd2fff3fbfebcf1fdff" ...

The Angular template driven forms are flagging as invalid despite the regExp being a match

My input looks like this: <div class="form-group"> <label for="power">Hero Power</label> <input [(ngModel)]="model.powerNumber" name="powerNumber" type="text" class="form-control" pattern="^[0-9]+$"id= ...

Learn how to automatically deploy a Vue.js application to cPanel using GitHub Actions, specifically targeting the files inside the "dist

In my Vue.js project, let's call it "my_web", I have successfully deployed it to the public_html folder in cPanel. The issue I am facing is that all files from the my_web directory are being uploaded. I only want the files from the dist folder to be u ...

Guide on uploading files with VueJS and Laravel 5.3

I'm currently working on a single-page application using VueJS, Laravel 5.3, and Passport Authentication module. So far, my code is working fine and I can successfully retrieve the selected file names. However, I am unsure how to proceed with sending ...

The Vue warning indicates that there was a failed type check for the "value" prop. It was expecting an array but received a number with a value of 1

I am facing an issue with an input of type number where I need to restrict the user from entering a number greater than ten. Initially, everything was working fine until I decided to change the value to an array (from value: 1 to value: [1, 1]) After swit ...

What differences exist in the implications of the options for the socket.io server object?

According to the socket.io documentation, you have the option to utilize the http.Server object or directly input a port number into the socket.io server object. What distinguishes the two methods? Instantiate the socket.io Object const io = require(&apo ...

Display iframe as the initial content upon loading

Seeking solutions for loading an iframe using jQuery or Ajax and outputting the content to the page once it has been loaded. The challenge lies in loading an external page that may be slow or fail to load altogether, leading to undesired blank spaces on th ...

Using Javascript's Speech Recognition to activate a button

I am new to using JavaScript Speech Recognition and decided to work with the Annyang library. My goal is to automatically trigger the "show date" button when the user says 'hello', without actually clicking the button. However, I've been fac ...

Easily transform checkboxes into images using jQuery with no need for external plugins

Is it possible to replace checkboxes with images without using jQuery plugins? I'm hoping to achieve this in just a few lines of code. Thank you. ...

Ways to prevent mouse selection in an input field without disabling or making it read-only

Imagine this scenario: <input type="text"> The task at hand is to prevent text selection within the <input> field. ...

A guide to duplicating an image and placing multiple copies in various random locations

I'm trying to add multiple copies of an image to my webpage using create.js. I want each copy to be placed in a random position. I attempted to use the jQuery clone() method, but it didn't work as expected. function handleComplete(e) var _ob ...

Harness the power of ng-click in conjunction with data-ng-href for a

I am attempting to create a button that takes the user to the product details while also having the ability to increase a counter using an ng-click function. <div class="row center-block save-button" > <a data-ng-href="/savings/{{saving._id}} ...