cartodb-4.42/lib/assets/javascripts/builder/deep-insights-integration/link-layer-tooltip.js
2024-04-06 05:25:13 +00:00

23 lines
707 B
JavaScript
Executable File

module.exports = function linkLayerTooltip (layerDef, visMap) {
if (!layerDef.tooltipModel) return;
function onChange (tooltipModel) {
var attrs = JSON.parse(JSON.stringify(tooltipModel.attributes));
var tooltip = visMap.getLayerById(layerDef.id).tooltip;
// some layers like basemaps, torque, or aggregated don't have infowindows
// so skip update
tooltip && tooltip.update(attrs);
}
var tooltipModel = layerDef.tooltipModel;
if (tooltipModel.get('template_name')) {
tooltipModel.setTemplate(tooltipModel.get('template_name'));
}
tooltipModel.bind('change', onChange);
layerDef.bind('destroy', function () {
tooltipModel.unbind('change', onChange);
});
};