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

MapLibre support #1571

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if useMapLibre
},
product_name: "Mapbox"
}
$RNMGL_USE_MAPLIBRE = true
end

# We ingore warning except for RNMBGL
Expand Down
18 changes: 18 additions & 0 deletions ios/RCTMGL/MGLModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ + (BOOL)requiresMainQueueSetup
{
// style urls
NSMutableDictionary *styleURLS = [[NSMutableDictionary alloc] init];

#ifdef RNMGL_USE_MAPLIBRE
for (MGLDefaultStyle* style in [MGLStyle predefinedStyles]) {
[styleURLS setObject:[style.url absoluteString] forKey:style.name];
}
[styleURLS setObject:[[MGLStyle defaultStyleURL] absoluteString] forKey:@"Default"];
#else
[styleURLS setObject:[MGLStyle.streetsStyleURL absoluteString] forKey:@"Street"];
[styleURLS setObject:[MGLStyle.darkStyleURL absoluteString] forKey:@"Dark"];
[styleURLS setObject:[MGLStyle.lightStyleURL absoluteString] forKey:@"Light"];
[styleURLS setObject:[MGLStyle.outdoorsStyleURL absoluteString] forKey:@"Outdoors"];
[styleURLS setObject:[MGLStyle.satelliteStyleURL absoluteString] forKey:@"Satellite"];
[styleURLS setObject:[MGLStyle.satelliteStreetsStyleURL absoluteString] forKey:@"SatelliteStreet"];
#endif

// event types
NSMutableDictionary *eventTypes = [[NSMutableDictionary alloc] init];
Expand Down Expand Up @@ -240,7 +248,13 @@ + (BOOL)requiresMainQueueSetup

RCT_EXPORT_METHOD(setAccessToken:(NSString *)accessToken)
{
#ifdef RNMGL_USE_MAPLIBRE
if (accessToken.length > 0) {
[MGLSettings setApiKey:accessToken];
}
#else
[MGLAccountManager setAccessToken:accessToken];
#endif
}

RCT_EXPORT_METHOD(addCustomHeader:(NSString *)headerName forHeaderValue:(NSString *) headerValue)
Expand All @@ -255,7 +269,11 @@ + (BOOL)requiresMainQueueSetup

RCT_EXPORT_METHOD(getAccessToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef RNMGL_USE_MAPLIBRE
NSString* accessToken = MGLSettings.apiKey;
#else
NSString *accessToken = MGLAccountManager.accessToken;
#endif

if (accessToken != nil) {
resolve(accessToken);
Expand Down
3 changes: 3 additions & 0 deletions ios/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ If you want to use that, simply add this to your `ios/Podfile`

```ruby
$RNMBGL_Use_SPM = true
$RNMGL_USE_MAPLIBRE = true
```

If you want to adjust/ edit your MapLibre version you can also pass a hash
Expand All @@ -87,8 +88,10 @@ $RNMBGL_Use_SPM = {
},
product_name: "Mapbox"
}
$RNMGL_USE_MAPLIBRE = true
```


<br>

## React-Native < `0.60.0`
Expand Down
3 changes: 3 additions & 0 deletions react-native-mapbox-gl.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ Pod::Spec.new do |s|

s.subspec 'DynamicLibrary' do |sp|
sp.source_files = "ios/RCTMGL/**/*.{h,m}"
if $RNMGL_USE_MAPLIBRE
sp.compiler_flags = '-DRNMGL_USE_MAPLIBRE=1'
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain how this is relevant?
Haven't seen this come up again in your changes - does MapLibre require this somehow?

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It defines RNMGL_USE_MAPLIBRE preprocessor macro, so we can do #ifdef RNMGL_USE_MAPLIBRE in code

end
end

if ENV["REACT_NATIVE_MAPBOX_GL_USE_FRAMEWORKS"]
Expand Down