-
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
map.transformResponse #6976
Comments
Thanks for the suggestion @stevage. Tile responses happen on the Web Worker, and functions cannot be transferred to a worker, so unfortunately it can't be as simple as a function callback. Custom sources are our intended solution for this, and we aim to make them as convenient as possible within the constraints we have. Let's keep discussion on that issue. |
Thanks. Can you explain what you mean by "tile responses"? This wouldn't be per-tile, just once per source, right? |
Well, I meant to say "tile requests", but it also applies to GeoJSON requests -- both of those are made from the worker, and the expectation for a |
I'm running into this too. I'm using a semaphore to deal with the fact that the data may be ready before the map loads or after, but I agree it's clunky. |
I tend to use this pattern: map.onLoad = cb => map.loaded() ? cb () : map.on('load', cb);
d3.csv(...).then(rows => {
map.onLoad(() => map.addSource(rowsToSource(rows));
}); |
@stevage Thanks that much nicer! |
Motivation
It is a very common need to fetch data from somewhere then turn it into GeoJSON, before adding it into the map. Typically the source is either CSV or JSON.
Currently this has some downsides:
loaded()
andon('load')
event do not work as expected #6707)map.addSource('mydata', { type: 'geojson', source: 'http://example.com/not-yet-a-geo.json')
Design Alternatives
Custom Sources may solve this, but I suspect will be much more complicated. And they're not available yet, right? :)
Design
It's very simple and easy to understand for the user. It neatly parallels
transformRequest
.There might be some performance benefits? (The docs say that using GeoJSON via url is more efficient than fetching it yourself and calling
setData()
but I don't know why.)There is no direct connection between the source and the
transformResponse
function. If there were multiple different sources that required transformation, that function would start to get complex.I think there is some overlap with #5104 but I don't entirely understand that issue.
(Partly inspired by This SO question)
The text was updated successfully, but these errors were encountered: