cartodb-4.42/lib/assets/javascripts/builder/deep-insights-integration/link-layer-tooltip.js

23 lines
707 B
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
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);
});
};