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

Marker size when changing the zoom level #25

Closed
sana-20 opened this issue May 26, 2021 · 3 comments
Closed

Marker size when changing the zoom level #25

sana-20 opened this issue May 26, 2021 · 3 comments

Comments

@sana-20
Copy link

sana-20 commented May 26, 2021

Hi Peter.

I’ve been developing metro app using your library and I added multiple markers in the map.
But I come across the problem that some markers are overlapped as you can see below images.

What I want is changing the size of a marker along with the zoom level of the map or replace the marker image with other size. Say, if the map is zoomed out, the marker would be getting smaller so a user can click each marker precisely.

It would be great if you have any advice for solving this problem.

zoom_inzoom_out

@p-lr
Copy link
Owner

p-lr commented May 26, 2021

Hi @sana-20

Assuming your marker is a custom view, you need to scale it in your onDraw() overload.
Here is an example, which draws a line between two points on the map. The line needs to be redrawn when the scale changes, just like your custom markers. You can see that all informations needed (scale, scroll, rotation) is taken from a ReferentialData instance.

To get the updated ReferentialData when e.g the scale changes, you need to use the addReferentialLister API on your MapView (see below the documentation of this API):

/**
 * Add a [ReferentialListener] to the MapView. This [ReferentialListener] will be notified of any
 * change of scale, rotation angle, or rotation pivot point.
 * Using this API, the MapView holds a reference on the provided [ReferentialListener] instance.
 * Don't forget to remove it when it's no longer needed, using [removeReferentialOwner].
 */
 fun addReferentialListener(listener: ReferentialListener) {
    listener.onReferentialChanged(referentialData)
    refListenerList.add(listener)
 }

@sana-20
Copy link
Author

sana-20 commented May 28, 2021

Hi @peterLaurence. As your explanation, I changed my custom marker class and added addReferentialListener in mapView, then I called resizeMarker() in onReferentialChanged.
It works as intended now. Thanks for your help.

@p-lr
Copy link
Owner

p-lr commented May 28, 2021

Great!
One day, when you decide to migrate to Jetpack Compose, there will be a MapCompose library ready: https://github.com/peterLaurence/MapCompose
For now, it's too early (Jetpack Compose is in beta).

@p-lr p-lr closed this as completed May 28, 2021
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

2 participants