projectionStream在D3.js v4中不是一个函数

projectionStream is not a function in D3.js v4

本文关键字:函数 一个 D3 js v4 projectionStream      更新时间:2023-09-26

我们正在做这个网站http://bandaultralarga.italia.it/mappa-bul/

在那个页面上,我们有一个gMap,我们在上面画了一些多边形,使用d3(v3)和topoJson。

现在我们想(想)切换到新的v4添加新的数据可视化设计的页面上,但保持我们已经有。

麻烦出现在下面的叠加函数中,我们将坐标转换为谷歌地图系统。

参考D3 v4 API文档,我们从:

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

:

path = d3.geoPath().projection(googleMapProjection);

但是这会产生主题错误(projectionStream不是一个函数)

有什么线索可以让它再次工作吗?

var overlay = new google.maps.OverlayView();
overlay.onAdd = function () {
    var div = document.createElement('div');
    div.id = 'svg_map';
    div.style.borderStyle = 'none';
    div.style.borderWidth = '0px';
    div.style.position = 'absolute';
    this.getPanes().overlayMouseTarget.appendChild(div);
    overlay.draw = function () {
        var overlayProjection = this.getProjection();
        var googleMapProjection = function (coordinates) {
            var googleCoordinates = new google.maps.LatLng(coordinates[0], coordinates[1]);
            var pixelCoordinates = overlayProjection.fromLatLngToDivPixel(googleCoordinates);
            return [pixelCoordinates.x + 4000, pixelCoordinates.y + 4000];
        };
        path = d3.geoPath().projection(googleMapProjection); // Here is where troubles come
        generaOverlay(overlay, datiShape);
    };
};
overlay.setMap(map);

mbostock answer:

请阅读d3-geo发布说明或CHANGES.md:

"回退投影"——当你传递一个函数而不是一个投影给path时。不再支持投影。对于地理投影,使用d3。geoProjection或d3。geoProjectionMutator来定义一个自定义投影。对于任意几何变换,实现流接口;参见d3.geoTransform.