@@ -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,42 @@ let pointSource = ShapeSource(identifier: "points") {
7688 . ignoresSafeArea ( . all)
7789}
7890
91+ #Preview( " Clustered Circles with Symbols " ) {
92+ @State var camera = MapViewCamera . center ( CLLocationCoordinate2D ( latitude: 48.2082 , longitude: 16.3719 ) , zoom: 5 , direction: 0 )
93+ return MapView ( styleURL: demoTilesURL, camera: $camera) {
94+ // Clusters pins when they would touch
95+
96+ // Cluster == YES shows only those pins that are clustered, using .text
97+ CircleStyleLayer ( identifier: " simple-circles-clusters " , source: clustered)
98+ . radius ( 16 )
99+ . color ( . systemRed)
100+ . strokeWidth ( 2 )
101+ . strokeColor ( . white)
102+ . predicate ( NSPredicate ( format: " cluster == YES " ) )
103+
104+ SymbolStyleLayer ( identifier: " simple-symbols-clusters " , source: clustered)
105+ . textColor ( . white)
106+ . text ( expression: NSExpression ( format: " CAST(point_count, 'NSString') " ) )
107+ . predicate ( NSPredicate ( format: " cluster == YES " ) )
108+
109+
110+ // Cluster != YES shows only those pins that are not clustered, using an icon
111+ CircleStyleLayer ( identifier: " simple-circles-non-clusters " , source: clustered)
112+ . radius ( 16 )
113+ . color ( . systemRed)
114+ . strokeWidth ( 2 )
115+ . strokeColor ( . white)
116+ . predicate ( NSPredicate ( format: " cluster != YES " ) )
117+
118+ SymbolStyleLayer ( identifier: " simple-symbols-non-clusters " , source: clustered)
119+ . iconImage ( UIImage ( systemName: " mappin " ) !. withRenderingMode ( . alwaysTemplate) )
120+ . iconColor ( . white)
121+ . predicate ( NSPredicate ( format: " cluster != YES " ) )
122+
123+ }
124+ . ignoresSafeArea ( . all)
125+ }
126+
79127// TODO: Fixme
80128// #Preview("Multiple Symbol Icons") {
81129// MapView(styleURL: demoTilesURL) {
0 commit comments