You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Multi event listeners for plugins development #9917
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) ?
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.
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.
@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.
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.
Activity
Guardiola31337 commentedon Sep 5, 2017
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 commentedon Sep 6, 2017
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.
tobrun commentedon 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
addIdleCameraListenerwould 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 commentedon Oct 6, 2017
@emerciercontexeo proposed solution in #10141
tobrun commentedon Oct 10, 2017
This landed in #10141
Etienne-io commentedon Feb 17, 2018
@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 commentedon 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.