Skip to content

Show existing LOIs on map while creating a new LOI - #3865

Open
cuongnt wants to merge 3 commits into
google:masterfrom
cuongnt:master
Open

Show existing LOIs on map while creating a new LOI#3865
cuongnt wants to merge 3 commits into
google:masterfrom
cuongnt:master

Conversation

@cuongnt

@cuongnt cuongnt commented Jul 30, 2026

Copy link
Copy Markdown

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

DrawAreaTaskViewModel

  • Inject LocationOfInterestRepositoryInterface and SurveyRepositoryInterface
  • Expose existingLoiFeatures: StateFlow<Set<Feature>> derived from activeSurveyFlow → getValidLois()

DrawAreaTaskMapFragment

  • renderFeatures() now combines draftArea with existingLoiFeatures

DropPinTaskViewModel

  • Same injection pattern and existingLoiFeatures flow

DropPinTaskMapFragment

  • renderFeatures() now combines pin features with existingLoiFeatures

Behaviour

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.

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.
@google-cla

google-cla Bot commented Jul 30, 2026

Copy link
Copy Markdown

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.

@cuongnt cuongnt closed this Jul 30, 2026
@cuongnt

cuongnt commented Jul 30, 2026

Copy link
Copy Markdown
Author

@cuongnt cuongnt reopened this Jul 30, 2026
@cuongnt

cuongnt commented Jul 30, 2026

Copy link
Copy Markdown
Author

ground-android-master.pdf
Unfortunately, I didn't record a screen video. I've summarized the calibration process to display the drawn polygons on the new batch drawing module in the PDF file above.

@andreia-ferreira andreia-ferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/

Comment on lines +61 to +81
/**
* 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,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of duplicating this both in DropPinTaskViewModel and DrawAreaTaskViewModel, this can be moved to BaseMapViewModel, which both fragments can later access with getMapViewModel()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a good option.

…/tasks/polygon/DrawAreaTaskMapFragment.kt

Co-authored-by: Andreia Ferreira <51242456+andreia-ferreira@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

3 participants