我有一個WV縣的topoJSON地圖。正確顯示人口密度。該地圖是從geoJSON數據創建的,然後使用topojson進行轉換。這是開發人員用來創建靜態數據顯示的所有常規步驟。我現在的問題是,這張地圖的用戶會希望在其上放置數據,而他們只有經緯度值。如何顯示先前創建的topoJSON映射上的lat,lon數據?如何將lat,lon數據動態地放置到topoJSON地圖上
下面是一些樣本數據:
var sampleData = [
{"name": "Weirton", "coordinates": [-80.589517, 40.418957]},
{"name": "Morgantown", "coordinates": [-79.955897, 39.629526]},
{"name": "Shepherdstown", "coordinates": [-77.804161, 39.430100]}
];
那我試圖展示在我(已顯示)的地圖,就像這樣:
var group = svg.append('g');
group.selectAll("cities")
.data(sampleData)
.enter()
.append("cities")
.attr("class", "cities")
.attr("transform", function(d) {return "translate(" + projection(d.coordinates) + ")";});
是否有可能得到一些緯度,經度數據到一個靜態地圖上,或者我瘋了一些編程錯誤?
更新:我已經打了數據,發現使用此代碼:
svg.append("path")
.datum(topojson.feature(wv, dynamicData))
.attr("d", path)
.attr("class", "place")
作品與此數據
var dynamicData =
{
"type":"GeometryCollection",
"geometries":[
{"type":"Point","properties":{"NAME":"Weirton"},"id":"Weirton","coordinates":[4172,9359]},
{"type":"Point","properties":{"NAME":"Morgantown"},"id":"Morgantown","coordinates":[5458,7063]},
{"type":"Point","properties":{"NAME":"Shepherdstown"},"id":"Shepherdstown","coordinates":[9826,6483]}]
};
,但不使用該數據
var dynamicData =
{
"type":"GeometryCollection",
"geometries":[
{"type":"Point","properties":{"NAME":"Weirton"},"id":"Weirton","coordinates":[-80.589517, 40.418957]},
{"type":"Point","properties":{"NAME":"Morgantown"},"id":"Morgantown","coordinates":[-79.955897, 39.629526]},
{"type":"Point","properties":{"NAME":"Shepherdstown"},"id":"Shepherdstown","coordinates":[-77.804161, 39.430100]}]
};
有人可以告訴我如何計算新的座標嗎?
您可以創建一個JSFiddle或Plunkr或其他東西,以便我們可以確切地看到您在做什麼? – reblace
好吧,我的問題是我無法在JSFiddle上獲得我的topoJSON文件。至少我不知道如何做到這一點。 – user3018981
如果我通過topojson運行我的原始緯度/經度數據並查看輸出,我會得到{「name」:「Weirton」,\t \t「coordinates」:[4172,9359]}。 topojson如何計算這些值?如果我可以對我的動態數據進行相同的計算,我可能會繼續。 – user3018981