layers.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import "package:flutter/material.dart";
  2. import "package:flutter_map/flutter_map.dart";
  3. import "package:photos/generated/l10n.dart";
  4. import "package:photos/theme/ente_theme.dart";
  5. import "package:photos/ui/map/tile/attribution/map_attribution.dart";
  6. import "package:photos/ui/map/tile/cache.dart";
  7. import "package:url_launcher/url_launcher.dart";
  8. import "package:url_launcher/url_launcher_string.dart";
  9. const String _userAgent = "io.ente.photos";
  10. class MapAttributionOptions {
  11. final double permanentHeight;
  12. final BorderRadius popupBorderRadius;
  13. final double iconSize;
  14. const MapAttributionOptions({
  15. this.permanentHeight = 24,
  16. this.popupBorderRadius = const BorderRadius.all(Radius.circular(12)),
  17. this.iconSize = 20,
  18. });
  19. }
  20. class OSMTileLayer extends StatelessWidget {
  21. const OSMTileLayer({super.key});
  22. @override
  23. Widget build(BuildContext context) {
  24. return TileLayer(
  25. urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
  26. subdomains: const ['a', 'b', 'c'],
  27. backgroundColor: Colors.transparent,
  28. userAgentPackageName: _userAgent,
  29. tileProvider: CachedNetworkTileProvider(),
  30. );
  31. }
  32. }
  33. class OSMFranceTileLayer extends StatelessWidget {
  34. const OSMFranceTileLayer({super.key});
  35. @override
  36. Widget build(BuildContext context) {
  37. return TileLayer(
  38. urlTemplate: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
  39. fallbackUrl: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
  40. subdomains: const ['a', 'b', 'c'],
  41. tileProvider: CachedNetworkTileProvider(),
  42. backgroundColor: const Color.fromARGB(255, 246, 246, 246),
  43. userAgentPackageName: _userAgent,
  44. panBuffer: 1,
  45. );
  46. }
  47. }
  48. class OSMFranceTileAttributes extends StatelessWidget {
  49. final MapAttributionOptions options;
  50. const OSMFranceTileAttributes({
  51. this.options = const MapAttributionOptions(),
  52. super.key,
  53. });
  54. @override
  55. Widget build(BuildContext context) {
  56. final textTheme = getEnteTextTheme(context).tinyBold;
  57. return MapAttributionWidget(
  58. alignment: AttributionAlignment.bottomLeft,
  59. showFlutterMapAttribution: false,
  60. permanentHeight: options.permanentHeight,
  61. popupBackgroundColor: getEnteColorScheme(context).backgroundElevated,
  62. popupBorderRadius: options.popupBorderRadius,
  63. iconSize: options.iconSize,
  64. attributions: [
  65. TextSourceAttribution(
  66. S.of(context).openstreetmapContributors,
  67. textStyle: textTheme,
  68. onTap: () => launchUrlString('https://openstreetmap.org/copyright'),
  69. ),
  70. TextSourceAttribution(
  71. 'HOT Tiles',
  72. textStyle: textTheme,
  73. onTap: () => launchUrl(Uri.parse('https://www.hotosm.org/')),
  74. ),
  75. TextSourceAttribution(
  76. S.of(context).hostedAtOsmFrance,
  77. textStyle: textTheme,
  78. onTap: () => launchUrl(Uri.parse('https://www.openstreetmap.fr/')),
  79. ),
  80. ],
  81. );
  82. }
  83. }
  84. class MapBoxTilesLayer extends StatelessWidget {
  85. const MapBoxTilesLayer({super.key});
  86. @override
  87. Widget build(BuildContext context) {
  88. return TileLayer(
  89. urlTemplate:
  90. "https://api.mapbox.com/styles/v1/{mb_user}/{mb_style_id}/tiles/{z}/{x}/{y}?access_token={mb_token}",
  91. fallbackUrl: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
  92. subdomains: const ['a', 'b', 'c'],
  93. backgroundColor: Colors.transparent,
  94. userAgentPackageName: _userAgent,
  95. tileProvider: CachedNetworkTileProvider(),
  96. additionalOptions: const {
  97. "mb_token": String.fromEnvironment("mb_token"),
  98. "mb_style_id": String.fromEnvironment("mb_style_id"),
  99. "mb_user": String.fromEnvironment("mb_user"),
  100. },
  101. );
  102. }
  103. }