本文介绍了使旧的地理环境适应D3 v5,如何表达Promise队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将,以适应现代D3v5:第一步, D3v4正在运行与此源一起转换,但是我需要最后一步,从旧队列开始,

I am adapting an old version D3 map visualization to modern D3v5: first step, to D3v4, is running with this source, but to the final step I need to convert Promises, from old queue,

d3.queue().defer(d3.json,"file.json").(ready);

向现代v5风格... 如何以v5风格表达?
似乎是

to the modern v5 style... How to express in v5 style?
Seems that is something as

var brMap = d3.json("file.json");
Promise.all([brMap]).then(ready)    

但不起作用.

PS:v5 简单示例在哪里?

PS: where the v5 simple examples?

推荐答案

感谢@GerardoFurtado和@altocumulus,答案就在他的评论上,在这里全部合并.

Thanks @GerardoFurtado and @altocumulus, the answer was on his comments, here merging all.

有一些全局变量(也许不是最佳实践)

There are some globals (perhaps not a best practice)

var g;

在页面加载后"上下文中运行

In "after page load" context run

svg = d3.select("etc..")
g = svg.append("g")
// ...
d3.json("file.json").then(ready);

其中函数ready()类似于

function ready(shp) {
  var data1 = topojson.feature(shp, shp.item1);
  //... draw map appenging features to global g
}

此处中查看解决方案的最终结果.

See the final result of the solution here.

这篇关于使旧的地理环境适应D3 v5,如何表达Promise队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 11:19