Added Santali and Sindhi languages; removed 'try ... catch' block because the function shouldn't error
This commit is contained in:
77
index.js
77
index.js
@@ -21,6 +21,8 @@ const nepaliColor = "#71998e" // Nepali
|
||||
const urduColor = "#3fa179" // Urdu
|
||||
const tuluColor = "#dedc52" // Tulu
|
||||
const maithaliColor = "#4472a6" // Maithali
|
||||
const santaliColor = "#96bf60" // Santhali
|
||||
const sindhiColor = "#e89931" // Sindhi
|
||||
|
||||
const unavailLangColor = "#555555"
|
||||
|
||||
@@ -46,6 +48,8 @@ const languages = {
|
||||
urdu: {name: "Urdu", color: urduColor, districts: []},
|
||||
tulu: {name: "Tulu", color: tuluColor, districts: []},
|
||||
maithali: {name: "Maithali", color: maithaliColor, districts: []},
|
||||
santali: {name: "Santali", color: santaliColor, districts: []},
|
||||
sindhi: {name: "Sindhi", color: sindhiColor, districts: []},
|
||||
unavail: {name: "Unavailable", color: unavailLangColor, districts: []},
|
||||
};
|
||||
|
||||
@@ -140,6 +144,21 @@ const district2lang = { // Should override state colors
|
||||
"Saharanpur": languages["urdu"],
|
||||
"Shamli": languages["urdu"],
|
||||
"Hapur": languages["urdu"],
|
||||
|
||||
"Kutch": languages["sindhi"],
|
||||
|
||||
"Godda": languages["santali"],
|
||||
"Deoghar": languages["santali"],
|
||||
"Dumka": languages["santali"],
|
||||
"Jamtara": languages["santali"],
|
||||
"Sahibganj": languages["santali"],
|
||||
"Pakur": languages["santali"],
|
||||
"East Singhbhum": languages["santali"],
|
||||
"Jhargram": languages["santali"],
|
||||
"Bankura": languages["santali"],
|
||||
"Purulia": languages["santali"],
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -160,8 +179,6 @@ function reverseCoordArrays(coords) {
|
||||
|
||||
|
||||
function getOuterBoundaryPolygon(features) {
|
||||
try {
|
||||
|
||||
// Check if we have features to process
|
||||
if (!features || features.length === 0) {
|
||||
console.warn("No features to process for boundary");
|
||||
@@ -173,31 +190,13 @@ function getOuterBoundaryPolygon(features) {
|
||||
return features[0];
|
||||
}
|
||||
|
||||
// Combine all polygons using turf.union
|
||||
let combined = turf.union(turf.featureCollection(features))
|
||||
|
||||
// for (let i=0; i<combined.geometry.coordinates.length; i++) {
|
||||
// let outerCoords = combined.geometry.coordinates[i]
|
||||
// if (!turf.booleanClockwise(outerCoords)) {
|
||||
// outerCoords.reverse()
|
||||
// }
|
||||
//
|
||||
// combined.geometry.coordinates[i] = outerCoords;
|
||||
// }
|
||||
|
||||
combined.geometry.coordinates = reverseCoordArrays(combined.geometry.coordinates);
|
||||
return combined;
|
||||
} catch (error) {
|
||||
console.error("Error processing GeoJSON:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function stateOrDistrictOrLanguage(d) {
|
||||
if (typeof d.properties.district !== 'undefined') {
|
||||
return "district"
|
||||
@@ -213,7 +212,6 @@ function stateOrDistrictOrLanguage(d) {
|
||||
function drawMap(world) {
|
||||
const mapWidth = document.getElementById("indiaMap").getAttribute("width")
|
||||
const mapHeight = document.getElementById("indiaMap").getAttribute("height")
|
||||
console.log(d3.geoBounds(world));
|
||||
const projection = d3.geoMercator().fitSize([mapWidth, mapHeight], world)
|
||||
const path = d3.geoPath().projection(projection);
|
||||
|
||||
@@ -253,26 +251,25 @@ 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);
|
||||
|
||||
// svg.append("path")
|
||||
// .datum(outerBound)
|
||||
// .attr("d", path)
|
||||
// .attr("fill", "none")
|
||||
// .attr("stroke", "red")
|
||||
// .attr("stroke-width", 2)
|
||||
// }
|
||||
// console.log(JSON.stringify(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))
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user