Show existing LOIs on map while creating a new LOI - #3865
Conversation
When a user draws a new polygon (DrawAreaTaskMapFragment) or drops a new pin (DropPinTaskMapFragment), already-saved LOIs are now rendered as background features on the map for spatial context. Changes: - DrawAreaTaskViewModel: inject LoiRepository + SurveyRepository; expose existingLoiFeatures StateFlow mapped from activeSurveyFlow - DrawAreaTaskMapFragment: combine draftArea with existingLoiFeatures in renderFeatures() so both are rendered together - DropPinTaskViewModel: same injection and existingLoiFeatures flow - DropPinTaskMapFragment: combine pin features with existingLoiFeatures Existing LOIs are rendered with Feature.Type.LOCATION_OF_INTEREST, non-clusterable and non-selected to distinguish them from the active drawing target.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
ground-android-master.pdf |
andreia-ferreira
left a comment
There was a problem hiding this comment.
thanks for taking this up! Left some comments to improve the implementation, also could you please add some unit tests for the new logic? 🙏
the pipeline seems to be failing because the CLA hasn't been signed, you can do that here: https://cla.developers.google.com/
| /** | ||
| * Features representing LOIs that already exist in the survey, shown as background context while | ||
| * the user drops a new pin. | ||
| */ | ||
| val existingLoiFeatures: StateFlow<Set<Feature>> = | ||
| surveyRepository.activeSurveyFlow | ||
| .filterNotNull() | ||
| .flatMapLatest { survey -> loiRepository.getValidLois(survey) } | ||
| .map { lois -> lois.map { loi -> loi.toExistingFeature() }.toSet() } | ||
| .stateIn(viewModelScope, WhileSubscribed(5_000), emptySet()) | ||
|
|
||
| private fun LocationOfInterest.toExistingFeature(): Feature = | ||
| Feature( | ||
| id = id, | ||
| type = Feature.Type.LOCATION_OF_INTEREST, | ||
| geometry = geometry, | ||
| style = Feature.Style(job.getDefaultColor()), | ||
| clusterable = false, | ||
| selected = false, | ||
| ) | ||
|
|
There was a problem hiding this comment.
instead of duplicating this both in DropPinTaskViewModel and DrawAreaTaskViewModel, this can be moved to BaseMapViewModel, which both fragments can later access with getMapViewModel()
…/tasks/polygon/DrawAreaTaskMapFragment.kt Co-authored-by: Andreia Ferreira <51242456+andreia-ferreira@users.noreply.github.com>
Summary
When a user draws a new polygon or drops a new pin, already-saved LOIs are now rendered as background features on the map for spatial context.
Changes
DrawAreaTaskViewModelLocationOfInterestRepositoryInterfaceandSurveyRepositoryInterfaceexistingLoiFeatures: StateFlow<Set<Feature>>derived fromactiveSurveyFlow → getValidLois()DrawAreaTaskMapFragmentrenderFeatures()now combinesdraftAreawithexistingLoiFeaturesDropPinTaskViewModelexistingLoiFeaturesflowDropPinTaskMapFragmentrenderFeatures()now combines pin features withexistingLoiFeaturesBehaviour
Existing LOIs are rendered with
Feature.Type.LOCATION_OF_INTEREST,clusterable = false,selected = false— visually consistent with the home map but non-interactive during data collection.Testing
Existing Hilt test infrastructure injects real repositories; no test file changes required.