Since language boundaries are now loaded from json, I can detect them and apply the right CSS class; removed JSON generation code

master
Aadhavan Srinivasan 1 month ago
parent 5fc15a2c5c
commit 625b1d1377

@ -198,11 +198,15 @@ function getOuterBoundaryPolygon(features) {
function stateOrDistrict(d) {
function stateOrDistrictOrLanguage(d) {
if (typeof d.properties.district !== 'undefined') {
return "district"
} else {
return "state"
if (typeof d.properties.lang_name !== 'undefined') {
return "language"
} else {
return "state"
}
}
}
@ -220,12 +224,16 @@ function drawMap(world) {
states.append("path")
.attr("d", path)
.attr("class", d => stateOrDistrict(d))
.attr("fill", d => district2lang.hasOwnProperty(d.properties.district) ?
.attr("class", d => stateOrDistrictOrLanguage(d))
.attr("fill", function(d) {
if (stateOrDistrictOrLanguage(d) === "district") {
return district2lang.hasOwnProperty(d.properties.district) ?
district2lang[d.properties.district].color :
state2lang[d.properties.st_nm].color)
state2lang[d.properties.st_nm].color
}
})
.each(function(d) {
if (stateOrDistrict(d) == "district") {
if (stateOrDistrictOrLanguage(d) === "district") {
districtLang = district2lang.hasOwnProperty(d.properties.district) ? district2lang[d.properties.district] : state2lang[d.properties.st_nm];
districtLang.districts.push(d)
}
@ -245,29 +253,28 @@ function drawMap(world) {
let allLangs = []
for (const [langId,lang] of Object.entries(languages)) {
let geojson = {
"type": "FeatureCollection",
"features": lang.districts
};
let outerBound = getOuterBoundaryPolygon(geojson.features)
outerBound["id"] = "lang" + lang.name
outerBound.properties["lang_name"]= lang.name
allLangs.push(outerBound);
console.log(JSON.stringify(outerBound, null, 2))
svg.append("path")
.datum(outerBound)
.attr("d", path)
.attr("fill", "none")
.attr("stroke", "red")
.attr("stroke-width", 2)
}
console.log(allLangs)
// for (const [langId,lang] of Object.entries(languages)) {
// let geojson = {
// "type": "FeatureCollection",
// "features": lang.districts
// };
//
// let outerBound = getOuterBoundaryPolygon(geojson.features)
// outerBound["id"] = "lang" + lang.name
// outerBound.properties["lang_name"]= lang.name
// allLangs.push(outerBound);
// svg.append("path")
// .datum(outerBound)
// .attr("d", path)
// .attr("fill", "none")
// .attr("stroke", "red")
// .attr("stroke-width", 2)
// }
// console.log(JSON.stringify(allLangs))
}
d3.json("india_with_districts.json").then(drawMap)
d3.json("india_with_districts_with_languages.json").then(drawMap)

Loading…
Cancel
Save