D3.js D3地图禁用城市标签上的缩放

D3.js D3地图禁用城市标签上的缩放,d3.js,D3.js,我被这个问题困扰了几天,我希望有人能帮助我。 基本上这就是问题所在: 我有一张英国地图,上面有城市标签和标记。我已经启用了缩放和平移,但当我放大时,甚至标记和标签的尺寸也会增加。 我希望在缩放期间保留标记泊松,平移伦敦始终处于其位置,但不缩放标记和标签的尺寸 这是我的缩放功能 var zoomBehav= function(){ var t = d3.event.translate, s = d3.event.scale; t[0] = Math.mi

我被这个问题困扰了几天,我希望有人能帮助我。 基本上这就是问题所在: 我有一张英国地图,上面有城市标签和标记。我已经启用了缩放和平移,但当我放大时,甚至标记和标签的尺寸也会增加。 我希望在缩放期间保留标记泊松,平移伦敦始终处于其位置,但不缩放标记和标签的尺寸

这是我的缩放功能

var zoomBehav= function(){
      var t = d3.event.translate,
          s = d3.event.scale;
      t[0] = Math.min(width / 2 * (s - 1), Math.max(width / 2 * (1 - s), t[0]));
      t[1] = Math.min(height / 2 * (s - 1) + 230 * s, Math.max(height / 2 * (1 - s) - 230 * s, t[1]));
      zoom.translate(t);
      g.style("stroke-width", 1 / s).attr("transform", "translate(" + t + ") scale(" + s + ")");
    };
有人能帮我吗

附加信息 我想我应该写更多的信息。 我的svg定义为

this.svg = d3.select("#"+this.config.mapContainer).append("svg")    
              .attr("id","svgMap")
              .attr("width",width)
              .attr("height",height)
              .style("background-color", "lightblue")
              .append("g").attr('id','first_g')
              .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")")

        //Adding Zoom Rect to svg
        this.svg.append("rect")
                .attr("id", "d3e_zoomArea")
                .attr("class", "d3e_zoomArea")
                .attr("x", -width / 2)
                .attr("y", -height / 2)
                .attr("width", width)
                .attr("height", height)
                .attr('onmousedown', 'return false');

        //Insert g elementi in svg
        g = this.svg.append("g").attr('id','g_pathContainer');

        //Set Actual Map Right Projection
        / create a first guess for the projection
    subunits = topojson.feature(map, map.objects[level]);
    center = d3.geo.centroid(subunits);

    projection = d3.geo.mercator()
                .scale(width / 2 / Math.PI) //Crea la scala di visualizzazione
                .center(center) //Centra la posizione sulla mappa
                .translate([0, 0]);

    path = d3.geo.path().projection(projection);

    // using the path determine the bounds of the current map and use 
    // these to determine better values for the scale and translation             
    var bounds  = path.bounds(subunits);
    var hscale  = scale*width  / (bounds[1][0] - bounds[0][0]);
    var vscale  = scale*height / (bounds[1][1] - bounds[0][1]);
    scale   = (hscale < vscale) ? hscale : vscale;

    // new projection
    projection = d3.geo.mercator().center(center)
                       .scale(scale).translate([0, 0]);
    path = path.projection(projection);

        zoom = d3.behavior.zoom()
                    .translate(projection.translate())
                    .scale(projection.scale())
                    .scaleExtent([this.config.scaleRange.scaleMin , this.config.scaleRange.scaleMax])
                    .on("zoom", zoomed);
        d3.select("#first_g").call(zoom);
添加了JSFIDDLE
我创建了一个JSFIDLE来重现我的问题。我对基础投影应用了一些初始变换,以便根据实际国家对地图进行居中和缩放

您需要缩放投影,而不是SVG,请参见示例。我尝试了这个解决方案,定义了缩放功能,如示例所示。但地图完全消失,在可视区域设置路径。我编辑了我的答案以提供更多信息。我做错了什么?TKSA也许看一看JSFIDLE会非常有用useful@user1651248最初的问题是,使用图形变换进行缩放时,线条和圆点会变大。它是快速和简单的,但它缩放一切平等。如果需要调试投影比例缩放函数的帮助,则必须发布该代码,包括为实现缩放而调用的实际缩放函数。