Skip to content

Commit 93be515

Browse files
authored
Add option to enable/disable map widget attribution (#536)
* Add option to enable/disable map widget attribution * Enable Android snapshots to be consumed * Update logo settings in bulk * Update attribution settings in bulk
1 parent 61bf343 commit 93be515

File tree

10 files changed

+118
-54
lines changed

10 files changed

+118
-54
lines changed

android/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ rootProject.allprojects {
3333
password = token
3434
}
3535
}
36+
maven {
37+
url 'https://api.mapbox.com/downloads/v2/snapshots/maven'
38+
authentication {
39+
basic(BasicAuthentication)
40+
}
41+
credentials {
42+
username = "mapbox"
43+
password = token
44+
}
45+
}
3646
}
3747
}
3848

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/mapping/AttributionMappings.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ import com.mapbox.maps.mapbox_maps.toLogicalPixels
88
import com.mapbox.maps.plugin.attribution.generated.AttributionSettingsInterface
99

1010
fun AttributionSettingsInterface.applyFromFLT(settings: AttributionSettings, context: Context) {
11-
settings.iconColor?.let { iconColor = it.toInt() }
12-
settings.position?.let { position = it.toPosition() }
13-
settings.marginLeft?.let { marginLeft = it.toDevicePixels(context) }
14-
settings.marginTop?.let { marginTop = it.toDevicePixels(context) }
15-
settings.marginRight?.let { marginRight = it.toDevicePixels(context) }
16-
settings.marginBottom?.let { marginBottom = it.toDevicePixels(context) }
17-
settings.clickable?.let { clickable = it }
11+
updateSettings {
12+
settings.enabled?.let { this.enabled = it }
13+
settings.iconColor?.let { this.iconColor = it.toInt() }
14+
settings.position?.let { this.position = it.toPosition() }
15+
settings.marginLeft?.let { this.marginLeft = it.toDevicePixels(context) }
16+
settings.marginTop?.let { this.marginTop = it.toDevicePixels(context) }
17+
settings.marginRight?.let { this.marginRight = it.toDevicePixels(context) }
18+
settings.marginBottom?.let { this.marginBottom = it.toDevicePixels(context) }
19+
settings.clickable?.let { this.clickable = it }
20+
}
1821
}
1922

2023
fun AttributionSettingsInterface.toFLT(context: Context) = AttributionSettings(
24+
enabled = enabled,
2125
iconColor = iconColor.toUInt().toLong(),
2226
position = position.toOrnamentPosition(),
2327
marginLeft = marginLeft.toLogicalPixels(context),

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/mapping/LogoMappings.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ import com.mapbox.maps.mapbox_maps.toLogicalPixels
88
import com.mapbox.maps.plugin.logo.generated.LogoSettingsInterface
99

1010
fun LogoSettingsInterface.applyFromFLT(settings: LogoSettings, context: Context) {
11-
settings.position?.let { position = it.toPosition() }
12-
settings.marginLeft?.let { marginLeft = it.toDevicePixels(context) }
13-
settings.marginTop?.let { marginTop = it.toDevicePixels(context) }
14-
settings.marginRight?.let { marginRight = it.toDevicePixels(context) }
15-
settings.marginBottom?.let { marginBottom = it.toDevicePixels(context) }
11+
this.updateSettings {
12+
settings.enabled?.let { this.enabled = it }
13+
settings.position?.let { this.position = it.toPosition() }
14+
settings.marginLeft?.let { this.marginLeft = it.toDevicePixels(context) }
15+
settings.marginTop?.let { this.marginTop = it.toDevicePixels(context) }
16+
settings.marginRight?.let { this.marginRight = it.toDevicePixels(context) }
17+
settings.marginBottom?.let { this.marginBottom = it.toDevicePixels(context) }
18+
}
1619
}
1720

1821
fun LogoSettingsInterface.toFLT(context: Context) = LogoSettings(
22+
enabled = enabled,
1923
position = position.toOrnamentPosition(),
2024
marginLeft = marginLeft.toLogicalPixels(context),
2125
marginTop = marginTop.toLogicalPixels(context),

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/Settings.kt

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ data class CompassSettings(
558558
* Generated class from Pigeon that represents data sent in messages.
559559
*/
560560
data class AttributionSettings(
561+
/**
562+
* Whether the attribution icon is visible on the map.
563+
* Restricted API. Please contact Mapbox to discuss your use case if you intend to use this property.
564+
*/
565+
val enabled: Boolean? = null,
561566
/** Defines text color of the attribution icon. */
562567
val iconColor: Long? = null,
563568
/** Defines where the attribution icon is positioned on the map */
@@ -577,20 +582,22 @@ data class AttributionSettings(
577582
companion object {
578583
@Suppress("UNCHECKED_CAST")
579584
fun fromList(list: List<Any?>): AttributionSettings {
580-
val iconColor = list[0].let { if (it is Int) it.toLong() else it as Long? }
581-
val position = (list[1] as Int?)?.let {
585+
val enabled = list[0] as Boolean?
586+
val iconColor = list[1].let { if (it is Int) it.toLong() else it as Long? }
587+
val position = (list[2] as Int?)?.let {
582588
OrnamentPosition.ofRaw(it)
583589
}
584-
val marginLeft = list[2] as Double?
585-
val marginTop = list[3] as Double?
586-
val marginRight = list[4] as Double?
587-
val marginBottom = list[5] as Double?
588-
val clickable = list[6] as Boolean?
589-
return AttributionSettings(iconColor, position, marginLeft, marginTop, marginRight, marginBottom, clickable)
590+
val marginLeft = list[3] as Double?
591+
val marginTop = list[4] as Double?
592+
val marginRight = list[5] as Double?
593+
val marginBottom = list[6] as Double?
594+
val clickable = list[7] as Boolean?
595+
return AttributionSettings(enabled, iconColor, position, marginLeft, marginTop, marginRight, marginBottom, clickable)
590596
}
591597
}
592598
fun toList(): List<Any?> {
593599
return listOf<Any?>(
600+
enabled,
594601
iconColor,
595602
position?.raw,
596603
marginLeft,
@@ -608,6 +615,11 @@ data class AttributionSettings(
608615
* Generated class from Pigeon that represents data sent in messages.
609616
*/
610617
data class LogoSettings(
618+
/**
619+
* Whether the logo is visible on the map.
620+
* Restricted API. Please contact Mapbox to discuss your use case if you intend to use this property.
621+
*/
622+
val enabled: Boolean? = null,
611623
/** Defines where the logo is positioned on the map */
612624
val position: OrnamentPosition? = null,
613625
/** Defines the margin to the left that the attribution icon honors. This property is specified in pixels. */
@@ -623,18 +635,20 @@ data class LogoSettings(
623635
companion object {
624636
@Suppress("UNCHECKED_CAST")
625637
fun fromList(list: List<Any?>): LogoSettings {
626-
val position = (list[0] as Int?)?.let {
638+
val enabled = list[0] as Boolean?
639+
val position = (list[1] as Int?)?.let {
627640
OrnamentPosition.ofRaw(it)
628641
}
629-
val marginLeft = list[1] as Double?
630-
val marginTop = list[2] as Double?
631-
val marginRight = list[3] as Double?
632-
val marginBottom = list[4] as Double?
633-
return LogoSettings(position, marginLeft, marginTop, marginRight, marginBottom)
642+
val marginLeft = list[2] as Double?
643+
val marginTop = list[3] as Double?
644+
val marginRight = list[4] as Double?
645+
val marginBottom = list[5] as Double?
646+
return LogoSettings(enabled, position, marginLeft, marginTop, marginRight, marginBottom)
634647
}
635648
}
636649
fun toList(): List<Any?> {
637650
return listOf<Any?>(
651+
enabled,
638652
position?.raw,
639653
marginLeft,
640654
marginTop,

example/integration_test/attribution_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void main() {
1515
final mapboxMap = await mapFuture;
1616
final attribution = mapboxMap.attribution;
1717
var settings = AttributionSettings(
18+
enabled: false,
1819
iconColor: Colors.blue.value,
1920
position: OrnamentPosition.TOP_RIGHT,
2021
marginLeft: 1,
@@ -25,6 +26,7 @@ void main() {
2526
);
2627
await attribution.updateSettings(settings);
2728
var updatedSettings = await attribution.getSettings();
29+
expect(updatedSettings.enabled, isFalse);
2830
expect(updatedSettings.position, OrnamentPosition.TOP_RIGHT);
2931
expect(updatedSettings.iconColor, Colors.blue.value);
3032
if (Platform.isIOS) {

example/integration_test/logo_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void main() {
1414
final mapboxMap = await mapFuture;
1515
final logo = mapboxMap.logo;
1616
var settings = LogoSettings(
17+
enabled: false,
1718
position: OrnamentPosition.BOTTOM_LEFT,
1819
marginLeft: 1,
1920
marginTop: 2,
@@ -22,6 +23,7 @@ void main() {
2223
await logo.updateSettings(settings);
2324
var getSettings = await logo.getSettings();
2425
expect(getSettings.position, OrnamentPosition.BOTTOM_LEFT);
26+
expect(getSettings.enabled, isFalse);
2527
if (Platform.isIOS) {
2628
expect(getSettings.marginLeft, 1);
2729
expect(getSettings.marginBottom, 4);

ios/Classes/AttributionController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Foundation
2-
@_spi(Experimental) import MapboxMaps
2+
@_spi(Experimental) @_spi(Restricted) import MapboxMaps
33

44
final class AttributionController: AttributionSettingsInterface {
55

@@ -19,7 +19,7 @@ final class AttributionController: AttributionSettingsInterface {
1919
attributionButton.position = .topTrailing
2020
attributionButton.margins = CGPoint(x: settings.marginRight ?? 0, y: settings.marginTop ?? 0)
2121
}
22-
22+
attributionButton.visibility = (settings.enabled ?? true) ? .visible : .hidden
2323
ornaments.options.attributionButton = attributionButton
2424

2525
if let iconColor = settings.iconColor {
@@ -33,6 +33,7 @@ final class AttributionController: AttributionSettingsInterface {
3333
let iconColor = ornaments.attributionButton.tintColor.rgb()
3434

3535
return AttributionSettings(
36+
enabled: options.visibility != .hidden,
3637
iconColor: Int64(iconColor),
3738
position: position,
3839
marginLeft: options.margins.x,

ios/Classes/Generated/Settings.swift

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ struct CompassSettings {
609609
///
610610
/// Generated class from Pigeon that represents data sent in messages.
611611
struct AttributionSettings {
612+
/// Whether the attribution icon is visible on the map.
613+
/// Restricted API. Please contact Mapbox to discuss your use case if you intend to use this property.
614+
var enabled: Bool?
612615
/// Defines text color of the attribution icon.
613616
var iconColor: Int64?
614617
/// Defines where the attribution icon is positioned on the map
@@ -625,19 +628,21 @@ struct AttributionSettings {
625628
var clickable: Bool?
626629

627630
static func fromList(_ list: [Any?]) -> AttributionSettings? {
628-
let iconColor: Int64? = isNullish(list[0]) ? nil : (list[0] is Int64? ? list[0] as! Int64? : Int64(list[0] as! Int32))
631+
let enabled: Bool? = nilOrValue(list[0])
632+
let iconColor: Int64? = isNullish(list[1]) ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32))
629633
var position: OrnamentPosition?
630-
let positionEnumVal: Int? = nilOrValue(list[1])
634+
let positionEnumVal: Int? = nilOrValue(list[2])
631635
if let positionRawValue = positionEnumVal {
632636
position = OrnamentPosition(rawValue: positionRawValue)!
633637
}
634-
let marginLeft: Double? = nilOrValue(list[2])
635-
let marginTop: Double? = nilOrValue(list[3])
636-
let marginRight: Double? = nilOrValue(list[4])
637-
let marginBottom: Double? = nilOrValue(list[5])
638-
let clickable: Bool? = nilOrValue(list[6])
638+
let marginLeft: Double? = nilOrValue(list[3])
639+
let marginTop: Double? = nilOrValue(list[4])
640+
let marginRight: Double? = nilOrValue(list[5])
641+
let marginBottom: Double? = nilOrValue(list[6])
642+
let clickable: Bool? = nilOrValue(list[7])
639643

640644
return AttributionSettings(
645+
enabled: enabled,
641646
iconColor: iconColor,
642647
position: position,
643648
marginLeft: marginLeft,
@@ -649,6 +654,7 @@ struct AttributionSettings {
649654
}
650655
func toList() -> [Any?] {
651656
return [
657+
enabled,
652658
iconColor,
653659
position?.rawValue,
654660
marginLeft,
@@ -664,6 +670,9 @@ struct AttributionSettings {
664670
///
665671
/// Generated class from Pigeon that represents data sent in messages.
666672
struct LogoSettings {
673+
/// Whether the logo is visible on the map.
674+
/// Restricted API. Please contact Mapbox to discuss your use case if you intend to use this property.
675+
var enabled: Bool?
667676
/// Defines where the logo is positioned on the map
668677
var position: OrnamentPosition?
669678
/// Defines the margin to the left that the attribution icon honors. This property is specified in pixels.
@@ -676,17 +685,19 @@ struct LogoSettings {
676685
var marginBottom: Double?
677686

678687
static func fromList(_ list: [Any?]) -> LogoSettings? {
688+
let enabled: Bool? = nilOrValue(list[0])
679689
var position: OrnamentPosition?
680-
let positionEnumVal: Int? = nilOrValue(list[0])
690+
let positionEnumVal: Int? = nilOrValue(list[1])
681691
if let positionRawValue = positionEnumVal {
682692
position = OrnamentPosition(rawValue: positionRawValue)!
683693
}
684-
let marginLeft: Double? = nilOrValue(list[1])
685-
let marginTop: Double? = nilOrValue(list[2])
686-
let marginRight: Double? = nilOrValue(list[3])
687-
let marginBottom: Double? = nilOrValue(list[4])
694+
let marginLeft: Double? = nilOrValue(list[2])
695+
let marginTop: Double? = nilOrValue(list[3])
696+
let marginRight: Double? = nilOrValue(list[4])
697+
let marginBottom: Double? = nilOrValue(list[5])
688698

689699
return LogoSettings(
700+
enabled: enabled,
690701
position: position,
691702
marginLeft: marginLeft,
692703
marginTop: marginTop,
@@ -696,6 +707,7 @@ struct LogoSettings {
696707
}
697708
func toList() -> [Any?] {
698709
return [
710+
enabled,
699711
position?.rawValue,
700712
marginLeft,
701713
marginTop,

ios/Classes/LogoController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Foundation
2-
@_spi(Experimental) import MapboxMaps
2+
@_spi(Experimental) @_spi(Restricted) import MapboxMaps
33

44
final class LogoController: LogoSettingsInterface {
55
func updateSettings(settings: LogoSettings) throws {
@@ -18,14 +18,15 @@ final class LogoController: LogoSettingsInterface {
1818
logo.position = .topTrailing
1919
logo.margins = CGPoint(x: settings.marginRight ?? 0, y: settings.marginTop ?? 0)
2020
}
21-
21+
logo.visibility = (settings.enabled ?? true) ? .visible : .hidden
2222
ornaments.options.logo = logo
2323
}
2424

2525
func getSettings() throws -> LogoSettings {
2626
let options = ornaments.options.logo
2727
let position = getFLT_SETTINGSOrnamentPosition(position: options.position)
2828
return LogoSettings(
29+
enabled: options.visibility != .hidden,
2930
position: position,
3031
marginLeft: options.margins.x,
3132
marginTop: options.margins.y,

0 commit comments

Comments
 (0)