私は各国ごとに1つのマーカーを持つクリック可能な世界地図を作成しようとしています。出身国のマーカーがクリックされている場合、他の国とのやりとりを集約して表示する必要があります。私は世界地図を描くことができましたが、CSVファイルで与えられたIPアドレスを使って、2カ国間のやりとりをどうやって描くのか分かりません。私は解決策を探してみましたが無駄でした。私はd3.jsに新しいです誰かがこれにいくつかの光を投げることができれば素晴らしいだろう。IPアドレスを使用して送信元と宛先の間のやりとりを引き出す方法は?
提案は本当に役に立ちます。相対的なライブラリ(必要な場合)や他の提案を使用して進む方法についての示唆は、あらゆる直接的な答えと同様に役立ちます。ありがとうございました。ここ はここplnkr
で正しい方向を指すようにスクリプト
var app = angular.module("chartApp", []);
app.controller("SalesController", function($scope, $http) {
$http.get("countries.csv").then(function(response) {
$scope.salesData = response;
});
});
app.directive("linearChart", function($window) {
return {
restrict: "EA",
// template: "<svg width='1024' height='728'></svg>",
link: function(scope, elem, attrs) {
// canvas resolution
var margin = { top: 50, left: 50, right: 50, bottom: 50 },
height = 900 - margin.top - margin.bottom,
width = 1400 - margin.left - margin.right;
// defines "svg" as data type and "make canvas" command
var svg = d3.select("#map")
.append("svg")
.attr("height", height + margin.top + margin.bottom)
.attr("width", width + margin.left + margin.right)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// var width = 1500,
// height = 900;
d3.queue()
.defer(d3.json, "https://unpkg.com/[email protected]/world/110m.json")
.defer(d3.csv, "countries.csv")
.await(ready);
// projection-settings for mercator
var projection = d3.geoMercator()
// .translate([width/2, height/2])
// where to center the map in degrees
.center([-30, 60])
// // zoomlevel
.scale(200);
// // map-rotation
// .rotate([0, 0]);
/* Create a Path using projection */
var path = d3.geoPath()
.projection(projection);
function ready(error, data, country_name) {
console.log(data);
var countries = topojson.feature(data, data.objects.countries).features;
console.log(countries);
console.log(country_name);
/* Add a path for each country
Shapes -> Path
*/
svg.selectAll(".country")
.data(countries)
.enter().append("path")
.attr("class", "country")
.attr("d", path)
.on('mouseover', function(d) {
d3.select(this).classed("selected", true);
})
.on('mouseout', function(d) {
d3.select(this).classed("selected", false);
});
svg.selectAll(".country-circles")
.data(country_name)
.enter().append("circle")
.attr("class", "circle")
.attr("r", 2)
.attr("cx", function(d) {
var coords = projection([d.longitude, d.latitude]);
return coords[0];
})
.attr("cy", function(d) {
var coords = projection([d.longitude, d.latitude]);
return coords[1];
});
svg.selectAll(".countries")
.data(country_name)
.enter().append("marker")
.attr("class", "countries")
.attr("x", function(d) {
var coords = projection([d.longitude, d.latitude]);
return coords[0];
})
.attr("y", function(d) {
var coords = projection([d.longitude, d.latitude]);
return coords[1];
})
// .text(function(d) {
// return d.country_name;
// })
.attr("dx", 5)
.attr("dy", 2);
}
}
};
});
$ httpリクエストのデータは 'response.data'です。 'console.log'で' response'オブジェクトを見ると、これは明らかです。 [小さなプログラムをデバッグする方法](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)を読んでください。 – georgeawg
ありがとうございました。しかし、地図が表示された後、$ httpのリクエストデータが使用されますが、最初に地図が表示されません – HebleV
このコードはどこにありますか?すべての行が壊れているようです。ディレクティブの名前が適切に正規化されていないため、ディレクティブはインスタンス化されていません。 postLinkコードは 'id =" map "で要素を探しますが、そのような要素はありません。リストは続く。 – georgeawg