Skip to content

Commit

Permalink
MapLibre support
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas committed Oct 20, 2021
1 parent 65c9767 commit aa730fd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
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'
end
end

if ENV["REACT_NATIVE_MAPBOX_GL_USE_FRAMEWORKS"]
Expand Down

0 comments on commit aa730fd

Please sign in to comment.