Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Interaction

JMap.Map.Interaction

We introduced a notion of map interactor in JMap.

The need is that we want the map to interact in different ways depending on what the user is doing :

  • When he is drawing on the map we display shape on the map
  • When he is clicking on the map we display a popup information
  • etc...

So we defined our own map interactors for JMap, and we also allow you to create and register your own interactors.

An interactor is a JS object that define 4 functions (for more details consult interface JMapInteractor) :

 - init(map: mapboxgl.Map): void
 - activate(): void
 - deactivate(): void
 - terminate(): void

After creating your interactor object, you need to add it through the interaction service :

 JMap.Map.Interaction.addInteractor(
   "display-bubbles-on-click", // interactor id
   bubbleInteractor, // interactor object
   true // if true activate the interactor after being added
)

There is always an interactor actived, and this is the active interactions that are in use on the map.

When you activate an interactor, the previous one is deactivated, and the new one activated on the map.

When you don't need anymore an interactor you can terminate it, and it will not exist anymore in the JMap NG Core library.

Index

Functions

activateInteractorById

  • activateInteractorById(interactorId: string): void
  • JMap.Map.Interaction.activateInteractorById

    Activate an existing map interactor.

    Deactivate the previous one, and activate the new one.

    throws

    Error if interactor is not found

    example
    
    // Activate the JMAP defined interactor "draw"
    JMap.Map.Interaction.activateInteractorById("draw")

    Parameters

    • interactorId: string

      The interactor id to activate

    Returns void

addInteractor

  • addInteractor(id: string, interactor: JMapInteractor, active?: undefined | false | true): void
  • JMap.Map.Interaction.addInteractor

    Add a map interactor.

    If the id has already an existing interactor defined for, it will replace the old one.

    So be carrefull not to remove JMap interactors.

    You can get the list of already existing interactor ids like this :

    JMap.Map.Interaction
       .getAllInteractorDescriptors()
       .map(interactor => interactor.id)
    throws

    Error if bad parameters are passed

    example
    
    // add a new interactor
    JMap.Map.Interaction.addInteractor("my-custom-pin", { ...mapInteractor }, false)
    
    // add and activate a new interactor
    JMap.Map.Interaction.addInteractor("my-custom-pin", { ...mapInteractor }, true)

    Parameters

    • id: string

      The new interactor id.

    • interactor: JMapInteractor

      The map interactor object

    • Optional active: undefined | false | true

      If true will activate the new interactor after being added

    Returns void

getActiveInteractorId

  • getActiveInteractorId(): string
  • JMap.Map.Interaction.getActiveInteractorId

    Returns the active interactor id.

    example
    
    // Returns the active interactor descriptor
    JMap.Map.Interaction.getActiveInteractorId()

    Returns string

getAllInteractorIds

  • getAllInteractorIds(): string[]
  • JMap.Map.Interaction.getAllInteractorIds

    Returns all existing interactor ids.

    example
    
    // returns all existing interactor ids
    JMap.Map.Interaction.getAllInteractorIds()

    Returns string[]

terminateInteractorById

  • terminateInteractorById(interactorId: string): void
  • JMap.Map.Interaction.terminateInteractorById

    Terminate the map interactor.

    After being terminated, the interactor doesn't exist anymore in JMap NG Core library.

    You cannot activate it anymore.

    throws

    Error if interactor is not found

    example
    
    // terminate interactor id="custom-selection"
    JMap.Map.Interaction.terminateInteractorById("custom-selection")

    Parameters

    • interactorId: string

      The interactor id to terminate

    Returns void