Skip to content

How to distinguish user-initiated map move events from events fired as a result of programmatic APIs? #793

Description

@igalgh

maplibre-gl-js version: (all)

Question

I need a way to respond differently to map move/pan/pitch/bearing events depending on those events being a result of user-interaction or programmatic API calls.

Reasoning:
We have a special mode where map view changes which are a result of user interactions are written to the DB.
Map movements which is a result of API calls do not.

One way to implement it is to add an eventData argument to all programmatic API calls as in:

map.setCenter(center, {originIsApi: true}) 

It can hold a flag which implies the event originates from an API call and not a result of user interaction.

This approach seems a little hackish thou. It requires updating every api call in the project: force an eventData arg for each, which is only used for this reason.

It'd be so much more elegant to have this information built into the events by design.
It'll save the developer the effort of modifying the entire API calls set.

The eventData approach also involves an elevated risk for bugs; inexperienced developers could neglect providing a suitable eventDataarg, introducing very subtle bugs which are difficult to track down.

Anyone else facing a similar issue? Perhaps I'm missing a better solution...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions