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

Multi event listeners for plugins development #9917

Closed

Description

@Etienne-io

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

Activity

  1. Guardiola31337 commented on Sep 5, 2017

    @Guardiola31337
    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.

  2. Etienne-io commented on Sep 6, 2017

    @Etienne-io
    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.

  3. added
    Android
    on Sep 6, 2017
  4. tobrun commented on Sep 12, 2017

    @tobrun
    Member

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

  5. tobrun commented on Oct 6, 2017

    @tobrun
    Member

    @emerciercontexeo proposed solution in #10141

  6. added this to the android-v5.2.0 milestone on Oct 6, 2017
  7. self-assigned this
    on Oct 6, 2017
  8. tobrun commented on Oct 10, 2017

    @tobrun
    Member

    This landed in #10141

  9. Etienne-io commented on Feb 17, 2018

    @Etienne-io
    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

  10. tobrun commented on Feb 19, 2018

    @tobrun
    Member

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Android

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions