Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Multi event listeners for plugins development #9917

Closed
Etienne-io opened this issue Sep 5, 2017 · 7 comments
Closed

Multi event listeners for plugins development #9917

Etienne-io opened this issue Sep 5, 2017 · 7 comments
Assignees
Labels
Android Mapbox Maps SDK for Android

Comments

@Etienne-io
Copy link

I am developing a plugin for mapbox.

The amount of data is huge and I can't just display everything so, to make it works, I have to use the Camera listeners to know what I have to display on the map.

The problem is that if the developer using this plugin wants to listen to Mapbox Camera event, he will destroy my listeners and the plugin won't work anymore.

1- Developer instantiate plugin
2- Plugin internally set camera listener to work
3- Developer set camera listener for his use case
4- Plugin won't work anymore.

Do you have any advise on how to implement this?
Would it require the Mapview to allow multiple listeners (addIdleCameraListener instead of setIdleCameraListener) ?

Thanks,

Etienne

@Guardiola31337
Copy link
Contributor

Hey @emerciercontexeo thanks for reaching out.

Is this an Android plugin? If so, do you know that there is a Mapbox Plugins for Android repo to implement that kind of functionalities? There is where well-contained features (single-purpose libraries) built on top of the Maps SDK live. I encourage you to 👀 it and ask whatever questions you may have there.

@Etienne-io
Copy link
Author

It's an Android plugin. I had already take a look at the Plugins Repositories but I didn't find any example for my issue.

On my side, I can imagine two solutions :

The first is found in the GeoJSON plugin by passing a Listener to the plugin constructor (or using a setter on the plugin). With this, the plugin can use its own listener, consume it and call the listener provided by the developper.
But this solution is pretty weird.
Firstly, the developer have to pass a listener to the plugin to get a event provided by the map.
Secondly, if many plugins have to use the same event listener, it will be very hard to do it properly.

Another solution could be to force the developer to call the plugin listener when he use the same listener in his code. In this case, it have to be well documented to avoid support.

But, in my opinion, a plugin should be able to work alone. Without interference with the "standard" mapbox development.
We could imagine a way to dispatch an event to many plugins. Each plugin could be use the same event independently. And a developper that use a plugin won't have to worry about anything in its own code.

If necessary, I can move this discussion to the plugin repository but I think that this should be considered as an improvement of MapboxSDK directly : Provide a way to listen the same event with more than one listener.

NB : For camera event, we can use MapView.onChangeListener as a workaround but it's not really friendly. And the problem is still existing for click and annotation listener.

@Guardiola31337 Guardiola31337 added the Android Mapbox Maps SDK for Android label Sep 6, 2017
@tobrun
Copy link
Member

tobrun commented Sep 12, 2017

@emerciercontexeo you are correct that we atm only allow one active listener at the same time. Proposed solution of multiple listeners with addIdleCameraListener would work but would require some refactoring. I need to look into if we can make this change without breaking semver. Thank you for reporting this, this would be a great addition.

@tobrun
Copy link
Member

tobrun commented Oct 6, 2017

@emerciercontexeo proposed solution in #10141

@tobrun tobrun added this to the android-v5.2.0 milestone Oct 6, 2017
@tobrun tobrun self-assigned this Oct 6, 2017
@tobrun
Copy link
Member

tobrun commented Oct 10, 2017

This landed in #10141

@Etienne-io
Copy link
Author

@tobrun Thanks for this update. Plugin development is way better.

Will you apply the same modification for all the listeners ?

For my case, I need this on setOnMarkerClickListener but it should make sense to get it on setOnPolygonClickListener and setOnPolylineClickListener.

Thanks again,

Etienne

@tobrun
Copy link
Member

tobrun commented Feb 19, 2018

We like to keep the aim for these to the more low level api's as runtime styling and not expose such mechanisms for higher level api's as annotations. In any case you can roll your own click mechanism relying on MapboxMap#QueryRenderedFeatures without blocking the mentioned listeners.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

No branches or pull requests

3 participants