diff --git a/lib/src/sbb_map_style/sbb_rokas_map_styler.dart b/lib/src/sbb_map_style/sbb_rokas_map_styler.dart index 673f34d..0e7dff5 100644 --- a/lib/src/sbb_map_style/sbb_rokas_map_styler.dart +++ b/lib/src/sbb_map_style/sbb_rokas_map_styler.dart @@ -12,7 +12,10 @@ import 'package:sbb_maps_flutter/src/sbb_map_style/api_key_missing_exception.dar /// /// The [initialStyleId] is `journey_maps_bright_v1`. class SBBRokasMapStyler { - static _rokasStyleUrl(String styleId) => 'https://journey-maps-tiles.geocdn.sbb.ch/styles/$styleId/style.json'; + static _rokasProdStyleUrl(String styleId) => 'https://journey-maps-tiles.geocdn.sbb.ch/styles/$styleId/style.json'; + static _rokasIntStyleUrl(String styleId) => 'https://journey-maps-tiles.geocdn-int.sbb.ch/styles/$styleId/style.json'; + + static _rokasStyleUrl(String style, {isInt = false}) => isInt ? _rokasIntStyleUrl(style) : _rokasProdStyleUrl(style); static const _brightV1 = 'journey_maps_bright_v1'; static const _darkV1 = 'journey_maps_dark_v1'; @@ -36,20 +39,30 @@ class SBBRokasMapStyler { /// /// Throws an [ApiKeyMissing] exception **during runtime** if neither is given. /// + /// To use integration data for vector tiles and POIs, set + /// [useIntegrationData] to true. + /// /// The [initialStyleId] is `journey_maps_bright_v1`. - static SBBMapStyler full({String? apiKey, bool isDarkMode = false}) { + static SBBMapStyler full({ + String? apiKey, + bool isDarkMode = false, + bool useIntegrationData = false, + }) { final key = _apiKeyElseThrow(apiKey); + final isInt = useIntegrationData || _intEnvVarSet(); + _logIfIsInt(isInt); + final rokasDefaultStyle = SBBMapStyle.fromURL( id: _brightV1, - brightStyleURL: _rokasStyleUrl(_brightV1), + brightStyleURL: _rokasStyleUrl(_brightV1, isInt: isInt), apiKey: key, - darkStyleURL: _rokasStyleUrl(_darkV1), + darkStyleURL: _rokasStyleUrl(_darkV1, isInt: isInt), ); final aerialStyle = SBBMapStyle.fromURL( id: _aerialV1, - brightStyleURL: _rokasStyleUrl(_aerialV1), + brightStyleURL: _rokasStyleUrl(_aerialV1, isInt: isInt), apiKey: key, ); @@ -76,15 +89,25 @@ class SBBRokasMapStyler { /// /// Throws an [ApiKeyMissing] exception **during runtime** if neither is given. /// + /// To use integration data for vector tiles and POIs, set + /// [useIntegrationData] to true. + /// /// The [initialStyleId] is `journey_maps_bright_v1`. - static SBBMapStyler noAerial({String? apiKey, bool isDarkMode = false}) { + static SBBMapStyler noAerial({ + String? apiKey, + bool isDarkMode = false, + bool useIntegrationData = false, + }) { String key = _apiKeyElseThrow(apiKey); + final isInt = useIntegrationData || _intEnvVarSet(); + _logIfIsInt(isInt); + final rokasDefaultStyle = SBBMapStyle.fromURL( id: _brightV1, - brightStyleURL: _rokasStyleUrl(_brightV1), + brightStyleURL: _rokasStyleUrl(_brightV1, isInt: isInt), apiKey: key, - darkStyleURL: _rokasStyleUrl(_darkV1), + darkStyleURL: _rokasStyleUrl(_darkV1, isInt: isInt), ); return SBBCustomMapStyler( @@ -118,4 +141,17 @@ class SBBRokasMapStyler { } return legacyKey; } + + static bool _intEnvVarSet() { + const intFlag = String.fromEnvironment('SBB_MAPS_INT_ENABLED'); + if (intFlag.isNotEmpty) return intFlag == 'true'; + + return false; + } + + static void _logIfIsInt(bool isInt) { + if (!isInt) return; + final logger = Logger(); + logger.i('sbb_maps_flutter: You are currently opted in to use integration data.'); + } } diff --git a/test/src/sbb_map_style/sbb_rokas_map_styler_test.dart b/test/src/sbb_map_style/sbb_rokas_map_styler_test.dart index c71ee1f..15f889b 100644 --- a/test/src/sbb_map_style/sbb_rokas_map_styler_test.dart +++ b/test/src/sbb_map_style/sbb_rokas_map_styler_test.dart @@ -1,49 +1,67 @@ import 'package:sbb_maps_flutter/sbb_maps_flutter.dart'; +import 'package:sbb_maps_flutter/src/sbb_map_style/api_key_missing_exception.dart'; +import 'package:test/expect.dart'; import 'package:test/test.dart'; void main() { group('Unit Test SBBRokasMapStyler', () { - group('initalization', () { - test('whenFull_shouldReturnCustomMapStylerWithAllStyleIds', () { - // act - final actual = SBBRokasMapStyler.full(apiKey: 'key'); - - // expect - expect(actual, isA()); - expect(actual.getStyleIds().contains('journey_maps_aerial_v1'), equals(true)); - expect(actual.getStyleIds().contains('journey_maps_bright_v1'), equals(true)); - }); - - test('whenFull_shouldReturnInBrightMode', () { - // act - final actual = SBBRokasMapStyler.full(apiKey: 'key'); - - // expect - expect(actual, isA()); - expect(actual.isDarkMode, equals(false)); - }); - - test('whenFull_shouldReturnStyleUriInBrightMode', () { - // arrange - const expectedUri = 'https://journey-maps-tiles.geocdn.sbb.ch' - '/styles/journey_maps_bright_v1/style.json?api_key=key'; - - // act - final actual = SBBRokasMapStyler.full(apiKey: 'key'); - - // expect - expect(actual, isA()); - expect(actual.currentStyleURI, equals(expectedUri)); - }); - - test('whenNoAerial_shouldNotHaveAerial', () { - // act - final actual = SBBRokasMapStyler.noAerial(apiKey: 'key'); - - // expect - expect(actual, isA()); - expect(actual.getStyleIds().contains('journey_maps_aerial_v1'), equals(false)); - }); + test('whenFull_shouldReturnCustomMapStylerWithAllStyleIds', () { + // act + final actual = SBBRokasMapStyler.full(apiKey: 'key'); + + // expect + expect(actual, isA()); + expect(actual.getStyleIds().contains('journey_maps_aerial_v1'), equals(true)); + expect(actual.getStyleIds().contains('journey_maps_bright_v1'), equals(true)); + }); + + test('whenFull_shouldReturnInBrightMode', () { + // act + final actual = SBBRokasMapStyler.full(apiKey: 'key'); + + // expect + expect(actual, isA()); + expect(actual.isDarkMode, equals(false)); + }); + + test('whenFull_shouldReturnStyleUriInBrightMode', () { + // arrange + const expectedUri = 'https://journey-maps-tiles.geocdn.sbb.ch' + '/styles/journey_maps_bright_v1/style.json?api_key=key'; + + // act + final actual = SBBRokasMapStyler.full(apiKey: 'key'); + + // expect + expect(actual, isA()); + expect(actual.currentStyleURI, equals(expectedUri)); + }); + + test('whenNoAerial_shouldNotHaveAerial', () { + // act + final actual = SBBRokasMapStyler.noAerial(apiKey: 'key'); + + // expect + expect(actual, isA()); + expect(actual.getStyleIds().contains('journey_maps_aerial_v1'), equals(false)); + }); + + test('whenNoApiKey_shouldThrowApiKeyMissingException', () { + // act + expect + expect(() => SBBRokasMapStyler.full(), throwsA(const TypeMatcher())); + }); + + test('whenUseIntegrationDataIsTrue_uriShouldBeIntPointing', () { + // arrange + const expectedUri = 'https://journey-maps-tiles.geocdn-int.sbb.ch' + '/styles/journey_maps_bright_v1/style.json?api_key=key'; + + // act + final actual = SBBRokasMapStyler.full(apiKey: 'key', useIntegrationData: true); + + // expect + expect(actual, isA()); + expect(actual.currentStyleURI, equals(expectedUri)); }); }); }