/* * Add a cell to the tooltip that has a "Loading..." value and launches an asynchronous process that replaces this "Loading..." with a real value * Usage: to use with reverse geocoding * Piotr Szrajber <piotr.szrajber@hexagongeospatial.com> */vari=0;gsp.ready("v1.0",function(gsp){gsp.bi.stage.findWidgets({descriptors:[{chartM:{chart:"choropleth"}}]},function(widgets){if(!widgets||!widgets[0]){console.error("No choropleth found.");}vargeochart=widgets[0].chart;varorig=geochart.tooltipProvider().update;geochart.tooltipProvider().update=function(){varargs=Array.prototype.slice.call(arguments);orig.apply(this,arguments);varttipContent=this.getTooltipContent(args[1],args[2]);// add a new table row with a cell that is using feature IDvarnewContent=this.getTooltipContent(args[1],args[2]).replace(/<\/table>/,"<tr><td>NEW PARAMETER:</td><td id=\"Loading_tooltip_"+args[1].id+"\">Loading...</td></tr></table>");args[0].setContent(newContent);setTimeout(function(){varcell=document.querySelector("#Loading_tooltip_"+args[1].id);// if there is no such a cell, it means that the tooltip has been closed before so we can actuall cancel the asynchronous operationif(!cell){console.log("No cell for id="+args[1].id);return;}// TODO: launch Reverse geocoding and output it to that cell (with the ID) when it's done// TODO: cancel the request when the tooltip is abandonedcell.innerHTML="Hello world "+i+++"!";},3000);}});});
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.