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

Is it possible to override "getArrayBuffer" for offline usage/fallback? #812

Closed
fnicollet opened this issue Nov 6, 2014 · 2 comments
Closed

Comments

@fnicollet
Copy link
Contributor

Hello,

This is more of a question than an issue. I would like to have a fallback on local PBF files while offline, so basically instead of retrieving them via HTTP, override the behaviour and load a file from my hard drive. I can do this very easily in leaflet classic TMS layers with some code like:

L.TileLayer.Common = L.TileLayer.extend({
    getTileUrl: function (tilePoint, tile) {
    ... do something clever
    }
});

Works very well and I am very happy with that behaviour that allows me to override leaflet function without having to modify leaflet's core.
I would like to do the same with mapbox-gl-js but it seems like the way it is architectured makes it hard to override functions/behaviours because you can only see what's exported publicly, not the inside functions.

I found the part of the code that I need to override:

WorkerTile.loading[source][id] = getArrayBuffer(url, function(err, data) {

Which calls "getArrayBuffer", which have been initialized as a local variable with

var getArrayBuffer = require('../util/ajax').getArrayBuffer;

From the outside, here is what the debugger can see:
image

Very little, only main objects and their prototype. I could modify util.getArrayBuffer but it is too late because Worker already "copied" it locally.

I am not so used to "require" and how it works but it looks like you can't access what's outside of the exports, so I can't "hack" very far.
Only solution I see is to modify the source code for getArrayBuffer and recompile my own version of mapbox-gl-js but i would rather not do that.

If there is some JS wizardry that would allow me to do it, i would be very interested :)

Thanks!

@jfirebaugh
Copy link
Contributor

I think your best bet is to set the source URL to either a remote URL or file:// URL depending on offline status. We'll keep the offline use case in mind but allowing access to private implementation details of gl-js isn't something we're likely to do.

@fnicollet
Copy link
Contributor Author

Thanks for the clarification :)

Fabien

@lucaswoj lucaswoj mentioned this issue Feb 28, 2017
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

No branches or pull requests

2 participants