maplibre / flutter-maplibre-gl

Customizable, performant and vendor-free vector and raster maps, flutter wrapper for maplibre-native and maplibre-gl-js (fork of flutter-mapbox-gl/maps)
https://pub.dev/packages/maplibre_gl
Other
224 stars 124 forks source link

Transforming requests #158

Open noorbakerally opened 2 years ago

noorbakerally commented 2 years ago

In the JavaScript Maplibre, it is possible to transforms request as described here, and shown below. Do we have this feature in this library?

// use transformRequest to modify requests that begin with `http://myHost`
transformRequest: function(url, resourceType) {
if (resourceType === 'Source' && url.indexOf('http://myHost') > -1) {
return {
url: url.replace('http', 'https'),
headers: { 'my-custom-header': true },
credentials: 'include'  // Include cookies for cross-origin requests
}
}
}
m0nac0 commented 2 years ago

Unfortunately that is not supported, yet.

noorbakerally commented 1 year ago

Any advice about which files to modify to implement this functionality?

m0nac0 commented 1 year ago

@noorbakerally Ideally, you should first research if this is possible also in the Android/iOS Maplibre libraries. Since this is a cross-platform library, we should strive to implement new features on all 3 supported platforms. However, if you only feel comfortable implementing this for web, you could also contribute that and we see if someone else can implement it for the other platforms.

For web specifically, you would probably have to pass a transformRequest to MapOptions here https://github.com/m0nac0/flutter-maplibre-gl/blob/c723434d635068157311eb47c26df3e0554ff894/maplibre_gl_web/lib/src/mapbox_web_gl_platform.dart#L69 You can look at the other parameters to see how they are being passed down within the library.

Regarding the transformRequest, I recommend you to look at the source code/docs of maplibre-gl-dart (or mapbox-gl-dart, where maplibre-gl-dart was forked from). The relevant docs from mapbox-gl-dart are here: https://pub.dev/documentation/mapbox_gl_dart/latest/mapboxgl/MapOptions/transformRequest.html I'm not sure, though, how easy it would be to pass a dart function in there. You might to experiment a bit with the Dart-JS interop...

noorbakerally commented 1 year ago

@m0nac0 thanks for the advise, let me check that, we are building something quite complex with this library in flutter, so far, it has been great, only this bit is required now

berkayoruc commented 1 year ago

@noorbakerally do you find any solution

noorbakerally commented 1 year ago

@berkayoruc unfortunately no, we had to change much in our project to adapt, but the issue isn't with the Flutter library, the native libraries works differently

m0nac0 commented 1 year ago

If you are looking to add custom headers to your requests, you can try the setHttpHeaders method (a global level at the library level).

l2-flutter-dev commented 6 months ago

Any updates here? I'm looking to add Authorization headers to my requests, but it seems setHttpHeaders doesn't work for updating headers throughout the lifecycle of the app.

From Mapbox documentation it seems any further changes to sessionConfiguration via setHttpHeaders doesn't affect the current session: https://github.com/mapbox/mapbox-gl-native-ios/blob/c8917ac1ea2f9f45e9a5a0e3376314160d64d5f3/platform/darwin/src/MGLNetworkConfiguration.h#L58-L60