Skip to content

Commit 6492d02

Browse files
authored
Nautical miles (#1042)
* Add nautical miles scale bar distance unit * add changelog entry
1 parent 0c0f179 commit 6492d02

File tree

7 files changed

+183
-74
lines changed

7 files changed

+183
-74
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### main
2+
3+
* Add nautical miles scale bar distance unit.
4+
15
### 2.17.0-rc.1
26

37
* [iOS] Fix annotation interaction handlers (tap, drag etc.) not working after annotation update.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ fun ScaleBarSettingsInterface.applyFromFLT(settings: ScaleBarSettings, context:
2424
settings.textBorderWidth?.let { this.textBorderWidth = it.toDevicePixels(context) }
2525
settings.textSize?.let { this.textSize = it.toFloat() }
2626
settings.isMetricUnits?.let { this.isMetricUnits = it }
27+
settings.distanceUnits?.let {
28+
this.distanceUnits = com.mapbox.maps.plugin.DistanceUnits.values()[it.ordinal]
29+
}
2730
settings.refreshInterval?.let { this.refreshInterval = it }
2831
settings.showTextBorder?.let { this.showTextBorder = it }
2932
settings.ratio?.let { this.ratio = it.toFloat() }
@@ -47,6 +50,7 @@ fun ScaleBarSettingsInterface.toFLT(context: Context) = ScaleBarSettings(
4750
textBorderWidth = textBorderWidth.toLogicalPixels(context),
4851
textSize = textSize.toDouble(),
4952
isMetricUnits = isMetricUnits,
53+
distanceUnits = DistanceUnits.values()[distanceUnits.ordinal],
5054
refreshInterval = refreshInterval,
5155
showTextBorder = showTextBorder,
5256
ratio = ratio.toDouble(),

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

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ enum class ModelElevationReference(val raw: Int) {
140140
}
141141
}
142142

143+
/**
144+
* Supported distance unit types.
145+
* Default value: "metric".
146+
*/
147+
enum class DistanceUnits(val raw: Int) {
148+
/** Metric units using meters and kilometers. The scale bar will automatically choose between meters and kilometers based on the distance being displayed for optimal readability. */
149+
METRIC(0),
150+
/** Imperial units using feet for short distances and miles for longer distances. The scale bar will display distances in feet for small distances and automatically switch to miles for longer distances. */
151+
IMPERIAL(1),
152+
/** Nautical units using fathoms for short distances and nautical miles for longer distances. The scale bar will display distances in fathoms for small distances and automatically switch to nautical miles for longer distances. Commonly used for marine and aviation navigation. */
153+
NAUTICAL(2);
154+
155+
companion object {
156+
fun ofRaw(raw: Int): DistanceUnits? {
157+
return values().firstOrNull { it.raw == raw }
158+
}
159+
}
160+
}
161+
143162
/**
144163
* Gesture configuration allows to control the user touch interaction.
145164
*
@@ -712,6 +731,11 @@ data class ScaleBarSettings(
712731
* Default value: true.
713732
*/
714733
val isMetricUnits: Boolean? = null,
734+
/**
735+
* Supported distance unit types.
736+
* Default value: "metric".
737+
*/
738+
val distanceUnits: DistanceUnits? = null,
715739
/**
716740
* Configures minimum refresh interval, in millisecond, default is 15.
717741
* Default value: 15.
@@ -750,11 +774,12 @@ data class ScaleBarSettings(
750774
val textBorderWidth = pigeonVar_list[12] as Double?
751775
val textSize = pigeonVar_list[13] as Double?
752776
val isMetricUnits = pigeonVar_list[14] as Boolean?
753-
val refreshInterval = pigeonVar_list[15] as Long?
754-
val showTextBorder = pigeonVar_list[16] as Boolean?
755-
val ratio = pigeonVar_list[17] as Double?
756-
val useContinuousRendering = pigeonVar_list[18] as Boolean?
757-
return ScaleBarSettings(enabled, position, marginLeft, marginTop, marginRight, marginBottom, textColor, primaryColor, secondaryColor, borderWidth, height, textBarMargin, textBorderWidth, textSize, isMetricUnits, refreshInterval, showTextBorder, ratio, useContinuousRendering)
777+
val distanceUnits = pigeonVar_list[15] as DistanceUnits?
778+
val refreshInterval = pigeonVar_list[16] as Long?
779+
val showTextBorder = pigeonVar_list[17] as Boolean?
780+
val ratio = pigeonVar_list[18] as Double?
781+
val useContinuousRendering = pigeonVar_list[19] as Boolean?
782+
return ScaleBarSettings(enabled, position, marginLeft, marginTop, marginRight, marginBottom, textColor, primaryColor, secondaryColor, borderWidth, height, textBarMargin, textBorderWidth, textSize, isMetricUnits, distanceUnits, refreshInterval, showTextBorder, ratio, useContinuousRendering)
758783
}
759784
}
760785
fun toList(): List<Any?> {
@@ -774,6 +799,7 @@ data class ScaleBarSettings(
774799
textBorderWidth,
775800
textSize,
776801
isMetricUnits,
802+
distanceUnits,
777803
refreshInterval,
778804
showTextBorder,
779805
ratio,
@@ -802,6 +828,7 @@ data class ScaleBarSettings(
802828
textBorderWidth == other.textBorderWidth &&
803829
textSize == other.textSize &&
804830
isMetricUnits == other.isMetricUnits &&
831+
distanceUnits == other.distanceUnits &&
805832
refreshInterval == other.refreshInterval &&
806833
showTextBorder == other.showTextBorder &&
807834
ratio == other.ratio &&
@@ -1130,51 +1157,56 @@ private open class SettingsPigeonCodec : StandardMessageCodec() {
11301157
}
11311158
}
11321159
134.toByte() -> {
1160+
return (readValue(buffer) as Long?)?.let {
1161+
DistanceUnits.ofRaw(it.toInt())
1162+
}
1163+
}
1164+
135.toByte() -> {
11331165
return (readValue(buffer) as? List<Any?>)?.let {
11341166
ScreenCoordinate.fromList(it)
11351167
}
11361168
}
1137-
135.toByte() -> {
1169+
136.toByte() -> {
11381170
return (readValue(buffer) as? List<Any?>)?.let {
11391171
GesturesSettings.fromList(it)
11401172
}
11411173
}
1142-
136.toByte() -> {
1174+
137.toByte() -> {
11431175
return (readValue(buffer) as? List<Any?>)?.let {
11441176
LocationPuck2D.fromList(it)
11451177
}
11461178
}
1147-
137.toByte() -> {
1179+
138.toByte() -> {
11481180
return (readValue(buffer) as? List<Any?>)?.let {
11491181
LocationPuck3D.fromList(it)
11501182
}
11511183
}
1152-
138.toByte() -> {
1184+
139.toByte() -> {
11531185
return (readValue(buffer) as? List<Any?>)?.let {
11541186
LocationPuck.fromList(it)
11551187
}
11561188
}
1157-
139.toByte() -> {
1189+
140.toByte() -> {
11581190
return (readValue(buffer) as? List<Any?>)?.let {
11591191
LocationComponentSettings.fromList(it)
11601192
}
11611193
}
1162-
140.toByte() -> {
1194+
141.toByte() -> {
11631195
return (readValue(buffer) as? List<Any?>)?.let {
11641196
ScaleBarSettings.fromList(it)
11651197
}
11661198
}
1167-
141.toByte() -> {
1199+
142.toByte() -> {
11681200
return (readValue(buffer) as? List<Any?>)?.let {
11691201
CompassSettings.fromList(it)
11701202
}
11711203
}
1172-
142.toByte() -> {
1204+
143.toByte() -> {
11731205
return (readValue(buffer) as? List<Any?>)?.let {
11741206
AttributionSettings.fromList(it)
11751207
}
11761208
}
1177-
143.toByte() -> {
1209+
144.toByte() -> {
11781210
return (readValue(buffer) as? List<Any?>)?.let {
11791211
LogoSettings.fromList(it)
11801212
}
@@ -1204,44 +1236,48 @@ private open class SettingsPigeonCodec : StandardMessageCodec() {
12041236
stream.write(133)
12051237
writeValue(stream, value.raw)
12061238
}
1207-
is ScreenCoordinate -> {
1239+
is DistanceUnits -> {
12081240
stream.write(134)
1241+
writeValue(stream, value.raw)
1242+
}
1243+
is ScreenCoordinate -> {
1244+
stream.write(135)
12091245
writeValue(stream, value.toList())
12101246
}
12111247
is GesturesSettings -> {
1212-
stream.write(135)
1248+
stream.write(136)
12131249
writeValue(stream, value.toList())
12141250
}
12151251
is LocationPuck2D -> {
1216-
stream.write(136)
1252+
stream.write(137)
12171253
writeValue(stream, value.toList())
12181254
}
12191255
is LocationPuck3D -> {
1220-
stream.write(137)
1256+
stream.write(138)
12211257
writeValue(stream, value.toList())
12221258
}
12231259
is LocationPuck -> {
1224-
stream.write(138)
1260+
stream.write(139)
12251261
writeValue(stream, value.toList())
12261262
}
12271263
is LocationComponentSettings -> {
1228-
stream.write(139)
1264+
stream.write(140)
12291265
writeValue(stream, value.toList())
12301266
}
12311267
is ScaleBarSettings -> {
1232-
stream.write(140)
1268+
stream.write(141)
12331269
writeValue(stream, value.toList())
12341270
}
12351271
is CompassSettings -> {
1236-
stream.write(141)
1272+
stream.write(142)
12371273
writeValue(stream, value.toList())
12381274
}
12391275
is AttributionSettings -> {
1240-
stream.write(142)
1276+
stream.write(143)
12411277
writeValue(stream, value.toList())
12421278
}
12431279
is LogoSettings -> {
1244-
stream.write(143)
1280+
stream.write(144)
12451281
writeValue(stream, value.toList())
12461282
}
12471283
else -> super.writeValue(stream, value)

example/integration_test/scale_bar_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main() {
2929
textBarMargin: 1,
3030
textBorderWidth: 2,
3131
textSize: 10,
32-
isMetricUnits: true,
32+
distanceUnits: DistanceUnits.NAUTICAL,
3333
refreshInterval: 10,
3434
showTextBorder: true,
3535
ratio: 1.5,
@@ -38,7 +38,7 @@ void main() {
3838
await scaleBar.updateSettings(settings);
3939
var updatedSettings = await scaleBar.getSettings();
4040
expect(updatedSettings.position, OrnamentPosition.BOTTOM_RIGHT);
41-
expect(updatedSettings.isMetricUnits, true);
41+
expect(updatedSettings.distanceUnits, DistanceUnits.NAUTICAL);
4242
if (Platform.isIOS) {
4343
expect(updatedSettings.marginRight, 3);
4444
expect(updatedSettings.marginBottom, 4);

ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Generated/Settings.swift

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ enum ModelElevationReference: Int {
109109
case gROUND = 1
110110
}
111111

112+
/// Supported distance unit types.
113+
/// Default value: "metric".
114+
enum DistanceUnits: Int {
115+
/// Metric units using meters and kilometers. The scale bar will automatically choose between meters and kilometers based on the distance being displayed for optimal readability.
116+
case mETRIC = 0
117+
/// Imperial units using feet for short distances and miles for longer distances. The scale bar will display distances in feet for small distances and automatically switch to miles for longer distances.
118+
case iMPERIAL = 1
119+
/// Nautical units using fathoms for short distances and nautical miles for longer distances. The scale bar will display distances in fathoms for small distances and automatically switch to nautical miles for longer distances. Commonly used for marine and aviation navigation.
120+
case nAUTICAL = 2
121+
}
122+
112123
/// Gesture configuration allows to control the user touch interaction.
113124
///
114125
/// Generated class from Pigeon that represents data sent in messages.
@@ -529,6 +540,9 @@ struct ScaleBarSettings {
529540
/// Whether the scale bar is using metric unit. True if the scale bar is using metric system, false if the scale bar is using imperial units.
530541
/// Default value: true.
531542
var isMetricUnits: Bool? = nil
543+
/// Supported distance unit types.
544+
/// Default value: "metric".
545+
var distanceUnits: DistanceUnits? = nil
532546
/// Configures minimum refresh interval, in millisecond, default is 15.
533547
/// Default value: 15.
534548
var refreshInterval: Int64? = nil
@@ -560,10 +574,11 @@ struct ScaleBarSettings {
560574
let textBorderWidth: Double? = nilOrValue(pigeonVar_list[12])
561575
let textSize: Double? = nilOrValue(pigeonVar_list[13])
562576
let isMetricUnits: Bool? = nilOrValue(pigeonVar_list[14])
563-
let refreshInterval: Int64? = nilOrValue(pigeonVar_list[15])
564-
let showTextBorder: Bool? = nilOrValue(pigeonVar_list[16])
565-
let ratio: Double? = nilOrValue(pigeonVar_list[17])
566-
let useContinuousRendering: Bool? = nilOrValue(pigeonVar_list[18])
577+
let distanceUnits: DistanceUnits? = nilOrValue(pigeonVar_list[15])
578+
let refreshInterval: Int64? = nilOrValue(pigeonVar_list[16])
579+
let showTextBorder: Bool? = nilOrValue(pigeonVar_list[17])
580+
let ratio: Double? = nilOrValue(pigeonVar_list[18])
581+
let useContinuousRendering: Bool? = nilOrValue(pigeonVar_list[19])
567582

568583
return ScaleBarSettings(
569584
enabled: enabled,
@@ -581,6 +596,7 @@ struct ScaleBarSettings {
581596
textBorderWidth: textBorderWidth,
582597
textSize: textSize,
583598
isMetricUnits: isMetricUnits,
599+
distanceUnits: distanceUnits,
584600
refreshInterval: refreshInterval,
585601
showTextBorder: showTextBorder,
586602
ratio: ratio,
@@ -604,6 +620,7 @@ struct ScaleBarSettings {
604620
textBorderWidth,
605621
textSize,
606622
isMetricUnits,
623+
distanceUnits,
607624
refreshInterval,
608625
showTextBorder,
609626
ratio,
@@ -857,24 +874,30 @@ private class SettingsPigeonCodecReader: FlutterStandardReader {
857874
}
858875
return nil
859876
case 134:
860-
return ScreenCoordinate.fromList(self.readValue() as! [Any?])
877+
let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?)
878+
if let enumResultAsInt = enumResultAsInt {
879+
return DistanceUnits(rawValue: enumResultAsInt)
880+
}
881+
return nil
861882
case 135:
862-
return GesturesSettings.fromList(self.readValue() as! [Any?])
883+
return ScreenCoordinate.fromList(self.readValue() as! [Any?])
863884
case 136:
864-
return LocationPuck2D.fromList(self.readValue() as! [Any?])
885+
return GesturesSettings.fromList(self.readValue() as! [Any?])
865886
case 137:
866-
return LocationPuck3D.fromList(self.readValue() as! [Any?])
887+
return LocationPuck2D.fromList(self.readValue() as! [Any?])
867888
case 138:
868-
return LocationPuck.fromList(self.readValue() as! [Any?])
889+
return LocationPuck3D.fromList(self.readValue() as! [Any?])
869890
case 139:
870-
return LocationComponentSettings.fromList(self.readValue() as! [Any?])
891+
return LocationPuck.fromList(self.readValue() as! [Any?])
871892
case 140:
872-
return ScaleBarSettings.fromList(self.readValue() as! [Any?])
893+
return LocationComponentSettings.fromList(self.readValue() as! [Any?])
873894
case 141:
874-
return CompassSettings.fromList(self.readValue() as! [Any?])
895+
return ScaleBarSettings.fromList(self.readValue() as! [Any?])
875896
case 142:
876-
return AttributionSettings.fromList(self.readValue() as! [Any?])
897+
return CompassSettings.fromList(self.readValue() as! [Any?])
877898
case 143:
899+
return AttributionSettings.fromList(self.readValue() as! [Any?])
900+
case 144:
878901
return LogoSettings.fromList(self.readValue() as! [Any?])
879902
default:
880903
return super.readValue(ofType: type)
@@ -899,35 +922,38 @@ private class SettingsPigeonCodecWriter: FlutterStandardWriter {
899922
} else if let value = value as? ModelElevationReference {
900923
super.writeByte(133)
901924
super.writeValue(value.rawValue)
902-
} else if let value = value as? ScreenCoordinate {
925+
} else if let value = value as? DistanceUnits {
903926
super.writeByte(134)
927+
super.writeValue(value.rawValue)
928+
} else if let value = value as? ScreenCoordinate {
929+
super.writeByte(135)
904930
super.writeValue(value.toList())
905931
} else if let value = value as? GesturesSettings {
906-
super.writeByte(135)
932+
super.writeByte(136)
907933
super.writeValue(value.toList())
908934
} else if let value = value as? LocationPuck2D {
909-
super.writeByte(136)
935+
super.writeByte(137)
910936
super.writeValue(value.toList())
911937
} else if let value = value as? LocationPuck3D {
912-
super.writeByte(137)
938+
super.writeByte(138)
913939
super.writeValue(value.toList())
914940
} else if let value = value as? LocationPuck {
915-
super.writeByte(138)
941+
super.writeByte(139)
916942
super.writeValue(value.toList())
917943
} else if let value = value as? LocationComponentSettings {
918-
super.writeByte(139)
944+
super.writeByte(140)
919945
super.writeValue(value.toList())
920946
} else if let value = value as? ScaleBarSettings {
921-
super.writeByte(140)
947+
super.writeByte(141)
922948
super.writeValue(value.toList())
923949
} else if let value = value as? CompassSettings {
924-
super.writeByte(141)
950+
super.writeByte(142)
925951
super.writeValue(value.toList())
926952
} else if let value = value as? AttributionSettings {
927-
super.writeByte(142)
953+
super.writeByte(143)
928954
super.writeValue(value.toList())
929955
} else if let value = value as? LogoSettings {
930-
super.writeByte(143)
956+
super.writeByte(144)
931957
super.writeValue(value.toList())
932958
} else {
933959
super.writeValue(value)

0 commit comments

Comments
 (0)