@@ -216,23 +216,26 @@ class MapFragment : Fragment() {
216216 }
217217
218218 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
219- val merchantSourceAndLayers = createMerchantsSourceAndLayers(
219+ val merchantLayers = createMerchantsSourceAndLayers(
220220 markerBackgroundColor = prefs.markerBackgroundColor(requireContext()),
221221 markerBadgeBackgroundColor = prefs.badgeBackgroundColor(requireContext()),
222222 markerBadgeTextColor = prefs.badgeTextColor(requireContext()),
223223 usingOpenFreeMap = usingOpenFreeMap(),
224224 )
225-
226- merchantsSource = merchantSourceAndLayers.first
227-
225+ val eventLayers = createEventLayers(
226+ markerBackgroundColor = prefs.markerBackgroundColor(requireContext()),
227+ usingOpenFreeMap = usingOpenFreeMap(),
228+ )
229+ merchantsSource = merchantLayers.first
230+ eventsSource = eventLayers.first
228231 binding.map.getMapAsync { map ->
229232 map.getStyle { style ->
230- style.addSource(merchantSourceAndLayers.first)
231- merchantSourceAndLayers.second.forEach { style.addLayer(it) }
233+ style.addSource(merchantLayers.first)
234+ merchantLayers.second.forEach { style.addLayer(it) }
235+ style.addSource(eventLayers.first)
236+ eventLayers.second.forEach { style.addLayer(it) }
232237 }
233238 }
234-
235- initEventsMap()
236239 initExchangesMap()
237240
238241 initSearchBar(binding)
@@ -767,93 +770,6 @@ class MapFragment : Fragment() {
767770 private lateinit var eventsSource: GeoJsonSource
768771 private lateinit var exchangesSource: GeoJsonSource
769772
770- private fun initEventsMap () {
771- val eventsSource = GeoJsonSource (
772- " eventsSource" ,
773- EMPTY_GEOJSON ,
774- GeoJsonOptions ()
775- .withCluster(true )
776- .withClusterMaxZoom(14 )
777- .withClusterRadius(30 )
778- )
779-
780- val eventsClusterBackgroundLayer by lazy {
781- CircleLayer (" eventsClusterBackground" , eventsSource.id).apply {
782- setProperties(
783- PropertyFactory .circleColor(prefs.markerBackgroundColor(requireContext())),
784- PropertyFactory .circleRadius(23f ),
785- )
786- val pointCount = Expression .toNumber(Expression .get(" point_count" ))
787- setFilter(
788- Expression .all(
789- Expression .has(" point_count" ),
790- Expression .gte(
791- pointCount,
792- Expression .literal(1 )
793- )
794- )
795- )
796- }
797- }
798-
799- val eventsClusterCountLayer =
800- SymbolLayer (" eventsClusterCount" , eventsSource.id).apply {
801- if (usingOpenFreeMap()) {
802- setProperties(PropertyFactory .textFont(arrayOf(" Noto Sans Regular" )))
803- }
804- setProperties(
805- PropertyFactory .textField(Expression .toString(Expression .get(" point_count" ))),
806- PropertyFactory .textSize(16f ),
807- PropertyFactory .textColor(Color .WHITE ),
808- )
809- }
810-
811- val eventsLayer =
812- SymbolLayer (LAYER_EVENTS , eventsSource.id).apply {
813- setProperties(
814- PropertyFactory .iconImage(" btcmap-marker" ),
815- PropertyFactory .iconAnchor(Expression .literal(" bottom" )),
816- PropertyFactory .iconAllowOverlap(true ),
817- PropertyFactory .iconIgnorePlacement(true )
818- )
819- setFilter(
820- Expression .neq(Expression .get(" cluster" ), true )
821- )
822- }
823-
824- val eventsCategoryIconsLayer =
825- SymbolLayer (LAYER_EVENTS_CATEGORY_ICONS , eventsSource.id).apply {
826- setProperties(
827- PropertyFactory .iconImage(" marker-icon-event" ),
828- PropertyFactory .iconAnchor(ICON_ANCHOR_CENTER ),
829- PropertyFactory .iconOffset(
830- arrayOf(
831- 0f ,
832- ICON_OFFSET_Y
833- )
834- ),
835- PropertyFactory .iconAllowOverlap(true ),
836- PropertyFactory .iconIgnorePlacement(true )
837- )
838- setFilter(
839- Expression .neq(Expression .get(" cluster" ), true )
840- )
841- }
842-
843- binding.map.getMapAsync { map ->
844- map.getStyle { style ->
845- style.addSource(eventsSource)
846-
847- style.addLayer(eventsClusterBackgroundLayer)
848- style.addLayer(eventsClusterCountLayer)
849- style.addLayer(eventsLayer)
850- style.addLayer(eventsCategoryIconsLayer)
851- }
852- }
853-
854- this .eventsSource = eventsSource
855- }
856-
857773 private fun initExchangesMap () {
858774 val exchangesSource = GeoJsonSource (
859775 " exchangesSource" ,
0 commit comments