javascript-d3.geoEquirectangular()的地图渲染不一致
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-d3.geoEquirectangular()的地图渲染不一致,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2500字,纯文字阅读大概需要4分钟。
内容图文
我最近使用D3制作了一些地图,并且在路径无法正确关闭方面遇到了一些问题,如下面的第一个示例所示.我认为这是围绕-90度纬度精度的某种数据问题,但是我不确定如何验证这种怀疑.有趣的是,当我在页面上包含d3-geo模块的最新版本时,地图将按预期方式渲染(请参见下面的第二个示例).这里发生了什么?
var svg = d3.select("#map").style("border","0px solid #000000");
var width = 600;
var height = 300;
var proj = d3.geoEquirectangular().scale(95).translate([300,150]);
var path = d3.geoPath(proj);
//countries from natural earth dataset
var url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_110m_admin_0_countries.geojson";
d3.json(url, function(err, json){
//draw paths once
svg.selectAll("path").data(json.features).enter().append("path")
.attr("d", path).attr("stroke","#00aaff");
});
<script src="https://d3js.org/d3.v4.min.js"></script>
<h2>Fig. 1 Multiple paths not closed properly</h2>
<svg width="600px" height="300px" id="map"></svg>
<p>Uses D3 Version 4.13.0</p>
<p>GeoJson data source: <a href="https://github.com/nvkelso/natural-earth-vector/tree/master/geojson">https://github.com/nvkelso/natural-earth-vector/tree/master/geojson</a></p>
var svg = d3.select("#map").style("border","0px solid #000000");
var width = 600;
var height = 300;
var proj = d3.geoEquirectangular().scale(95).translate([300,150]);
var path = d3.geoPath(proj);
//countries from natural earth dataset
var url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_110m_admin_0_countries.geojson";
d3.json(url, function(err, json){
//draw paths once
svg.selectAll("path").data(json.features).enter().append("path")
.attr("d", path).attr("stroke","#00aaff");
});
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-geo.v1.min.js"></script>
<h2>Fig. 2 Map renders as expected</h2>
<p>The only difference from above is the inclusion of <a href="https://d3js.org/d3-geo.v1.min.js">https://d3js.org/d3-geo.v1.min.js</a></p>
<svg width="600px" height="300px" id="map"></svg>
<p>Uses D3 Version 4.13.0</p>
<p>GeoJson data source: <a href="https://github.com/nvkelso/natural-earth-vector/tree/master/geojson">https://github.com/nvkelso/natural-earth-vector/tree/master/geojson</a></p>
解决方法:
我相信您所引用的issue on github与d3如何引用多边形有关.该问题可能导致在某些投影上与南极重叠的多边形倒置.
d3-geo.v1.min.js的当前版本位于https://d3js.org/d3-geo.v1.min.js,版本为1.10,已于3月发布.此版本实现了此修复程序. d3v4(4.13)的最新版本于1月29日发布,因此不包含此修复程序,因此发现了该行为.
内容总结
以上是互联网集市为您收集整理的javascript-d3.geoEquirectangular()的地图渲染不一致全部内容,希望文章能够帮你解决javascript-d3.geoEquirectangular()的地图渲染不一致所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。