小编Mic*_*bbs的帖子

如何在使用 d3 绘制的 SVG 地图上显示国家名称标签?

我目前在尝试在 d3 世界地图上显示国家/地区名称时遇到问题。

这是显示国家/地区名称的传单示例的图像。这将是我想添加到我的 d3 版本中的内容。如果可能的话,只需国家名称。如果没有,我总是可以走传单路线,但我想我会先在 d3 尝试。

在此输入图像描述

这是d3版本

在此输入图像描述

这是我目前绘制地图的方式

    // reference to actual element d3 selects
    this.svg = d3.select(this.mapContainer.nativeElement)
        .append('svg')
        .attr('width', this.width)
        .attr('height', this.height)
        .call(zoom)
        .append('g')
        .attr('class', 'map');

    this.projection = d3.geoMercator()
        .scale(225)
        .translate([this.width / 2, this.height / 1.5]);

    const path = d3.geoPath().projection(this.projection);

    let g = this.svg.append('g');

    // if unknown is not in the filter set remove it from the json
    const filteredWorldMapJson = this.worldMapJson.features;

    // features are a list of countries
    // ex: { type: 'Feature', properties: { name: …
Run Code Online (Sandbox Code Playgroud)

javascript svg d3.js

1
推荐指数
1
解决办法
3319
查看次数

标签 统计

d3.js ×1

javascript ×1

svg ×1