CartoDB / toolkit

JS library to interact with CARTO APIs in a simple way
https://toolkit-wheat.now.sh
BSD 3-Clause "New" or "Revised" License
9 stars 3 forks source link

[#57710] Interactivity & Popups #96

Closed manmorjim closed 4 years ago

manmorjim commented 4 years ago

API for popups.

CH ticket: https://app.clubhouse.io/cartoteam/story/57710/interactivity-popups

Add & Remove popup click on a layer

// add interaction: popup on click
airbnbLayer.setPopupClick([
  { attr: "host_name", title: "Name" },
  "host_since",
  "country",
  { attr: "host_response_time", title: "Response Time" },
]);

// remove interaction click:
airbnbLayer.setPopupClick(null);

Add & Remove popup hover on a layer

// add interaction: popup on hover
airbnbLayer.setPopupHover([{ attr: "host_name", title: "Name" }, "country"]);

// remove interaction hover
airbnbLayer.setPopupHover(null);

Add a simple popup to a map

const p = new carto.viz.Popup();
p.setContent("This <b>is</b> a test");
p.setCoordinate([-3.7040553015362803, 40.405442923560564]);
p.addTo(deckMap);