Skip to content

Commit

Permalink
feat: deprecate old ROKAS map styles and replace with new map styles
Browse files Browse the repository at this point in the history
* feat: replace styles and add more tests to SBBRokasMapStyler
* docs: change main img with new styles

base_bright_v2_ki_v2 => journey_maps_bright_v1
base_dark_v2_ki_v2 => journey_maps_dark_v1
aerial_sbb_ki_v2 => journey_maps_aerial_v1
  • Loading branch information
smallTrogdor authored Nov 27, 2024
1 parent 3833568 commit 08e7f7a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 44 deletions.
Binary file modified example/gallery/main.webp
Binary file not shown.
28 changes: 14 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -405,26 +405,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.5"
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "3.0.5"
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "2.0.1"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -485,18 +485,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.15.0"
version: "1.11.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -681,10 +681,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.6.1"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -721,10 +721,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "14.2.5"
version: "13.0.0"
watcher:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/sbb_map_style/sbb_map_styler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class SBBMapStyler with ChangeNotifier {

/// Toggles between the dark and bright mode of [currentStyle].
///
/// Some [SBBMapStyle]s do not support dark mode (e.g. `aerial_sbb_ki_v2`).
/// Some [SBBMapStyle]s do not support dark mode (e.g. `journey_maps_aerial_v1`).
/// In that case, there will be no visual change in the map.
/// The [SBBMapStyler] however will be in dark mode, meaning [switchStyle] will
/// switch to the dark mode of the style.
Expand Down
48 changes: 24 additions & 24 deletions lib/src/sbb_map_style/sbb_rokas_map_styler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ import 'package:sbb_maps_flutter/src/sbb_map_style/api_key_missing_exception.dar
///
/// The base styles are:
///
/// * `base_bright_v2_ki_v2`
/// * `base_dark_v2_ki_v2`
/// * `aerial_sbb_ki_v2`
/// * `journey_maps_bright_v1`
/// * `journey_maps_dark_v1`
/// * `journey_maps_aerial_v1`
///
/// The [initialStyleId] is `base_bright_v2_ki_v2`.
/// 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 const _baseBrightV2KIV2 = 'base_bright_v2_ki_v2';
static const _baseDarkV2KIV2 = 'base_dark_v2_ki_v2';
static const _aerialSBBKIV2 = 'aerial_sbb_ki_v2';
static const _brightV1 = 'journey_maps_bright_v1';
static const _darkV1 = 'journey_maps_dark_v1';
static const _aerialV1 = 'journey_maps_aerial_v1';

const SBBRokasMapStyler._();

/// Creates a ROKAS [SBBMapStyler] with all styles.
///
/// The styles are:
///
/// * `base_bright_v2_ki_v2`
/// * `base_dark_v2_ki_v2`
/// * `aerial_sbb_ki_v2`
/// * `journey_maps_bright_v1`
/// * `journey_maps_dark_v1`
/// * `journey_maps_aerial_v1`
///
/// The ROKAS styles need an API key for the Journey Maps Tiles API.
///
Expand All @@ -36,27 +36,27 @@ class SBBRokasMapStyler {
///
/// Throws an [ApiKeyMissing] exception **during runtime** if neither is given.
///
/// The [initialStyleId] is `base_bright_v2_ki_v2`.
/// The [initialStyleId] is `journey_maps_bright_v1`.
static SBBMapStyler full({String? apiKey, bool isDarkMode = false}) {
final key = _apiKeyElseThrow(apiKey);

final rokasDefaultStyle = SBBMapStyle.fromURL(
id: _baseBrightV2KIV2,
brightStyleURL: _rokasStyleUrl(_baseBrightV2KIV2),
id: _brightV1,
brightStyleURL: _rokasStyleUrl(_brightV1),
apiKey: key,
darkStyleURL: _rokasStyleUrl(_baseDarkV2KIV2),
darkStyleURL: _rokasStyleUrl(_darkV1),
);

final aerialStyle = SBBMapStyle.fromURL(
id: _aerialSBBKIV2,
brightStyleURL: _rokasStyleUrl(_aerialSBBKIV2),
id: _aerialV1,
brightStyleURL: _rokasStyleUrl(_aerialV1),
apiKey: key,
);

return SBBCustomMapStyler(
styles: [rokasDefaultStyle],
aerialStyle: aerialStyle,
initialStyleId: _baseBrightV2KIV2,
initialStyleId: _brightV1,
isDarkMode: isDarkMode,
);
}
Expand All @@ -65,8 +65,8 @@ class SBBRokasMapStyler {
///
/// The styles are:
///
/// * `base_bright_v2_ki_v2`
/// * `base_dark_v2_ki_v2`
/// * `journey_maps_bright_v1`
/// * `journey_maps_dark_v1`
///
/// The ROKAS styles need an API key for the Journey Maps Tiles API.
///
Expand All @@ -76,20 +76,20 @@ class SBBRokasMapStyler {
///
/// Throws an [ApiKeyMissing] exception **during runtime** if neither is given.
///
/// The [initialStyleId] is `base_bright_v2_ki_v2`.
/// The [initialStyleId] is `journey_maps_bright_v1`.
static SBBMapStyler noAerial({String? apiKey, bool isDarkMode = false}) {
String key = _apiKeyElseThrow(apiKey);

final rokasDefaultStyle = SBBMapStyle.fromURL(
id: _baseBrightV2KIV2,
brightStyleURL: _rokasStyleUrl(_baseBrightV2KIV2),
id: _brightV1,
brightStyleURL: _rokasStyleUrl(_brightV1),
apiKey: key,
darkStyleURL: _rokasStyleUrl(_baseDarkV2KIV2),
darkStyleURL: _rokasStyleUrl(_darkV1),
);

return SBBCustomMapStyler(
styles: [rokasDefaultStyle],
initialStyleId: _baseBrightV2KIV2,
initialStyleId: _brightV1,
isDarkMode: isDarkMode,
);
}
Expand Down
31 changes: 27 additions & 4 deletions test/src/sbb_map_style/sbb_rokas_map_styler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ import 'package:sbb_maps_flutter/sbb_maps_flutter.dart';
import 'package:test/test.dart';

void main() {
group('Unit Test SBBCustomMapStyler', () {
group('Unit Test SBBRokasMapStyler', () {
group('initalization', () {
test('full should return custom map styler with all styles', () {
test('whenFull_shouldReturnCustomMapStylerWithAllStyleIds', () {
// act
final actual = SBBRokasMapStyler.full(apiKey: 'key');

// expect
expect(actual, isA<SBBCustomMapStyler>());
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');

Expand All @@ -13,13 +23,26 @@ void main() {
expect(actual.isDarkMode, equals(false));
});

test('aerial should return custom map styler without aerial', () {
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<SBBCustomMapStyler>());
expect(actual.currentStyleURI, equals(expectedUri));
});

test('whenNoAerial_shouldNotHaveAerial', () {
// act
final actual = SBBRokasMapStyler.noAerial(apiKey: 'key');

// expect
expect(actual, isA<SBBCustomMapStyler>());
expect(actual.getStyleIds().contains('aerial_sbb_ki_v2'), equals(false));
expect(actual.getStyleIds().contains('journey_maps_aerial_v1'), equals(false));
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion tool/sprite_2_dart/bin/sprite_2_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
const rokasStyles = ['aerial_sbb_ki_v2', 'base_dark_v2_ki_v2', 'base_bright_v2_ki_v2'];
const rokasStyles = ['journey_maps_aerial_v1', 'journey_maps_dark_v1', 'journey_maps_bright_v1'];

final allIcons = <String, String>{};
final allIconKeys = <String, Set<String>>{};
Expand Down

0 comments on commit 08e7f7a

Please sign in to comment.