Skip to content

Commit 0f8c06b

Browse files
authored
Add experimental LocationPuck3D.modelElevationReference property. (#2906)
1 parent 34a8a4d commit 0f8c06b

File tree

11 files changed

+99
-8
lines changed

11 files changed

+99
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Mapbox welcomes participation and contributions from everyone.
1313
## Bug fixes 🐞
1414
* Mark `BackgroundLayer.backgroundPitchAlignment` as experimental.
1515
* Skip any map scroll (panning) if shove gesture is already in progress preventing camera flying away.
16+
* Introduce experimental `LocationPuck3D.modelElevationReference` property.
1617

1718
# 11.9.0 December 18, 2024
1819
## Breaking changes ⚠️

plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/LayerSourceProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ internal object LayerSourceProvider {
4545
modelColor = locationModelLayerOptions.modelColor,
4646
modelColorExpression = locationModelLayerOptions.modelColorExpression?.let { Value.fromJson(it).take() },
4747
modelColorMixIntensity = locationModelLayerOptions.modelColorMixIntensity.toDouble(),
48-
modelColorMixIntensityExpression = locationModelLayerOptions.modelColorMixIntensityExpression?.let { Value.fromJson(it).take() }
48+
modelColorMixIntensityExpression = locationModelLayerOptions.modelColorMixIntensityExpression?.let { Value.fromJson(it).take() },
49+
modelElevationReference = locationModelLayerOptions.modelElevationReference
4950
)
5051

5152
fun getLocationIndicatorLayer() = LocationIndicatorLayerWrapper(LOCATION_INDICATOR_LAYER)

plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/ModelLayerWrapper.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.annotation.RestrictTo
44
import com.mapbox.bindgen.Value
55
import com.mapbox.maps.MapboxExperimental
66
import com.mapbox.maps.extension.style.utils.ColorUtils.colorIntToRgbaExpression
7+
import com.mapbox.maps.plugin.ModelElevationReference
78
import com.mapbox.maps.plugin.ModelScaleMode
89

910
@OptIn(MapboxExperimental::class)
@@ -26,6 +27,7 @@ internal class ModelLayerWrapper(
2627
modelColorExpression: Value?,
2728
modelColorMixIntensity: Double,
2829
modelColorMixIntensityExpression: Value?,
30+
modelElevationReference: ModelElevationReference,
2931
) : LocationLayerWrapper(layerId) {
3032
init {
3133
layerProperties["id"] = Value(layerId)
@@ -44,6 +46,7 @@ internal class ModelLayerWrapper(
4446
layerProperties["model-emissive-strength"] = modelEmissiveStrengthExpression ?: Value(modelEmissiveStrength)
4547
layerProperties["model-color"] = modelColorExpression ?: colorIntToRgbaExpression(modelColor)
4648
layerProperties["model-color-mix-intensity"] = modelColorMixIntensityExpression ?: Value(modelColorMixIntensity)
49+
layerProperties["model-elevation-reference"] = Value(modelElevationReference.value)
4750
}
4851

4952
private fun buildTransition(delay: Long, duration: Long): Value {
@@ -65,5 +68,7 @@ internal class ModelLayerWrapper(
6568

6669
fun modelScaleMode(modelScaleMode: ModelScaleMode) = updateProperty("model-scale-mode", Value(modelScaleMode.value))
6770

71+
fun modelElevationReference(modelElevationReference: ModelElevationReference) = updateProperty("model-elevation-reference", Value(modelElevationReference.value))
72+
6873
fun slot(slot: String?) = updateProperty("slot", Value(slot ?: ""))
6974
}

plugin-locationcomponent/src/main/java/com/mapbox/maps/plugin/locationcomponent/generated/LocationComponentAttributeParser.kt

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-locationcomponent/src/main/res-public/values/public.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,7 @@
100100
<public name="mapbox_locationComponentLocationPuckLocationPuck3DMaterialOverrides" type="attr" />
101101
<!-- The node overrides for the model. Default value: []. -->
102102
<public name="mapbox_locationComponentLocationPuckLocationPuck3DNodeOverrides" type="attr" />
103+
<!-- Selects the base of the model. Some modes might require precomputed elevation data in the tileset. Default value: "ground". -->
104+
<public name="mapbox_locationComponentLocationPuckLocationPuck3DModelElevationReference" type="attr" />
103105
</resources>
104106
<!-- End of generated file. -->

plugin-locationcomponent/src/main/res/values/attrs.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@
8080
<!-- Enable/Disable shadow receiving for the 3D location puck. Default value: true. -->
8181
<attr name="mapbox_locationComponentLocationPuckLocationPuck3DModelReceiveShadows" format="boolean"/>
8282
<!-- Defines scaling mode. Only applies to location-indicator type layers. Default value: "map". -->
83-
<attr name="mapbox_locationComponentLocationPuckLocationPuck3DModelScaleMode" format="enum"/>
83+
<attr name="mapbox_locationComponentLocationPuckLocationPuck3DModelScaleMode" format="enum">
84+
<!-- Model is scaled so that it's always the same size relative to other map features. The property model-scale specifies how many meters each unit in the model file should cover. -->
85+
<enum name="map" value="0"/>
86+
<!-- Model is scaled so that it's always the same size on the screen. The property model-scale specifies how many pixels each unit in model file should cover. -->
87+
<enum name="viewport" value="1"/>
88+
</attr>
8489
<!-- Strength of the emission. There is no emission for value 0. For value 1.0, only emissive component (no shading) is displayed and values above 1.0 produce light contribution to surrounding area, for some of the parts (e.g. doors). Expressions that depend on measure-light are only supported as a global layer value (and not for each feature) when using GeoJSON or vector tile as the model layer source. Default value: 1. Value range: [0, 5] -->
8590
<attr name="mapbox_locationComponentLocationPuckLocationPuck3DModelEmissiveStrength" format="float"/>
8691
<!-- The emissive strength expression of the model, which will overwrite the default model emissive strength. -->
@@ -101,6 +106,13 @@
101106
<attr name="mapbox_locationComponentLocationPuckLocationPuck3DMaterialOverrides" format="reference"/>
102107
<!-- The node overrides for the model. Default value: []. -->
103108
<attr name="mapbox_locationComponentLocationPuckLocationPuck3DNodeOverrides" format="reference"/>
109+
<!-- Selects the base of the model. Some modes might require precomputed elevation data in the tileset. Default value: "ground". -->
110+
<attr name="mapbox_locationComponentLocationPuckLocationPuck3DModelElevationReference" format="enum">
111+
<!-- Elevated rendering is enabled. Use this mode to elevate lines relative to the sea level. -->
112+
<enum name="sea" value="0"/>
113+
<!-- Elevated rendering is enabled. Use this mode to elevate lines relative to the ground's height below them. -->
114+
<enum name="ground" value="1"/>
115+
</attr>
104116
</declare-styleable>
105117
</resources>
106118
<!-- End of generated file. -->

plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/LayerSourceProviderTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class LayerSourceProviderTest {
7070
"model-cast-shadows" to true,
7171
"model-scale-transition" to hashMapOf("duration" to 0, "delay" to 0),
7272
"model-rotation-transition" to hashMapOf("duration" to 0, "delay" to 0),
73+
"model-elevation-reference" to "ground",
7374
"model-emissive-strength" to 1.0,
7475
"model-color" to listOf("rgba", 255, 255, 255, 1.0),
7576
"model-color-mix-intensity" to 0.0,

plugin-locationcomponent/src/test/java/com/mapbox/maps/plugin/locationcomponent/ModelLayerWrapperTest.kt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.mapbox.maps.MapboxExperimental
99
import com.mapbox.maps.MapboxStyleManager
1010
import com.mapbox.maps.extension.style.utils.ColorUtils.colorIntToRgbaExpression
1111
import com.mapbox.maps.logE
12+
import com.mapbox.maps.plugin.ModelElevationReference
1213
import com.mapbox.maps.plugin.ModelScaleMode
1314
import com.mapbox.maps.plugin.locationcomponent.utils.take
1415
import io.mockk.Runs
@@ -47,7 +48,8 @@ class ModelLayerWrapperTest {
4748
modelColor = INITIAL_MODEL_COLOR,
4849
modelColorExpression = null,
4950
modelColorMixIntensity = INITIAL_MODEL_COLOR_MIX_INTENSITY,
50-
modelColorMixIntensityExpression = null
51+
modelColorMixIntensityExpression = null,
52+
modelElevationReference = INITIAL_MODEL_ELEVATION_REFERENCE,
5153
)
5254
private val layerWithExpression = ModelLayerWrapper(
5355
layerId = MODEL_LAYER_ID,
@@ -66,7 +68,8 @@ class ModelLayerWrapperTest {
6668
modelColor = INITIAL_MODEL_COLOR,
6769
modelColorExpression = INITIAL_MODEL_COLOR_EXPRESSION,
6870
modelColorMixIntensity = INITIAL_MODEL_COLOR_MIX_INTENSITY,
69-
modelColorMixIntensityExpression = INITIAL_MODEL_COLOR_MIX_INTENSITY_EXPRESSION
71+
modelColorMixIntensityExpression = INITIAL_MODEL_COLOR_MIX_INTENSITY_EXPRESSION,
72+
modelElevationReference = INITIAL_MODEL_ELEVATION_REFERENCE,
7073
)
7174
private val expected: Expected<String, None> = mockk(relaxed = true)
7275

@@ -105,6 +108,7 @@ class ModelLayerWrapperTest {
105108
"model-emissive-strength" to INITIAL_MODEL_EMISSIVE_STENGTH,
106109
"model-color" to colorIntToRgbaExpression(INITIAL_MODEL_COLOR),
107110
"model-color-mix-intensity" to INITIAL_MODEL_COLOR_MIX_INTENSITY,
111+
"model-elevation-reference" to INITIAL_MODEL_ELEVATION_REFERENCE.value,
108112
).toValue(),
109113
layer.toValue(),
110114
)
@@ -130,6 +134,7 @@ class ModelLayerWrapperTest {
130134
"model-emissive-strength" to INITIAL_MODEL_EMISSIVE_STENGTH_EXPRESSION,
131135
"model-color" to INITIAL_MODEL_COLOR_EXPRESSION,
132136
"model-color-mix-intensity" to INITIAL_MODEL_COLOR_MIX_INTENSITY_EXPRESSION,
137+
"model-elevation-reference" to INITIAL_MODEL_ELEVATION_REFERENCE.value,
133138
).toValue(),
134139
layerWithExpression.toValue(),
135140
)
@@ -241,11 +246,26 @@ class ModelLayerWrapperTest {
241246
setModelScaleMode(ModelScaleMode.MAP)
242247
}
243248

249+
@Test
250+
fun testModelElevationReferenceGround() {
251+
setModelElevationReference(ModelElevationReference.GROUND)
252+
}
253+
254+
@Test
255+
fun testModelElevationReferenceSea() {
256+
setModelElevationReference(ModelElevationReference.SEA)
257+
}
258+
244259
private fun setModelScaleMode(mode: ModelScaleMode) {
245260
layer.modelScaleMode(mode)
246261
verify { style.setStyleLayerProperty(MODEL_LAYER_ID, "model-scale-mode", Value(mode.value)) }
247262
}
248263

264+
private fun setModelElevationReference(reference: ModelElevationReference) {
265+
layer.modelElevationReference(reference)
266+
verify { style.setStyleLayerProperty(MODEL_LAYER_ID, "model-elevation-reference", Value(reference.value)) }
267+
}
268+
249269
companion object {
250270
private const val MODEL_LAYER_ID = "modelLayerId"
251271
private const val MODEL_SOURCE_ID = "modelSourceId"
@@ -266,6 +286,7 @@ class ModelLayerWrapperTest {
266286
""".trimIndent()
267287
).take()
268288
private val INITIAL_SCALE_MODE = ModelScaleMode.VIEWPORT
289+
private val INITIAL_MODEL_ELEVATION_REFERENCE = ModelElevationReference.GROUND
269290
private val INITIAL_MODEL_EMISSIVE_STENGTH = 1.0
270291
private val INITIAL_MODEL_EMISSIVE_STENGTH_EXPRESSION = Value.fromJson(
271292
"""

sdk-base/api/Release/metalava.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@ package com.mapbox.maps.plugin {
10881088
}
10891089

10901090
public final class LocationPuck3D extends com.mapbox.maps.plugin.LocationPuck {
1091+
ctor public LocationPuck3D(String modelUri, java.util.List<java.lang.Float> position = listOf(0.0, 0.0), float modelOpacity = 1f, java.util.List<java.lang.Float> modelScale = listOf(1.0, 1.0, 1.0), String? modelScaleExpression = null, java.util.List<java.lang.Float> modelTranslation = listOf(0.0, 0.0, 0.0), java.util.List<java.lang.Float> modelRotation = listOf(0.0, 0.0, 90.0), @com.mapbox.maps.MapboxExperimental boolean modelCastShadows = true, @com.mapbox.maps.MapboxExperimental boolean modelReceiveShadows = true, @com.mapbox.maps.MapboxExperimental com.mapbox.maps.plugin.ModelScaleMode modelScaleMode = com.mapbox.maps.plugin.ModelScaleMode.VIEWPORT, float modelEmissiveStrength = 1f, String? modelEmissiveStrengthExpression = null, String? modelOpacityExpression = null, String? modelRotationExpression = null, int modelColor = Color.parseColor("#ffffff"), String? modelColorExpression = null, float modelColorMixIntensity = 0f, String? modelColorMixIntensityExpression = null, @com.mapbox.maps.MapboxExperimental java.util.List<java.lang.String> materialOverrides = emptyList(), @com.mapbox.maps.MapboxExperimental java.util.List<java.lang.String> nodeOverrides = emptyList(), @com.mapbox.maps.MapboxExperimental com.mapbox.maps.plugin.ModelElevationReference modelElevationReference = com.mapbox.maps.plugin.ModelElevationReference.GROUND);
10911092
ctor public LocationPuck3D(String modelUri, java.util.List<java.lang.Float> position = listOf(0.0, 0.0), float modelOpacity = 1f, java.util.List<java.lang.Float> modelScale = listOf(1.0, 1.0, 1.0), String? modelScaleExpression = null, java.util.List<java.lang.Float> modelTranslation = listOf(0.0, 0.0, 0.0), java.util.List<java.lang.Float> modelRotation = listOf(0.0, 0.0, 90.0), @com.mapbox.maps.MapboxExperimental boolean modelCastShadows = true, @com.mapbox.maps.MapboxExperimental boolean modelReceiveShadows = true, @com.mapbox.maps.MapboxExperimental com.mapbox.maps.plugin.ModelScaleMode modelScaleMode = com.mapbox.maps.plugin.ModelScaleMode.VIEWPORT, float modelEmissiveStrength = 1f, String? modelEmissiveStrengthExpression = null, String? modelOpacityExpression = null, String? modelRotationExpression = null, int modelColor = Color.parseColor("#ffffff"), String? modelColorExpression = null, float modelColorMixIntensity = 0f, String? modelColorMixIntensityExpression = null, @com.mapbox.maps.MapboxExperimental java.util.List<java.lang.String> materialOverrides = emptyList(), @com.mapbox.maps.MapboxExperimental java.util.List<java.lang.String> nodeOverrides = emptyList());
10921093
ctor public LocationPuck3D(String modelUri, java.util.List<java.lang.Float> position = listOf(0.0, 0.0), float modelOpacity = 1f, java.util.List<java.lang.Float> modelScale = listOf(1.0, 1.0, 1.0), String? modelScaleExpression = null, java.util.List<java.lang.Float> modelTranslation = listOf(0.0, 0.0, 0.0), java.util.List<java.lang.Float> modelRotation = listOf(0.0, 0.0, 90.0), @com.mapbox.maps.MapboxExperimental boolean modelCastShadows = true, @com.mapbox.maps.MapboxExperimental boolean modelReceiveShadows = true, @com.mapbox.maps.MapboxExperimental com.mapbox.maps.plugin.ModelScaleMode modelScaleMode = com.mapbox.maps.plugin.ModelScaleMode.VIEWPORT, float modelEmissiveStrength = 1f, String? modelEmissiveStrengthExpression = null, String? modelOpacityExpression = null, String? modelRotationExpression = null, int modelColor = Color.parseColor("#ffffff"), String? modelColorExpression = null, float modelColorMixIntensity = 0f, String? modelColorMixIntensityExpression = null, @com.mapbox.maps.MapboxExperimental java.util.List<java.lang.String> materialOverrides = emptyList());
10931094
ctor public LocationPuck3D(String modelUri, java.util.List<java.lang.Float> position = listOf(0.0, 0.0), float modelOpacity = 1f, java.util.List<java.lang.Float> modelScale = listOf(1.0, 1.0, 1.0), String? modelScaleExpression = null, java.util.List<java.lang.Float> modelTranslation = listOf(0.0, 0.0, 0.0), java.util.List<java.lang.Float> modelRotation = listOf(0.0, 0.0, 90.0), @com.mapbox.maps.MapboxExperimental boolean modelCastShadows = true, @com.mapbox.maps.MapboxExperimental boolean modelReceiveShadows = true, @com.mapbox.maps.MapboxExperimental com.mapbox.maps.plugin.ModelScaleMode modelScaleMode = com.mapbox.maps.plugin.ModelScaleMode.VIEWPORT, float modelEmissiveStrength = 1f, String? modelEmissiveStrengthExpression = null, String? modelOpacityExpression = null, String? modelRotationExpression = null, int modelColor = Color.parseColor("#ffffff"), String? modelColorExpression = null, float modelColorMixIntensity = 0f, String? modelColorMixIntensityExpression = null);
@@ -1121,20 +1122,22 @@ package com.mapbox.maps.plugin {
11211122
method public java.util.List<java.lang.String> component19();
11221123
method public java.util.List<java.lang.Float> component2();
11231124
method public java.util.List<java.lang.String> component20();
1125+
method public com.mapbox.maps.plugin.ModelElevationReference component21();
11241126
method public float component3();
11251127
method public java.util.List<java.lang.Float> component4();
11261128
method public String? component5();
11271129
method public java.util.List<java.lang.Float> component6();
11281130
method public java.util.List<java.lang.Float> component7();
11291131
method public boolean component8();
11301132
method public boolean component9();
1131-
method public com.mapbox.maps.plugin.LocationPuck3D copy(String modelUri, java.util.List<java.lang.Float> position, float modelOpacity, java.util.List<java.lang.Float> modelScale, String? modelScaleExpression, java.util.List<java.lang.Float> modelTranslation, java.util.List<java.lang.Float> modelRotation, boolean modelCastShadows, boolean modelReceiveShadows, com.mapbox.maps.plugin.ModelScaleMode modelScaleMode, float modelEmissiveStrength, String? modelEmissiveStrengthExpression, String? modelOpacityExpression, String? modelRotationExpression, int modelColor, String? modelColorExpression, float modelColorMixIntensity, String? modelColorMixIntensityExpression, java.util.List<java.lang.String> materialOverrides, java.util.List<java.lang.String> nodeOverrides);
1133+
method public com.mapbox.maps.plugin.LocationPuck3D copy(String modelUri, java.util.List<java.lang.Float> position, float modelOpacity, java.util.List<java.lang.Float> modelScale, String? modelScaleExpression, java.util.List<java.lang.Float> modelTranslation, java.util.List<java.lang.Float> modelRotation, boolean modelCastShadows, boolean modelReceiveShadows, com.mapbox.maps.plugin.ModelScaleMode modelScaleMode, float modelEmissiveStrength, String? modelEmissiveStrengthExpression, String? modelOpacityExpression, String? modelRotationExpression, int modelColor, String? modelColorExpression, float modelColorMixIntensity, String? modelColorMixIntensityExpression, java.util.List<java.lang.String> materialOverrides, java.util.List<java.lang.String> nodeOverrides, com.mapbox.maps.plugin.ModelElevationReference modelElevationReference);
11321134
method public java.util.List<java.lang.String> getMaterialOverrides();
11331135
method public boolean getModelCastShadows();
11341136
method public int getModelColor();
11351137
method public String? getModelColorExpression();
11361138
method public float getModelColorMixIntensity();
11371139
method public String? getModelColorMixIntensityExpression();
1140+
method public com.mapbox.maps.plugin.ModelElevationReference getModelElevationReference();
11381141
method public float getModelEmissiveStrength();
11391142
method public String? getModelEmissiveStrengthExpression();
11401143
method public float getModelOpacity();
@@ -1155,6 +1158,7 @@ package com.mapbox.maps.plugin {
11551158
method public void setModelColorExpression(String?);
11561159
method public void setModelColorMixIntensity(float);
11571160
method public void setModelColorMixIntensityExpression(String?);
1161+
method public void setModelElevationReference(com.mapbox.maps.plugin.ModelElevationReference);
11581162
method public void setModelEmissiveStrength(float);
11591163
method public void setModelEmissiveStrengthExpression(String?);
11601164
method public void setModelOpacity(float);
@@ -1175,6 +1179,7 @@ package com.mapbox.maps.plugin {
11751179
property public final String? modelColorExpression;
11761180
property public final float modelColorMixIntensity;
11771181
property public final String? modelColorMixIntensityExpression;
1182+
property public final com.mapbox.maps.plugin.ModelElevationReference modelElevationReference;
11781183
property public final float modelEmissiveStrength;
11791184
property public final String? modelEmissiveStrengthExpression;
11801185
property public final float modelOpacity;
@@ -1209,6 +1214,13 @@ package com.mapbox.maps.plugin {
12091214
method public void onStyleChanged(com.mapbox.maps.MapboxStyleManager style);
12101215
}
12111216

1217+
@com.mapbox.maps.MapboxExperimental public enum ModelElevationReference {
1218+
method public final String! getValue();
1219+
property public final String! value;
1220+
enum_constant public static final com.mapbox.maps.plugin.ModelElevationReference GROUND;
1221+
enum_constant public static final com.mapbox.maps.plugin.ModelElevationReference SEA;
1222+
}
1223+
12121224
@com.mapbox.maps.MapboxExperimental public enum ModelScaleMode {
12131225
method public final String! getValue();
12141226
property public final String! value;

0 commit comments

Comments
 (0)