1
I have several links:
<a href="javascript:void(0);" id="ZoomPath" data-ref-id-map="Layer_1" data-ref-g-id="xxx">São Paulo - São Paulo</a>
<a href="javascript:void(0);" id="ZoomPath" data-ref-id-map="Layer_1" data-ref-g-id="yyy">São Paulo - Osasco</a>
<a href="javascript:void(0);" id="ZoomPath" data-ref-id-map="Layer_2" data-ref-g-id="xxx">São Paulo - São Paulo</a>
<a href="javascript:void(0);" id="ZoomPath" data-ref-id-map="Layer_2" data-ref-g-id="yyy">São Paulo - Osasco</a>
And I have the code:
$(document).on('click', 'a#ZoomPath', function(){
var Mapa = $(this).attr('data-ref-id-map');
var GID = $(this).attr('data-ref-g-id');
clicked(GID, Mapa);
$("g#"+GID+' > path').each(function(){
$(this).addClass('hover-map');
});
$("g#"+GID+' > path').each(function(){
$(this).fadeIn(1000).fadeOut(1000).fadeIn(1000).fadeOut(1000).fadeIn(1000).fadeOut(1000).fadeIn(1000, function(){
$(this).removeClass('hover-map');
});
});
});
function clicked(id_click, id_map) {
var svgClicked = d3.select("svg#"+id_map);
var bbox = d3.select("svg#"+id_map+" g#"+id_click).node().getBBox();
var svgWidth = bbox.width;
var svgHeight = bbox.height;
var x = bbox.x-(280/2), //METADE DA LARGURA DO SVG /2
y = bbox.y-(245/2); //METADE DA ALTURA DO SVG /2
var scale = 2;
svgClicked.transition().duration(2000)
.call(zoom.translate([((x * -scale) + (svgWidth / 2)), ((y * -scale) + svgHeight / 2)])
.scale(scale).event);
}
The code above should work like this: When clicking on a link it takes the attributes data-ref-id-map and data-ref-g-id and zoom in on the SVG (data-ref-id-map
) that has a path with the ID that is on data-ref-g-map
. The problem is that it only zooms in ID SVG Layer_1. For more I click on the link that contains the Layer_2 he is giving in the other SVG (Layer_1).
I debugged to see which ID (layer) it is passing in the function clicked
and it passes the right ID (layer) in case Layer_2
I switched to class and it didn’t work either @Luizaugustoneto
– Alisson Acioli
You need to change this line: $(Document). on('click', 'a#Zoompath', Function(){ For this: $(Document). on('click', 'a. Zoompath', Function(){ Since it is now a class and no longer an ID.
– Ívini
True, I had not noticed q had forgotten this detail, cool @Ívini
– Luiz Augusto Neto