首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带d3fc的单张-标签-布局

带d3fc的单张-标签-布局
EN

Stack Overflow用户
提问于 2017-03-16 13:52:18
回答 1查看 329关注 0票数 3

尝试在传单中使用d3fc标签布局,但由于

TypeError: updateSelection.merge不是一个函数

代码语言:javascript
复制
 var map = L.map('map').setView([45.616037, 15.951813], 5);
    mapLink =
        '<a href="http://openstreetmap.org">OpenStreetMap</a>';
    L.tileLayer(
        'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '&copy; ' + mapLink + ' Contributors',
            maxZoom: 18,
        }).addTo(map);
    map._initPathRoot()  
    // Add an SVG element to Leaflet’s overlay pane
    var svg = d3.select("#map").select("svg"),
        g = svg.append("g");
    d3.json("data.json", function (geoShape) {
        geoShape.features.forEach(function (d) {
            d.LatLng = new L.LatLng(d.geometry.coordinates[1],
                d.geometry.coordinates[0])
        })
        var labelPadding = 2;

        var textLabel = fc.layoutTextLabel()
            .padding(labelPadding)
            .value(function (d) { return d.properties.name; });

        var strategy = fc.layoutRemoveOverlaps(fc.layoutGreedy());

        // create the layout that positions the labels
        var labels = fc.layoutLabel(strategy)
            .size(function (_, i, g) {
                // measure the label and add the required padding
                var textSize = d3.select(g[i])
                    .select('text')
                    .node()
                    .getBBox();
                return [textSize.width + labelPadding * 2, textSize.height + labelPadding * 2];
            })
            .position(function (d) { return projection(d.geometry.coordinates); })
            .component(textLabel);

        svg.datum(geoShape.features)
           .call(labels);
    })

使用D3FC-标签-传单布局有帮助吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-17 09:14:50

问题是,我使用的是D3版本3-这个组件是设计用来处理D3版本4的。

代码语言:javascript
复制
<script src="https://d3js.org/d3.v4.js"></script>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42836030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档