Skip to content

Commit 577f38e

Browse files
pengdevgithub-actions[bot]
authored andcommitted
[demo-app] Update appearances examples to showcase paint properties (#12560)
### Summary - Update Android and iOS appearances examples to demonstrate paint properties (translate, color, opacity) - Remove experimental annotations and comments — appearances are now stable - Add text labels to hotel icons to showcase text paint property changes ### Context Appearances in symbol layers now support both paint and layout properties and are no longer experimental. The existing native examples only demonstrated layout property changes (icon-image). This aligns them with the [GL-JS reference example](https://docs.mapbox.com/mapbox-gl-js/example/appearances/). GeoJSON data and layer style JSON are aligned with the GL-JS debug example (`projects/gl-js/debug/appearances.html`) — same hotel names, text layout props, base paint values, and appearance paint properties. The `hovered` appearance from GL-JS is omitted since hover doesn't apply on touch devices. ### Key Changes - **AppearancesActivity.kt**: Added text layout props, base paint section, paint properties in appearances (icon-translate, text-translate, text-color, text-halo, opacity). Added hotel names to GeoJSON. Removed experimental mentions. - **AppearancesExample.swift**: Same layer/GeoJSON updates. Removed `@_spi(Experimental)` import — all APIs used are public. - **example_descriptions.xml**: Updated description to mention paint properties. ### Validation - [x] Run Android compose-app Appearances example — verify text labels, translate on select, opacity on previously-clicked - [x] Run iOS example app Appearances example — verify same behavior cc @mapbox/maps-ios cc @mapbox/maps-android GitOrigin-RevId: 927ccada4f3bf73398702bb8923a900a5a7f4d33
1 parent 569a7cb commit 577f38e

2 files changed

Lines changed: 44 additions & 25 deletions

File tree

compose-app/src/main/java/com/mapbox/maps/compose/testapp/examples/style/AppearancesActivity.kt

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ import com.mapbox.maps.interactions.FeatureState
2727
import com.mapbox.maps.interactions.FeaturesetFeature
2828

2929
/**
30-
* Example demonstrating the experimental Appearances API for dynamic icon states.
31-
* Shows how to use appearances with feature-state to change icon images based on user interaction.
32-
* - Default: hotel icon
33-
* - Currently Selected: hotel-active icon
34-
* - Previously Clicked: hotel-clicked icon
30+
* Example demonstrating the Appearances API for dynamic icon and text states.
31+
* Shows how to use appearances with feature-state to change icon images and paint properties
32+
* based on user interaction.
33+
* - Default: hotel icon with dark label
34+
* - Currently Selected: hotel-active icon, floats up with blue label and halo
35+
* - Previously Clicked: hotel-clicked icon, dimmed
3536
*/
3637
public class AppearancesActivity : ComponentActivity() {
3738

@@ -131,11 +132,10 @@ public class AppearancesActivity : ComponentActivity() {
131132
).value!!
132133
)
133134

134-
// Add a layer to show an icon on every point with appearances
135-
// - When currentlySelected feature state is true: use "hotel-active" icon
136-
// - When hasBeenClicked feature state is true and currentlySelected is not: use "hotel-clicked" icon
137-
// - Otherwise: use the default "hotel" icon defined in layout
138-
// Appearances are experimental and subject to change in future versions
135+
// Add a symbol layer with appearances that change both layout and paint
136+
// properties based on feature state:
137+
// - "clicked": floats icon up, changes label to blue with halo
138+
// - "has-been-clicked": dims icon and label (opacity 0.45)
139139
try {
140140
style.addStyleLayer(
141141
Value.fromJson(POINTS_LAYER_JSON).value!!,
@@ -167,22 +167,41 @@ private const val POINTS_LAYER_JSON = """
167167
"layout": {
168168
"icon-allow-overlap": true,
169169
"icon-image": "hotel",
170-
"icon-size": 1.0,
171-
"icon-anchor": "center"
170+
"icon-size": 0.75,
171+
"text-field": ["get", "name"],
172+
"text-font": ["DIN Pro Medium", "Arial Unicode MS Regular"],
173+
"text-size": 12,
174+
"text-offset": [0, 1.2],
175+
"text-anchor": "top",
176+
"text-allow-overlap": true
177+
},
178+
"paint": {
179+
"text-color": "#333333",
180+
"text-halo-color": "#ffffff",
181+
"text-halo-width": 1,
182+
"icon-translate": [0, 0],
183+
"text-translate": [0, 0]
172184
},
173185
"appearances": [
174186
{
175-
"name": "currently-selected",
187+
"name": "clicked",
176188
"condition": ["boolean", ["feature-state", "currentlySelected"], false],
177189
"properties": {
178-
"icon-image": "hotel-active"
190+
"icon-image": "hotel-active",
191+
"icon-translate": [0, -12],
192+
"text-translate": [0, -12],
193+
"text-color": "#4264fb",
194+
"text-halo-color": "#c0caff",
195+
"text-halo-width": 2
179196
}
180197
},
181198
{
182199
"name": "has-been-clicked",
183200
"condition": ["boolean", ["feature-state", "hasBeenClicked"], false],
184201
"properties": {
185-
"icon-image": "hotel-clicked"
202+
"icon-image": "hotel-clicked",
203+
"icon-opacity": 0.45,
204+
"text-opacity": 0.45
186205
}
187206
}
188207
]
@@ -193,15 +212,15 @@ private const val HOTEL_GEOJSON = """
193212
{
194213
"type": "FeatureCollection",
195214
"features": [
196-
{"type": "Feature", "id": "1", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.8452993238082342, 42.100164223399275]}},
197-
{"type": "Feature", "id": "2", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.8438590191857145, 42.1004178052402]}},
198-
{"type": "Feature", "id": "3", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.844225198327564, 42.10130533369667]}},
199-
{"type": "Feature", "id": "4", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.8443594640122, 42.0990955459275]}},
200-
{"type": "Feature", "id": "5", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.8449697625811154, 42.09869705141318]}},
201-
{"type": "Feature", "id": "6", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.8471058075726603, 42.09978384873651]}},
202-
{"type": "Feature", "id": "7", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.8455739474818813, 42.10182152060625]}},
203-
{"type": "Feature", "id": "8", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.8427787800360136, 42.10039061289771]}},
204-
{"type": "Feature", "id": "9", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.8433280487479635, 42.0994396753579]}}
215+
{"type": "Feature", "id": "1", "properties": {"name": "Hotel Carlemany"}, "geometry": {"type": "Point", "coordinates": [1.8452993238082342, 42.100164223399275]}},
216+
{"type": "Feature", "id": "2", "properties": {"name": "Hotel Panorama"}, "geometry": {"type": "Point", "coordinates": [1.8438590191857145, 42.1004178052402]}},
217+
{"type": "Feature", "id": "3", "properties": {"name": "Hotel Andorra"}, "geometry": {"type": "Point", "coordinates": [1.844225198327564, 42.10130533369667]}},
218+
{"type": "Feature", "id": "4", "properties": {"name": "Hotel Plaza"}, "geometry": {"type": "Point", "coordinates": [1.8443594640122, 42.0990955459275]}},
219+
{"type": "Feature", "id": "5", "properties": {"name": "Hotel Cervol"}, "geometry": {"type": "Point", "coordinates": [1.8449697625811154, 42.09869705141318]}},
220+
{"type": "Feature", "id": "6", "properties": {"name": "Hotel Diplomatic"}, "geometry": {"type": "Point", "coordinates": [1.8471058075726603, 42.09978384873651]}},
221+
{"type": "Feature", "id": "7", "properties": {"name": "Hotel Guillem"}, "geometry": {"type": "Point", "coordinates": [1.8455739474818813, 42.10182152060625]}},
222+
{"type": "Feature", "id": "8", "properties": {"name": "Hotel Roc Blanc"}, "geometry": {"type": "Point", "coordinates": [1.8427787800360136, 42.10039061289771]}},
223+
{"type": "Feature", "id": "9", "properties": {"name": "Hotel President"}, "geometry": {"type": "Point", "coordinates": [1.8433280487479635, 42.0994396753579]}}
205224
]
206225
}
207226
"""

compose-app/src/main/res/values/example_descriptions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<string name="description_standard_style">Showcase usage of Standard style</string>
3030
<string name="description_clip_layer">Showcase the usage of clip layer.</string>
3131
<string name="description_interactions">Showcase the interactions.</string>
32-
<string name="description_appearances">Change icon images dynamically using the Appearances API with feature-state</string>
32+
<string name="description_appearances">Change icon images, text styles, and paint properties dynamically using the Appearances API with feature-state</string>
3333
<string name="description_custom_vector_icons">Dynamically style vector icons with custom colors and interactively change their size on tap</string>
3434
<string name="description_precipitations">Showcase the rain and snow effects.</string>
3535
<string name="description_color_theme">Showcase color theme.</string>

0 commit comments

Comments
 (0)