heremaps / here-sdk-examples

Android, iOS and Flutter example apps for the HERE SDK 4.x (Lite Edition, Explore Edition, Navigate Edition)
https://developer.here.com/products/here-sdk
Apache License 2.0
171 stars 135 forks source link

Multiple mapViews using recyclerview or lazycolumn #216

Closed thehrlein closed 1 year ago

thehrlein commented 1 year ago

Hey there,

in our application we have to show multiple mapViews inside one list. Until now, we used to use a recyclerview and in each viewholder one mapview was shown. Each viewholder shows some 2-line text information and by clicking the cell expands and shows the map. Clicking again collapses it. Clicking on a different viewholder expands it but collapses the one that is opened. So always only viewholder is expanded and shows the map at the time (beside of the collapsing / expanding animation where both are shown at a time). It worked but performance was not good and also had some blinking when expanding / collapsing the map.

Now, we switched to Jetpack compose and I am trying to show them in a lazy list but it got worse.

Is there any chance you include an example how to use multiple mapviews inside one list (either recyclerview or better lazycolum)? I am not how I should deal with the mapview lifecyle and if i should try to share one (or better two because of the expanding/collapsing thing) mapviews across all composables inside my lazycolumn and where is the correct place to "reset" the map and initialize with the data of the new expanding composable tile.

If any other developer did this before, I would be very happy if you could share your solution or if the HERE SDK Team can provide an example.

romandanylyk commented 1 year ago

Hey, I'm not from HERE, but it feels like showing a mapView in a recyclerView (or LazyColum) is quite ineffective, since the mapView is a heavy view to show and it has to be initialized every single time - the bad performance you are encountering is not a surprise.

If the map you have to show in an expanded item shows something specific and does not have to be interactive I would recommend replacing it with ImageView showing a static map instead. It might point the user to some specific coordinate and have a marker on it. While you can still have an interactive mapView in one of your 'details' screens, which will only have a single mapView at a time. That will increase your performance significantly.

https://developer.here.com/documentation/map-image/dev_guide/topics/display-options.html

thehrlein commented 1 year ago

Hey @romandanylyk, thank you for your reply. Yes I know, but my client insists on having a customizable map inside each item in the list. It is indeed not responsive (only showing a route but no interaction) but we have to use some custom map markers matching their brand design and colors, which is not possible with the map image api. The flags the api offers regarding coloring and marker style is very limited.

HERE-SDK-Support-Team commented 1 year ago

Hi @thehrlein, thanks for your suggestion. We have a Jetpack usage example in this question: https://github.com/heremaps/here-sdk-examples/issues/212. However, it does not answer your question with multiple map views in a list. The idea from @romandanylyk to show static images is not bad, and also the HERE SDK has an API to create a static image from a map view: https://developer.here.com/documentation/android-sdk-navigate/4.13.1.0/api_reference/com/here/sdk/mapview/MapView.TakeScreenshotCallback.html

Anyway, if only one map view is active at a time, then it would be recommended to call mapView.onPause() when it is inactive - this will save resources and rendering time.

If the performance is still bad, please file a question to our support team. The performance impact depends on many factors, but it should not be that bad if you have initialized the HERE SDK beforehand once and if you have create the map view instances as well. Either way, the HERE SDK definitely supports multiple map view instances and this should actually work. We do not have plans to host a dedicated example for a list with multiple map views, but if you experience any issues with this, please contact us.

Hope this helps!