Plotly_click not working with mapbox

I’ve been trying to get the plotly_click event to work with scattermapbox, but either it’s not working (or more likely) I’m doing something entirely wrong.

see https://codepen.io/dangelsaurus/pen/XWBmEEz?editors=1111 for an example… code is below as well

var myPlot = document.getElementById("myDiv"),
  data = [
    {
      type: "scattermapbox",
      marker: { color: "fuchsia", size: 4 }
    }
  ],
  layout = {
    dragmode: "zoom",
    mapbox: { style: "open-street-map", center: { lat: 38, lon: -90 }, zoom: 3 },
    margin: { r: 0, t: 0, b: 0, l: 0 }
  },
  config = {

  };
Plotly.newPlot("myDiv", data, layout, config);
myPlot.on("plotly_click", function (data) {
  console.log(data);
});

Hello @dangelsaurus,

Welcome to the community!

Typically, I believe that clickData is specific to clicking on an actually point in the map.

Try adding some data and see if you get the expected behavior when you click on the points.

@jinnyzor thanks for the confirmation! I came to that conclusion later in the evening after posting this after doing some more searching, and just was too tired to come back here and update. But thanks again for confirming!

1 Like