Skip to content

New toolbar button: Center on user's geolocation#626

Merged
gjmooney merged 15 commits intogeojupyter:mainfrom
HaudinFlorence:get_geolocation_and_recenter_the_map
Apr 16, 2025
Merged

New toolbar button: Center on user's geolocation#626
gjmooney merged 15 commits intogeojupyter:mainfrom
HaudinFlorence:get_geolocation_and_recenter_the_map

Conversation

@HaudinFlorence
Copy link
Contributor

@HaudinFlorence HaudinFlorence commented Apr 11, 2025

Description

This PR adds logics for getting the geolocation and centering the map on it. Changes includes adding:

  • a new command button in the toolbar with a target icon
  • a new command getGeolocation for getting the geolocation of the user using the geolocation API from Chrome
  • a geolocation attribute and a geolocationChanged signal to the JupyterGISModel
Screencast.From.2025-04-16.12-22-07.mp4

📚 Documentation preview: https://jupytergis--626.org.readthedocs.build/en/626/
💡 JupyterLite preview: https://jupytergis--626.org.readthedocs.build/en/626/lite

@github-actions
Copy link
Contributor

Binder 👈 Launch a Binder on branch HaudinFlorence/jupytergis/get_geolocation_and_recenter_the_map

@HaudinFlorence HaudinFlorence force-pushed the get_geolocation_and_recenter_the_map branch 3 times, most recently from 2e6c34b to d2ed785 Compare April 11, 2025 16:28
@HaudinFlorence HaudinFlorence marked this pull request as draft April 11, 2025 16:30
@SylvainCorlay
Copy link
Contributor

This looks fine with me.

Small nitpick: it seems that when we reach the maximum zoom level after clicking multiple times, it circles back to the minimum zoom level.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 12, 2025

Integration tests report: appsharing.space

@HaudinFlorence
Copy link
Contributor Author

HaudinFlorence commented Apr 12, 2025

This looks fine with me.

Small nitpick: it seems that when we reach the maximum zoom level after clicking multiple times, it circles back to the minimum zoom level.

Yes. That a choice I made but I can change this. And do nothing instead of centering and setting the zoom to 0. Here is the current implementation:

private _handleGeolocationChanged(
    sender: any,
    newPosition: JgisCoordinates
  ): void {
    const view = this._Map.getView();
    const zoom = view.getZoom();
    if (zoom !== undefined && zoom + 2 < 20) {
      this._moveToPosition(newPosition, zoom + 2);
    } else {
      this._moveToPosition(newPosition, 0);
    }
  }

@mfisher87 mfisher87 changed the title Get geolocation and recenter the map Get user's geolocation and recenter the map Apr 12, 2025
@mfisher87 mfisher87 changed the title Get user's geolocation and recenter the map New toolbar button: Get user's geolocation and recenter the map Apr 12, 2025
@mfisher87 mfisher87 changed the title New toolbar button: Get user's geolocation and recenter the map New toolbar button: Zoom to user's geolocation Apr 12, 2025
@gjmooney gjmooney added the enhancement New feature or request label Apr 14, 2025
@SylvainCorlay
Copy link
Contributor

Yes. That a choice I made but I can change this. And do nothing instead of centering and setting the zoom to 0. Here is the current implementation:

Maybe we should just center the map at the current location and not change the zoom level.

@HaudinFlorence
Copy link
Contributor Author

Yes. That a choice I made but I can change this. And do nothing instead of centering and setting the zoom to 0. Here is the current implementation:

Maybe we should just center the map at the current location and not change the zoom level.

Thanks for your suggestion @SylvainCorlay . It has been taken into account

@HaudinFlorence HaudinFlorence force-pushed the get_geolocation_and_recenter_the_map branch from 6b8a6d0 to 5aed8da Compare April 14, 2025 12:58
@HaudinFlorence HaudinFlorence marked this pull request as ready for review April 14, 2025 12:59
@HaudinFlorence HaudinFlorence force-pushed the get_geolocation_and_recenter_the_map branch from 1771158 to a498331 Compare April 14, 2025 13:02
@arjxn-py
Copy link
Member

Ahh there are more failures, the above import error was just one of them
I'm quickly looking at them.

@HaudinFlorence
Copy link
Contributor Author

Bot please update snapshots

1 similar comment
@arjxn-py
Copy link
Member

Bot please update snapshots

@HaudinFlorence HaudinFlorence force-pushed the get_geolocation_and_recenter_the_map branch from 018731e to ab3ab6d Compare April 14, 2025 15:12
@arjxn-py
Copy link
Member

Bot please update snapshots

@HaudinFlorence HaudinFlorence force-pushed the get_geolocation_and_recenter_the_map branch 5 times, most recently from c00d2f3 to c36736a Compare April 15, 2025 16:39
- a new command button in the toolbar
- a command for getting the geolocation of the user
- a geolocation attribute and a geolocationChanged signal to the JupyterGISModel
- centering and zooming around the geolocation
Add missing import of Feature in mainView.tsx.
@HaudinFlorence HaudinFlorence force-pushed the get_geolocation_and_recenter_the_map branch from c36736a to 15ff70c Compare April 16, 2025 10:00
@HaudinFlorence HaudinFlorence changed the title New toolbar button: Zoom to user's geolocation New toolbar button: Center on user's geolocation Apr 16, 2025
Copy link
Member

@arjxn-py arjxn-py left a comment

Choose a reason for hiding this comment

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

Thanks @HaudinFlorence, this is super awesome 🚀
Just a couple of questions and a suggestion :)

const content = galata.newContentsHelper(request);
await content.deleteDirectory('/testDir');
await content.uploadDirectory(
const uploaded = await content.uploadDirectory(
Copy link
Member

Choose a reason for hiding this comment

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

Is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is not. This is a left-over of some tests. I will remove it.


test.beforeEach(async ({ page }) => {
await page.filebrowser.open('testDir/test.jGIS');
const opened = await page.filebrowser.open('testDir/test.jGIS');
Copy link
Member

Choose a reason for hiding this comment

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

Just curious if this is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As previously explained. This is not. I will remove it.

}
});

commands.addCommand(CommandIDs.getGeolocation, {
Copy link
Member

Choose a reason for hiding this comment

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

Can you think of a scenario where we'd want to disable this button? In those cases we'd want to handle those in isEnabled

Copy link
Contributor Author

@HaudinFlorence HaudinFlorence Apr 16, 2025

Choose a reason for hiding this comment

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

You are rising an interesting point. In a version where the geolocation would be materialized by a marker on the map, we can imagine that the command is enabled only when there is no marker on the map yet. Or we could imagine a version with a toggle command toolbar button or a toggable custom layer. In any case, this PR addresses a first simple geolocation feature that will be improved in a future PR.

Co-authored-by: Arjun Verma <arjunverma.oc@gmail.com>
@arjxn-py arjxn-py requested a review from gjmooney April 16, 2025 10:28
@HaudinFlorence
Copy link
Contributor Author

@arjxn-py Thanks for the review

Copy link
Collaborator

@gjmooney gjmooney left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should probably delete this

Copy link
Collaborator

Choose a reason for hiding this comment

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

and this

HaudinFlorence and others added 2 commits April 16, 2025 12:44
Co-authored-by: Greg Mooney <gregory.mooney@quantstack.net>
@HaudinFlorence
Copy link
Contributor Author

@gjmooney Thanks for the review. I have taken all your comments into account.

@HaudinFlorence HaudinFlorence force-pushed the get_geolocation_and_recenter_the_map branch from 131f16b to efd9830 Compare April 16, 2025 11:05
@gjmooney gjmooney merged commit aa22dd6 into geojupyter:main Apr 16, 2025
14 checks passed
HaudinFlorence added a commit to HaudinFlorence/jupytergis that referenced this pull request Jan 28, 2026
* Add logics for geolocation including :
- a new command button in the toolbar
- a command for getting the geolocation of the user
- a geolocation attribute and a geolocationChanged signal to the JupyterGISModel
- centering and zooming around the geolocation

* Change the label of getGeolocation command.
Add missing import of Feature in mainView.tsx.

* Remove zooming around relocation in _handleGeolocationChanged function.

* Update target.svg fill and class properties to adapt to both themes.

* Update getGeolocation command label.

* Add a targetWithCenterIcon and replace targetIcon with this one in getGeolocation command. Rename previous svg file and related targetIcon to targetWithoutCenterIcon.

* Fix lint issues.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update packages/base/src/mainview/mainView.tsx

Co-authored-by: Arjun Verma <arjunverma.oc@gmail.com>

* Fix icon path issues

* Add test ids to the various command toolbar buttons.
Use getByTestId in geojson-layers.spec.ts.

* Update ui-tests/tests/geojson-layers.spec.ts

Co-authored-by: Arjun Verma <arjunverma.oc@gmail.com>

* Update packages/base/src/toolbar/widget.tsx

Co-authored-by: Greg Mooney <gregory.mooney@quantstack.net>

* Take review comments into account.

* Fix failing lint test.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Arjun Verma <arjunverma.oc@gmail.com>
Co-authored-by: arjxn-py <arjxn.py@gmail.com>
Co-authored-by: Greg Mooney <gregory.mooney@quantstack.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants