D3路径未显示

发布于 2025-02-13 13:03:37 字数 1109 浏览 1 评论 0 原文

我正在尝试使用D3和D3Geo从.geojson文件渲染的一些功能,并且我正在关注此作为指导。我真的不知道自己在做什么,因为我不擅长编程。它在DevTool控制台上没有显示错误,当我在Chrome中进行检查时,它显示了这些路径是创建的,但没有显示。

这是我的代码,JS部分:

var width = Math.max(
  document.documentElement.clientWidth,
  window.innerWidth || 0
);
var height = Math.max(
  document.documentElement.clientHeight,
  window.innerHeight || 0
);

d3.json("2022.json").then(function (data) {
  let geojson = data;
  console.log(data);

  let projection = d3
    .geoMercator()
    //.scale(1000)
    //.center([20, 40])
    //.translate([456, 250]);

  projection.fitExtent([width, height], data);

  let geoGenerator = d3.geoPath().projection(projection);

  function update(geojson) {
  let u = d3
    .select("#content")
    .data(geojson.features)
    .enter()
    u.append('path')
    .join("path")
    .attr("d", geoGenerator);
  }

  update(geojson);

});

在此处输入图像描述

I am trying to make some features from a .geojson file render using D3 and D3geo and i am following this https://www.d3indepth.com/geographic/ as a guide. I don't really know what i am doing since i am not good at programing. It shows no errors on devtool console and when i inspect it in chrome it shows that the paths are created but the are not showing.

here is my code, the js part:

var width = Math.max(
  document.documentElement.clientWidth,
  window.innerWidth || 0
);
var height = Math.max(
  document.documentElement.clientHeight,
  window.innerHeight || 0
);

d3.json("2022.json").then(function (data) {
  let geojson = data;
  console.log(data);

  let projection = d3
    .geoMercator()
    //.scale(1000)
    //.center([20, 40])
    //.translate([456, 250]);

  projection.fitExtent([width, height], data);

  let geoGenerator = d3.geoPath().projection(projection);

  function update(geojson) {
  let u = d3
    .select("#content")
    .data(geojson.features)
    .enter()
    u.append('path')
    .join("path")
    .attr("d", geoGenerator);
  }

  update(geojson);

});

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文