1

私は基本的に、Let's Make a Map チュートリアルhttp://bost.ocks.org/mike/map/に従って世界地図を作成しています。チュートリアルのように海岸線と陸地の境界を区別し、国コードを各境界のクラスとして追加して、国が強調表示されたときに塗りつぶしと線の色の両方が変更されるようにします。これは世界地図なので、手動で行うには国が多すぎますが、これを動的に行う方法がわかりません。

私のコードの関連部分は次のとおりです。

var countryPaths = svg.append("g")
.attr("class", "countryPaths");

var countries = topojson.feature(world, world.objects.countries);

// add individual country paths
countryPaths.selectAll(".countries")
.data(countries.features)
.enter()
.append("path")
.attr("class", function(d) {return "country " + d.properties.adm0_a3; } )
.attr("d", path)

// add coastline
countryPaths.append("path")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a == b }))
.attr("d", path)
.attr("class","coastLine");

// add terrestrial borders
countryPaths.append("path")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return (a !== b)}))
.attr("d", path)
.attr("class", "country-boundary");
});

ただし、これを行うと、海岸線 (および地上の境界線) が 1 つのパスとして作成されるため、たとえば日本の海岸線を別の色に変更することはできません。これを達成する方法はありますか?

4

0 に答える 0