javascript - Position of tooltip in d3.js -
i have map circle in real coordinate. put real coordinate on map use function:
map.latlngtolayerpoint ([x, y]); when zoomed, circle moves, relocate, within zoom trigger:
map.on ('zoomend', function () { }) i recalculate position of circle. when click on circle, tooltip displayed. if zoom, tooltip not next circle , moves. how can fix this?.
//moving tooltip var div= d3.select("body").append("div") .attr("class", "tooltip") .style("opacity", 0); //i put circle in coordinate var coordenadas=map.latlngtolayerpoint([coordinates[0].lat,coordinates[0].long]); svg.append('circle').attr("cx",position.x) .attr("cy", position.y) .attr("r", 30) .style("fill",'red') .style('pointer-events', 'all') .attr("class",'circulo_mapa') .on("click", function(element){ //tooltip div.style("opacity", .9) .html('message') .style("left", (d3.event.pagex) + "px") .style("top", (d3.event.pagey - 28) + "px"); }) //trigger on zoom map.on('zoomend', function() { //position of circle when zoomed executed d3.selectall(".circulo_mapa").attr("cx",function(d,i){ var position=map.latlngtolayerpoint([coordinates[0].lat,coordinates[0].long]); return position.x; }).attr("cy",function(d,i){ var position=map.latlngtolayerpoint([coordinates[0].lat,coordinates[0].long]); return position.y; }) });
Comments
Post a Comment