@@ -21,6 +21,18 @@ let pointSource = ShapeSource(identifier: "points") {
2121 }
2222}
2323
24+ @MainActor
25+ let clustered = ShapeSource ( identifier: " points " , options: [ . clustered: true , . clusterRadius: 44 ] ) {
26+ // Uses the DSL to quickly construct point features inline
27+ MLNPointFeature ( coordinate: CLLocationCoordinate2D ( latitude: 48.2082 , longitude: 16.3719 ) )
28+
29+ MLNPointFeature ( coordinate: CLLocationCoordinate2D ( latitude: 48.3082 , longitude: 16.3719 ) )
30+
31+ MLNPointFeature ( coordinate: CLLocationCoordinate2D ( latitude: 48.2082 , longitude: 16.9719 ) )
32+
33+ MLNPointFeature ( coordinate: CLLocationCoordinate2D ( latitude: 48.0082 , longitude: 17.9719 ) )
34+ }
35+
2436#Preview( " Rose Tint " ) {
2537 MapView ( styleURL: demoTilesURL) {
2638 // Silly example: a background layer on top of everything to create a tint effect
@@ -76,6 +88,44 @@ let pointSource = ShapeSource(identifier: "points") {
7688 . ignoresSafeArea ( . all)
7789}
7890
91+ #Preview( " Clustered Circles with Symbols " ) {
92+ @State var camera = MapViewCamera . center (
93+ CLLocationCoordinate2D ( latitude: 48.2082 , longitude: 16.3719 ) ,
94+ zoom: 5 ,
95+ direction: 0
96+ )
97+ return MapView ( styleURL: demoTilesURL, camera: $camera) {
98+ // Clusters pins when they would touch
99+
100+ // Cluster == YES shows only those pins that are clustered, using .text
101+ CircleStyleLayer ( identifier: " simple-circles-clusters " , source: clustered)
102+ . radius ( 16 )
103+ . color ( . systemRed)
104+ . strokeWidth ( 2 )
105+ . strokeColor ( . white)
106+ . predicate ( NSPredicate ( format: " cluster == YES " ) )
107+
108+ SymbolStyleLayer ( identifier: " simple-symbols-clusters " , source: clustered)
109+ . textColor ( . white)
110+ . text ( expression: NSExpression ( format: " CAST(point_count, 'NSString') " ) )
111+ . predicate ( NSPredicate ( format: " cluster == YES " ) )
112+
113+ // Cluster != YES shows only those pins that are not clustered, using an icon
114+ CircleStyleLayer ( identifier: " simple-circles-non-clusters " , source: clustered)
115+ . radius ( 16 )
116+ . color ( . systemRed)
117+ . strokeWidth ( 2 )
118+ . strokeColor ( . white)
119+ . predicate ( NSPredicate ( format: " cluster != YES " ) )
120+
121+ SymbolStyleLayer ( identifier: " simple-symbols-non-clusters " , source: clustered)
122+ . iconImage ( UIImage ( systemName: " mappin " ) !. withRenderingMode ( . alwaysTemplate) )
123+ . iconColor ( . white)
124+ . predicate ( NSPredicate ( format: " cluster != YES " ) )
125+ }
126+ . ignoresSafeArea ( . all)
127+ }
128+
79129// TODO: Fixme
80130// #Preview("Multiple Symbol Icons") {
81131// MapView(styleURL: demoTilesURL) {
0 commit comments