Add the region map, permanent attribution and the Sources screen
Puts a MapLibre map on screen framed on the region, with the credit obligations that come with showing third-party data satisfied structurally rather than by remembering to add a label. The base map style comes from MAP_STYLE_URL, and with no key configured the app generates a fallback style from the region's own bounding box: a flat background and the extent outline, no network sources at all. That keeps a fresh clone runnable offline without pulling in a boundary dataset that would carry its own licence, and it deliberately looks like a placeholder so it is not mistaken for a finished map. Attribution is driven by what is actually rendered. The bar lists the credits for the active sources only, because crediting OpenStreetMap while showing the fallback style would be a false attribution, and it says plainly when no base map is configured. It sits below the map rather than floating over it so no map control or gesture overlay can occlude a credit that the ODbL and CC BY-SA terms require to be visible. The Sources screen leads with the independence disclaimer, before the sources it qualifies, so a reader who stops after the first screenful has still seen it. Sources with no stated licence — ARPA publishes none for the alert bulletin — say so explicitly rather than being shown bare or given an invented one. A separate note explains that the rendered radar frames inherit CC BY-SA from the DPC source data. Also declares the INTERNET permission in the main manifest: Flutter injects it into the debug and profile manifests only, so a release build would otherwise fail every request on device. Verified: analyze clean, 66 tests passing, appbundle builds with the native MapLibre plugin. Not verified visually — this machine has no Android device or emulator image, so nobody has watched the map render. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../core/config/env.dart';
|
||||
import '../../core/region/region_config.dart';
|
||||
|
||||
/// Which base map the app is showing, and therefore which credits are owed.
|
||||
enum BaseMapKind {
|
||||
/// A real vector base map from [Env.mapStyleUrl]. Carries OpenStreetMap data,
|
||||
/// so the ODbL credit is mandatory.
|
||||
configured,
|
||||
|
||||
/// The bundled fallback: a flat background and the region outline, drawn from
|
||||
/// the region config. Contains no third-party map data, so crediting
|
||||
/// OpenStreetMap here would be a false attribution.
|
||||
offlineFallback,
|
||||
}
|
||||
|
||||
/// Resolves the MapLibre style the app should load.
|
||||
///
|
||||
/// With no `MAP_STYLE_URL` configured the app must still run — offline, in
|
||||
/// tests, and on a fresh clone with no credentials — so it falls back to a
|
||||
/// style generated from the region's own bounding box.
|
||||
class MapStyle {
|
||||
const MapStyle({required this.kind, required this.styleString});
|
||||
|
||||
factory MapStyle.forRegion(RegionConfig region) {
|
||||
if (Env.hasMapStyle) {
|
||||
return MapStyle(
|
||||
kind: BaseMapKind.configured,
|
||||
styleString: Env.mapStyleUrl,
|
||||
);
|
||||
}
|
||||
return MapStyle(
|
||||
kind: BaseMapKind.offlineFallback,
|
||||
styleString: buildFallbackStyle(region),
|
||||
);
|
||||
}
|
||||
|
||||
final BaseMapKind kind;
|
||||
|
||||
/// Either a style URL or an inline MapLibre style document; the map widget
|
||||
/// accepts both.
|
||||
final String styleString;
|
||||
|
||||
/// Attribution ids owed by the base map itself, as they appear in the region
|
||||
/// config. The radar and forecast layers add their own on top of these.
|
||||
Set<String> get attributionIds => switch (kind) {
|
||||
BaseMapKind.configured => const <String>{'osm'},
|
||||
BaseMapKind.offlineFallback => const <String>{},
|
||||
};
|
||||
|
||||
/// Builds a self-contained MapLibre style: a flat background plus the region
|
||||
/// bounding box, with no network sources at all.
|
||||
///
|
||||
/// The outline is deliberately the *bounding box*, not the administrative
|
||||
/// boundary. A real boundary would need a third-party dataset with its own
|
||||
/// licence, and would make the fallback look like a finished map when it is
|
||||
/// a placeholder.
|
||||
static String buildFallbackStyle(RegionConfig region) {
|
||||
final b = region.bounds;
|
||||
final ring = <List<double>>[
|
||||
<double>[b.west, b.south],
|
||||
<double>[b.east, b.south],
|
||||
<double>[b.east, b.north],
|
||||
<double>[b.west, b.north],
|
||||
<double>[b.west, b.south],
|
||||
];
|
||||
|
||||
final style = <String, Object?>{
|
||||
'version': 8,
|
||||
'name': 'Nuvolari offline fallback',
|
||||
'sources': <String, Object?>{
|
||||
'region-extent': <String, Object?>{
|
||||
'type': 'geojson',
|
||||
'data': <String, Object?>{
|
||||
'type': 'Feature',
|
||||
'properties': <String, Object?>{'id': region.id},
|
||||
'geometry': <String, Object?>{
|
||||
'type': 'Polygon',
|
||||
'coordinates': <Object?>[ring],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'layers': <Object?>[
|
||||
<String, Object?>{
|
||||
'id': 'background',
|
||||
'type': 'background',
|
||||
'paint': <String, Object?>{'background-color': '#0B1720'},
|
||||
},
|
||||
<String, Object?>{
|
||||
'id': 'region-extent-fill',
|
||||
'type': 'fill',
|
||||
'source': 'region-extent',
|
||||
'paint': <String, Object?>{
|
||||
'fill-color': '#13303F',
|
||||
'fill-opacity': 0.7,
|
||||
},
|
||||
},
|
||||
<String, Object?>{
|
||||
'id': 'region-extent-outline',
|
||||
'type': 'line',
|
||||
'source': 'region-extent',
|
||||
'paint': <String, Object?>{
|
||||
'line-color': '#4FA3D1',
|
||||
'line-width': 1.5,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return jsonEncode(style);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user