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 above code should work like this: Clicking on a link takes the data-ref-id-map and data-ref-g-id a zoom in SVG (% with%) that has a path with the ID that is in data-ref-id-map
. The problem is that it just zooms in on the SVG of the Layer_1 ID. As much as I click on the link containing the Layer_2 it is giving in the other SVG (Layer_1).
I made a debug to see which ID (layer) it is passing in the function data-ref-g-map
and it passes the right ID in the Layer_2