0

How can I add featureOver on map for multiple layers(layers added dynamically) using carto.js and leaflet. This functionality have worked only for one layer. Here is my code:

layer.on(carto.layer.events.FEATURE_OVER, featureEvent => {
  //console.log("feature event", featureEvent);
  popup.setLatLng(featureEvent.latLng);
  if (!popup.isOpen()) {
    popup.setContent(featureEvent.data.sdlbl);
    popup.openOn(map);
  }
});
layer.on(carto.layer.events.FEATURE_OUT, featureEvent => {
  popup.removeFrom(map);
});
1

Unfortunately, CARTO.js does not support feature over multiple layers. I have replicated your problem in this glitch example. CARTO VL, on the other hand, supports this type of interactivity. You can see a working example here. You can open a bug ticket in CARTO.js v4 github repository, but that project has not being updated for a while.

4
  • hey ramiroaznar thanks for replying now i have used corto.vl and tried to add label for each layer but i did not found any solution.if you have any idea please tell me – Upendra Yadav Feb 28 '20 at 11:57
  • Can you edit your question and add the piece of code using this time CARTO VL? I need your code to replicate the behavior. – ramiroaznar Feb 28 '20 at 12:37
  • thanks ramiroaznar .i got solution – Upendra Yadav Mar 17 '20 at 12:56
  • Can you post your solution as an answer? In doing so you will help the rest of the community. – ramiroaznar Mar 17 '20 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.