Skip to content

Commit 723458e

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 22f52e6 commit 723458e

1 file changed

Lines changed: 48 additions & 21 deletions

File tree

Sources/Examples/SwiftUI Examples/AppearancesExample.swift

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import SwiftUI
2-
@_spi(Experimental) import MapboxMaps
3-
4-
/// Example demonstrating the experimental Appearances API for dynamic icon states.
5-
/// Shows how to use appearances with feature-state to change icon images based on user interaction.
6-
/// - Default: hotel icon
7-
/// - Currently Selected: hotel-active icon
8-
/// - Previously Clicked: hotel-clicked icon
2+
import MapboxMaps
3+
4+
/// Example demonstrating the Appearances API for dynamic icon and text states.
5+
/// Shows how to use appearances with feature-state to change icon images and paint properties
6+
/// based on user interaction.
7+
/// - Default: hotel icon with dark label
8+
/// - Currently Selected: hotel-active icon, floats up with blue label and halo
9+
/// - Previously Clicked: hotel-clicked icon, dimmed
910
struct AppearancesExample: View {
1011
private static let currentlySelectedKey = "currentlySelected"
1112
private static let hasBeenClickedKey = "hasBeenClicked"
@@ -100,15 +101,15 @@ struct AppearancesExample: View {
100101
"data": [
101102
"type": "FeatureCollection",
102103
"features": [
103-
["type": "Feature", "id": 1, "properties": [:], "geometry": ["type": "Point", "coordinates": [1.8452993238082342, 42.100164223399275]]],
104-
["type": "Feature", "id": 2, "properties": [:], "geometry": ["type": "Point", "coordinates": [1.8438590191857145, 42.1004178052402]]],
105-
["type": "Feature", "id": 3, "properties": [:], "geometry": ["type": "Point", "coordinates": [1.844225198327564, 42.10130533369667]]],
106-
["type": "Feature", "id": 4, "properties": [:], "geometry": ["type": "Point", "coordinates": [1.8443594640122, 42.0990955459275]]],
107-
["type": "Feature", "id": 5, "properties": [:], "geometry": ["type": "Point", "coordinates": [1.8449697625811154, 42.09869705141318]]],
108-
["type": "Feature", "id": 6, "properties": [:], "geometry": ["type": "Point", "coordinates": [1.8471058075726603, 42.09978384873651]]],
109-
["type": "Feature", "id": 7, "properties": [:], "geometry": ["type": "Point", "coordinates": [1.8455739474818813, 42.10182152060625]]],
110-
["type": "Feature", "id": 8, "properties": [:], "geometry": ["type": "Point", "coordinates": [1.8427787800360136, 42.10039061289771]]],
111-
["type": "Feature", "id": 9, "properties": [:], "geometry": ["type": "Point", "coordinates": [1.8433280487479635, 42.0994396753579]]]
104+
["type": "Feature", "id": 1, "properties": ["name": "Hotel Carlemany"], "geometry": ["type": "Point", "coordinates": [1.8452993238082342, 42.100164223399275]]],
105+
["type": "Feature", "id": 2, "properties": ["name": "Hotel Panorama"], "geometry": ["type": "Point", "coordinates": [1.8438590191857145, 42.1004178052402]]],
106+
["type": "Feature", "id": 3, "properties": ["name": "Hotel Andorra"], "geometry": ["type": "Point", "coordinates": [1.844225198327564, 42.10130533369667]]],
107+
["type": "Feature", "id": 4, "properties": ["name": "Hotel Plaza"], "geometry": ["type": "Point", "coordinates": [1.8443594640122, 42.0990955459275]]],
108+
["type": "Feature", "id": 5, "properties": ["name": "Hotel Cervol"], "geometry": ["type": "Point", "coordinates": [1.8449697625811154, 42.09869705141318]]],
109+
["type": "Feature", "id": 6, "properties": ["name": "Hotel Diplomatic"], "geometry": ["type": "Point", "coordinates": [1.8471058075726603, 42.09978384873651]]],
110+
["type": "Feature", "id": 7, "properties": ["name": "Hotel Guillem"], "geometry": ["type": "Point", "coordinates": [1.8455739474818813, 42.10182152060625]]],
111+
["type": "Feature", "id": 8, "properties": ["name": "Hotel Roc Blanc"], "geometry": ["type": "Point", "coordinates": [1.8427787800360136, 42.10039061289771]]],
112+
["type": "Feature", "id": 9, "properties": ["name": "Hotel President"], "geometry": ["type": "Point", "coordinates": [1.8433280487479635, 42.0994396753579]]]
112113
]
113114
]
114115
]
@@ -121,27 +122,53 @@ struct AppearancesExample: View {
121122
return
122123
}
123124

124-
// Add a layer to show an icon on every point
125+
// Add a symbol layer with appearances that change both layout and paint properties:
126+
// - Currently selected: hotel-active icon, floats up, blue label with halo
127+
// - Previously clicked: hotel-clicked icon, dimmed (opacity 0.45)
128+
// - Default: hotel icon with dark label
125129
let layerJSON: [String: Any] = [
126130
"id": "points",
127131
"type": "symbol",
128132
"source": "points",
129133
"layout": [
130134
"icon-allow-overlap": true,
131135
"icon-image": "hotel",
132-
"icon-size": 0.75
136+
"icon-size": 0.75,
137+
"text-field": ["get", "name"],
138+
"text-font": ["DIN Pro Medium", "Arial Unicode MS Regular"],
139+
"text-size": 12,
140+
"text-offset": [0, 1.2],
141+
"text-anchor": "top",
142+
"text-allow-overlap": true
143+
],
144+
"paint": [
145+
"text-color": "#333333",
146+
"text-halo-color": "#ffffff",
147+
"text-halo-width": 1,
148+
"icon-translate": [0, 0],
149+
"text-translate": [0, 0]
133150
],
134-
// appearances are experimental and subject to change in future versions
135151
"appearances": [
136152
[
137153
"name": "clicked",
138154
"condition": ["boolean", ["feature-state", Self.currentlySelectedKey], false],
139-
"properties": ["icon-image": "hotel-active"]
155+
"properties": [
156+
"icon-image": "hotel-active",
157+
"icon-translate": [0, -12],
158+
"text-translate": [0, -12],
159+
"text-color": "#4264fb",
160+
"text-halo-color": "#c0caff",
161+
"text-halo-width": 2
162+
] as [String: Any]
140163
],
141164
[
142165
"name": "has-been-clicked",
143166
"condition": ["boolean", ["feature-state", Self.hasBeenClickedKey], false],
144-
"properties": ["icon-image": "hotel-clicked"]
167+
"properties": [
168+
"icon-image": "hotel-clicked",
169+
"icon-opacity": 0.45,
170+
"text-opacity": 0.45
171+
] as [String: Any]
145172
]
146173
]
147174
]

0 commit comments

Comments
 (0)