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

Bug when loading the Map with specific geojson #1493

Closed
luanrjjj opened this issue Apr 26, 2024 · 14 comments
Closed

Bug when loading the Map with specific geojson #1493

luanrjjj opened this issue Apr 26, 2024 · 14 comments

Comments

@luanrjjj
Copy link

When attempting to load a map using a specific GeoJSON file representing the states of Brazil, I encounter a situation where sometimes I face the following issue:
image

I have researched this problem, and typically, the issues reported here or on StackOverflow are related to the direction of GeoJSON coordinates. However, in my case, the loading process occurs normally. Despite this, even after a successful reload, a state may still break during subsequent reload attempts. I am using React with amCharts 5.

@martynasma
Copy link
Collaborator

Do you mean that exactly same GeoJSON sometimes produces proper map and sometimes this square?

Would you be able to post this as a runnable demo, e.g. on CodePen?

@luanrjjj
Copy link
Author

Yes, Exactly. I'm going to do this CodePen in the next week and put the link here.

@luanrjjj
Copy link
Author

luanrjjj commented May 3, 2024

So, I created a example in the following repository :
https://gitlab.com/alfredofreitas/amcharts-map-test-debug/

It's a simple nextjs project with only 1 page, the dashboard page. So, to test the app you need only enter in localhost:3000/dashboard

To install the package is necessary npm install and after to run npm run dev.

If the necessary I can deploy the project also to the vercel.

It was possible to reproduce the bug when I change the select state, as is possible to see in following picture:

image

The geojson is in the maps_counties folder

@martynasma
Copy link
Collaborator

Can you post just the GeoJSON? I don't have a GitLab account and they are making me jump through all these hoops just to access a repo.

@luanrjjj
Copy link
Author

luanrjjj commented May 3, 2024

Here a json used in the example
geojs-29-mun.json

@luanrjjj
Copy link
Author

luanrjjj commented May 3, 2024

If you want I can put in the github also.

@luanrjjj
Copy link
Author

luanrjjj commented May 3, 2024

The first load is fine, the problem is when I change the map based in a react state condition. The information is charged in the map but the image break

@luanrjjj
Copy link
Author

luanrjjj commented May 3, 2024

@martynasma
Copy link
Collaborator

Getting this:

image

@luanrjjj
Copy link
Author

luanrjjj commented May 7, 2024

You need enter in /dashboard path. http://localhost:3000/dashboard

@martynasma
Copy link
Collaborator

I think I know what's going on.

When you use reverseGeodata: true setting it mutates the source GeoJSON by modifying the order of coordinates in it.

If you set geoJSON with the same (mutated) object again, it reverses coordinates again, thus creating visual anomaly.

The solution would be to always create a shallow copy of the GeoJSON you set:

geoJSON: JSON.parse(JSON.stringify(object))

@luanrjjj
Copy link
Author

luanrjjj commented May 10, 2024

I did some testes here. It's better, but still unstable: the reload is broken with a probability around 30% - 50%. Do you have some other tip?

@martynasma
Copy link
Collaborator

I can't seem to be able to reproduce this outside of your specific app.

Here's a very basic repro case using your GeoJSON:
https://codepen.io/team/amcharts/pen/wvbvYNa/112f2ef728e40bf60ea92ee32ed9af7c?editors=0010

Technically, shallow-copying GeoJSON should be enough, as per above demo.

Copy link

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.

@github-actions github-actions bot added the stale label Jun 13, 2024
@zeroin zeroin closed this as completed Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants