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

resizeSvg
Aadhavan Srinivasan 2 months ago
parent 5fc15a2c5c
commit 625b1d1377

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

Loading…
Cancel
Save