Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clustering #75

Closed
Nbzh opened this issue Nov 22, 2024 · 1 comment
Closed

Clustering #75

Nbzh opened this issue Nov 22, 2024 · 1 comment

Comments

@Nbzh
Copy link

Nbzh commented Nov 22, 2024

Hello,

I'm trying to implement a map with markers and clusters. I 'm using a Protomaps style.

I'm following this example : https://github.com/maplibre/maplibre-plugins-android/blob/main/app/src/main/java/org/maplibre/android/plugins/testapp/activity/annotation/ClusterSymbolActivity.java

but I can't make it work. I can display my 157 markers but if I add the ClusterOptions there is nothing anymore displayed on the map

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        MapLibre.getInstance(this)
        binding = ActivityTestMaplibBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.mapView.onCreate(savedInstanceState)
        val clusterOptions = ClusterOptions()
            .withColorLevels(
                arrayOf(
                    Pair(100, Color.RED),
                    Pair(50, Color.BLUE),
                    Pair(0, Color.GREEN)
                )
            )
        binding.mapView.getMapAsync { map ->
            map.setStyle(
                Style.Builder()
                    .fromJson(getJsonStringFromAssets(this, "map/styles.json"))
            ) { style ->
                style.addImages(
                    hashMapOf(
                        "ic_associated" to BitmapFactory.decodeResource(
                            getResources(),
                            R.drawable.ic_marker_lumio
                        ),
                        "ic_not_associated" to BitmapFactory.decodeResource(
                            getResources(),
                            R.drawable.ic_marker_no_lumio
                        ),
                        "ic_malfunction_new" to BitmapFactory.decodeResource(
                            getResources(),
                            R.drawable.ic_marker_malfunction_new
                        ),
                        "ic_malfunction_qualified" to BitmapFactory.decodeResource(
                            getResources(),
                            R.drawable.ic_marker_malfunction_qualified
                        ),
                        "ic_malfunction_solved" to BitmapFactory.decodeResource(
                            getResources(),
                            R.drawable.ic_marker_malfunction_resolved
                        )
                    )
                )
                symbolManager =
                    SymbolManager(binding.mapView, map, style, null, null, clusterOptions)
                symbolManager.setIconAllowOverlap(true)
                symbolManager.iconIgnorePlacement = true
            }
            map.cameraPosition = CameraPosition.Builder().target(LatLng(0.0, 0.0)).zoom(1.0).build()
            viewModel.fullParksWithStreetlamps.observe(this) { parks ->
                lifecycleScope.launch(Dispatchers.IO) {
                    val symbolOptions = mutableListOf<SymbolOptions>()
                    parks.mapNotNull { p -> if (p.park.isBusiness) p.park.id else null }.let {
                        viewModel.selectParkStreetlamps(it).let { mapStreetlamps ->
                            mapStreetlamps.map { s ->
                                symbolOptions.add(
                                    SymbolOptions()
                                        .withGeometry(Point.fromLngLat(s.longitude, s.latitude))
                                        .withIconImage(s.getMarkerIconName())
                                )
                            }
                        }
                    }
                    symbolManager.create(symbolOptions).also {
                        Timber.tag("MapLibTest").d("symbols: ${it.count()}") //157
                    }
                }
            }
        }
    }

Second question : is it possible to create groups of cluster ? Having some markers in the blue clusters and others in green clusters

Thank you for your help.

@Nbzh
Copy link
Author

Nbzh commented Nov 22, 2024

After some researches, the issue is linked : #60

@Nbzh Nbzh closed this as completed Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant