MESSENGER-5379 dynamic location attribution from style.json

This commit is contained in:
Frank Rotermund
2024-01-09 11:02:02 +01:00
parent 9c10374575
commit d7749bb5da
12 changed files with 143 additions and 22 deletions
@@ -68,6 +68,9 @@ struct LocationSharingMapView: UIViewRepresentable {
/// Called when the user pan on the map
var userDidPan: (() -> Void)?
// bwi #5379: for copyright attribution
var attributionsChanged: ((LocationSharingAttribution) -> Void)?
// MARK: - UIViewRepresentable
@@ -154,6 +157,23 @@ extension LocationSharingMapView {
return nil
}
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
// bwi #5379: set copyright to info from style json if available. Needs reevaluation if there is more than one source
var attribution = LocationSharingAttribution()
for source in style.sources {
if let tileSource = source as? MGLRasterTileSource {
for attributionInfo in tileSource.attributionInfos {
attribution.copyrightTexts.append(attributionInfo.title.plainTextString())
attribution.copyrightLinks.append(attributionInfo.url)
}
}
}
locationSharingMapView.attributionsChanged?(attribution)
}
func mapViewDidFailLoadingMap(_ mapView: MGLMapView, withError error: Error) {
locationSharingMapView.errorSubject.send(.failedLoadingMap)
}