当我有土地的坐标信息时,如何用d3中的topojson颜色海洋? [英] How can I color ocean with topojson in d3 when I have coordinate info for land?

查看:202
本文介绍了当我有土地的坐标信息时,如何用d3中的topojson颜色海洋?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用d3学习topojson。
我有土地的坐标信息,它是正确渲染的。
那么,我如何添加颜色海洋(基本上在陆地)?我试着着色刻度,但不填满整个地图,留下空白点。



可视化版本托管在 http://jbk1109.github。 io /

  var projection = d3.geo.stereographic()
.scale(245)
.translate([width / 2,height / 2])
.rotate([ - 20,0])
.clipAngle(180 - 1e-4)
.clipExtent [[0,0],[width,height]])
.precision(.1);

var path = d3.geo.path()
.projection(projection)
var graticule = d3.geo.graticule();

var g = svg.append(g)

svg.append(path)
.datum(graticule)
.attr (class,graticule)
.attr(d,path)
.style(fill,none)
.style 777)
.style(stroke-width,0.2)

var land = svg.insert(path,.graticule)
.datum(topojson .feature(world,world.objects.land))
.attr(class,land)
.attr(d,path)
.style ,'#cbcbcb')
.style(opacity,0.8)


方案

没有必要(它将是相当困难,有点昂贵的计算)来计算出大地的逆。



您可以使用CSS:

  svg {
background:lightBlue;
}

或者您可以在前面加上< rect& / code>元素与蓝色填充在地图后面:

  svg.append('rect')
.attr('width',mapWidth)
.attr('height',mapHeight)
.attr('fill','lightBlue')
/ pre>

I am learning topojson with d3. I have coordinate information for land, which is rendered correctly. Then, how can I add color to ocean (basically outside land)? I tried coloring graticule, but doesn't fill up the entire map and leaves empty spots.

The visualization is hosted on http://jbk1109.github.io/

var projection = d3.geo.stereographic()
    .scale(245)
    .translate([width / 2, height / 2])
    .rotate([-20, 0])
    .clipAngle(180 - 1e-4)
    .clipExtent([[0, 0], [width, height]])
    .precision(.1);

var path = d3.geo.path()
    .projection(projection)
var graticule = d3.geo.graticule();

var g = svg.append("g")

svg.append("path")
    .datum(graticule)
    .attr("class", "graticule")
    .attr("d", path)
    .style("fill","none")
    .style("stroke","#777")
    .style("stroke-width",0.2)

var land = svg.insert("path", ".graticule")
      .datum(topojson.feature(world, world.objects.land))
      .attr("class", "land")
      .attr("d", path)
      .style("fill",'#cbcbcb')
      .style("opacity",0.8)

解决方案

There's no need (and it would be pretty difficult and somewhat expensive computationally) to figure out the inverse of the landmass. But you can just color the background.

I.e you can use CSS:

svg {
  background: lightBlue;
}

or you can prepend a <rect> element with a blue fill behind the map:

svg.append('rect')
  .attr('width', mapWidth)
  .attr('height', mapHeight)
  .attr('fill', 'lightBlue')

这篇关于当我有土地的坐标信息时,如何用d3中的topojson颜色海洋?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆