• JMap.Event.MouseOver.on.beforeContentProcessed

    This event is triggered each time the map is clicked, and before the mouseover content is calculated or popup opened.

    This event is a special on, as it offers 3 methods which can change the mouseover behavior:

    • getFeaturesByLayerId: it returns the feature that will be used to display the mouseover
    • addFeaturesToLayerSelection : add custom features to the mouseover
    • removeFeaturesFromLayerSelection: used to remove a clicked feature from the mouseover (will not be displayed in the mouseover)

    You can test the event function addFeaturesToLayerSelection, by pasting the following code in the console (adapt for your configuration):

    JMap.Event.MouseOver.on.beforeContentProcessed(
    "my-listener",
    params => {
    console.log("Mouseover selection before", params.selection[4])
    params.addFeaturesToLayerSelection(4, [{
    id: 58,
    properties: {JMAP_FID: 58, NOM_QR: "Bois-Francs"},
    type: "Feature",
    geometry: {coordinates: [],type: "Polygon"}
    }])
    console.log("Mouseover selection after", params.selection[4])
    }
    )

    This listener adds a feature on every click on the map, so no matter where you click, the mouseover will contains at least one feature (the one dynamically added by the listener)

    Then paste this in the console to remove the previous listener:

    JMap.Event.MouseOver.remove(“my-listener“)
    

    You can test that now no mouseover is displayed anymore when we click on an empty area.

    Finally you can test the event function removeFeaturesFromLayerSelection by pasting the following code snippet:

    JMap.Event.MouseOver.on.beforeContentProcessed(
    "my-listener",
    params => {
    console.log("Mouseover selection before", params.selection[4])
    params.removeFeaturesFromLayerSelection(4, [58])
    console.log("Mouseover selection after", params.selection[4])
    }
    )

    Now you can click on the feature id=58, but no mouseover will display for if, as it is automatically removed by the listener.

    Parameters

    • listenerId: string

      Your listener id (must be unique for all mouseover events)

    • fn: ((params) => void)

      Your listener function

    Returns void

    Example

    // Each time the map is clicked and "layer" interactor is active
    JMap.Event.MouseOver.on.beforeContentProcessed("my-listener", params => {
    // mouseover "clicked" features for layer id="3"
    let features = params.getFeaturesByLayerId(3) // returns an array copy
    // remove feature id=17
    params.removeFeaturesByLayerId(3, [123, 432])
    features = params.getFeaturesByLayerId(3)
    // now features id=123 and 432 are not anymore in features array
    const newFeature = { id="24553", ...etc } // a geojson feature
    params.addFeatureByLayerId(3, newFeature)
    features = params.getFeaturesByLayerId(3)
    // features contains the new feature and will display it in the mouseover
    })