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

Add support for pasting GeoJSON links #996

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

yushan-mu
Copy link
Contributor

fixes issue #992

src/mapml/utils/Util.js Outdated Show resolved Hide resolved
src/mapml/utils/Util.js Outdated Show resolved Hide resolved
try {
mapEl.geojson2mapml(JSON.parse(textContent));
} catch {
console.log('Invalid link!');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thIS error message should be more along the lines of "Error parsing GeoJSON from:" + URL . It can be hard to figure out what's gone wrong, but if we say what we were trying to do, sometimes it makes it a bit easier to understand.

mapEl.removeChild(mapEl.lastChild);
}
// garbage collect it
l = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is necessary, since the let for l scopes it to this block. It should get collected after the block closes.

@yushan-mu yushan-mu changed the title fix for issue #992 Add support for pasting GeoJSON links Oct 18, 2024
@AliyanH
Copy link
Member

AliyanH commented Nov 22, 2024

Hi @yushan-mu, I was playing with some data from the Region of Waterloo portal.

Layers that have the correct content type work great, i.e. https://hub.arcgis.com/api/v3/datasets/259750cc5e8c44f78c56d27ac28b04ed_16/downloads/data?format=geojson&spatialRefId=4326&where=1%3D1

but I noticed sometimes a file would have the incorrect content type but they would infact be a geojson file, i.e. the following 2 files were geojson files, but their content type was "application/octet-stream".

I pushed a commit to also look for file extensions, could you kindly review and add the necessary tests, i.e. content type that are not geojson/json but file extension is geojson/json.

@AliyanH AliyanH linked an issue Nov 22, 2024 that may be closed by this pull request
Copy link
Member

@AliyanH AliyanH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent test coverage @yushan-mu!

Just a few observations:

  • Please also add test coverage for the map.test.js file as you did for mapml-viewer.test.js
  • I like how you navigated server.js with the 2 geojson files, it would be good to provide meaningful names to the files so its easier for us to work with them in the future, it might be better if you rename items.json -> geojsonPoints.json and map.json -> geojsonPolygon.json
  • I noticed items.json has a lot of properties, might be worth it to remove them to make the json file smaller and easier to use in the future.

Great work!

Copy link
Member

@prushforth prushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! Thanks! Merge when ready!

Edited description, strict equality, and test timeouts

allow pasting of links ending in json or geojson which may have different content type

Added tests for files with (geo)json extensions

Cleaned up and synched tests
@yushan-mu yushan-mu merged commit ccf7b1f into Maps4HTML:main Dec 6, 2024
1 check passed
@yushan-mu yushan-mu deleted the cleaned-issue-992 branch December 6, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Link to GeoJSON resource should not give a parser error
3 participants