-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
better documentation / examples around loading GeoJSON by URL #1505
Comments
Do you have an example of a URL reference to a local file? This does not work:
}); However when I replace the "file:///testjson.json" with the JSON object it works fine...; so the reference does not work. |
@musicformellons Try with an |
Probably my lack of experience but I do not get it working with http:// or https:// using a local geojson file. Any guidance with more detail would be very helpful. As I am working in Django should I make a specifice URL for the geojson file in url.py or something? |
Wouldn't you just link to it the same way as any other static asset, like an image or stylesheet? |
Yes, thanks. I did this (and put the json in the static folder) and now works fine and indeed much faster with large json files: |
We've had some documentation pushing users towards URLs over literals for a while. Just pushed an example that uses a URL in 2535846. |
I think the documentation is incorrect. It's missing Should be: map.addSource('some id', {
type: 'geojson',
data: 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_ports.geojson'
}); |
Thanks @peeinears! This mistake must've been introduced as we moved from the |
I recognize this thread is quite old but I'm having some trouble loading GeoJSON using a url. I've loaded a file onto AWS S3 and distributed it using CloudFront so that it's accessible at d36v8m4hidy252.cloudfront.net/test.json, however I cannot get any coordinates to populate. Can anyone offer me help? |
I get a similar issue.I have my geojson file in the same project folder and for some reason it is unable to load it. However if i copy paste the entire geojson file in the source field instead of the static url it works: Error Stack:
|
@gautamc1106 you could try to un-inline your source, using |
I tried that too. Does not make a difference |
having same issue as @amauriciorr .. I cannot display raw geojson from URL hosted on AWS. The AWS object is public, the bucket has CORS configured to '*' and I am using http-server with cors on:
a working example would be really helpful in the docs for this (and other similar) use cases. |
"GeoJSON layers are slow" is a common complaint and the best solution is to use a URL for the
data
option rather than inline GeoJSON. This option is documented in https://www.mapbox.com/mapbox-gl-js/api/#geojsonsource, but we should make examples that demonstrate it and emphasize that it's the preferred way.The text was updated successfully, but these errors were encountered: