Skip to content

Commit 7428fb5

Browse files
committed
Fix 251 map for empty towns
1 parent 70844c6 commit 7428fb5

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/Map.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,31 +137,40 @@ class Map extends Component {
137137
domainMin = Math.min(...speciesView)
138138
} else if (this.props.location.pathname === '/251') {
139139
vermont = VermontTowns
140-
var emptyTowns = []
140+
const allVermontTowns = new Set()
141+
var townsInData = []
141142

142143
Object.keys(data.vt251data).forEach(town => {
143144
speciesTotals = data.vt251data[town].length
145+
townsInData.push(town)
144146
if (speciesTotals > 0) {
145147
totalTowns += 1
146-
} else {
147-
emptyTowns.push(town)
148148
}
149149
// Calculate{} the highest town, for use in coloring
150150
if (speciesTotals > domainMax) {
151151
domainMax = speciesTotals
152152
}
153153

154154
for (j = 0; j < VermontTowns.features.length; j++) {
155+
allVermontTowns.add(VermontTowns.features[j].properties.town)
155156
if (town.toUpperCase() === VermontTowns.features[j].properties.town) {
156157
VermontTowns.features[j].properties.speciesTotal = speciesTotals
157158
VermontTowns.features[j].properties.species = data.vt251data[town].map(x => banding.codeToCommonName(x))
158159
if (vt251localdata.includes(VermontTowns.features[j].properties.town)) {
159160
VermontTowns.features[j].properties.local = true
160161
}
162+
161163
break
162164
}
163165
}
164166
})
167+
168+
var emptyTowns = []
169+
for (const x of allVermontTowns) {
170+
if (townsInData.indexOf(x) === -1 ) {
171+
emptyTowns.push(x)
172+
}
173+
}
165174
} else if (this.props.location.pathname === '/counties') {
166175
Counties.features = Counties.features.map(feature => rewind(feature, {reverse: true}))
167176
vermont = Counties
@@ -276,9 +285,9 @@ class Map extends Component {
276285
function totalTownsText () {
277286
if (totalTowns) {
278287
d3.select('#locale').text(`Towns birded: ${totalTowns}`)
279-
// if (pathname === '/251') {
280-
// d3.select('#list').text(`Towns with no checklists:\n` + emptyTowns.map(x => capitalizeFirstLetters(x)).sort().join(', '))
281-
// }
288+
if (pathname === '/251') {
289+
d3.select('#list').text(`Towns with no checklists:\n` + emptyTowns.map(x => capitalizeFirstLetters(x)).sort().join(', '))
290+
}
282291
} else {
283292
d3.select('#locale').text('')
284293
}
@@ -440,6 +449,12 @@ class Map extends Component {
440449
}
441450
})
442451
.on('mouseover', function (d) {
452+
453+
if (!d.properties.species) {
454+
d.properties.species = []
455+
d.properties.speciesTotal = 0
456+
}
457+
443458
if (!townSelected) {
444459
// var xPosition = d3.mouse(this)[0]
445460
// var yPosition = d3.mouse(this)[1] - 30
@@ -504,7 +519,7 @@ class Map extends Component {
504519
.append('li')
505520
.html(String)
506521
} else if (['/regions', '/251'].includes(pathname) && d.properties.species) {
507-
if (d.properties.species.length === 0) {
522+
if (!d.properties.species || d.properties.species.length === 0) {
508523
if (pathname === '/251') {
509524
d3.select('#list')
510525
.html(`No one has logged any species here yet this year.`)
@@ -535,11 +550,11 @@ class Map extends Component {
535550
})
536551

537552
totalTownsText()
538-
// if (pathname === '/251') {
539-
// d3.select('#list').text(`Towns with no checklists:\n` + emptyTowns.map(x => capitalizeFirstLetters(x)).sort().join(', '))
540-
// } else {
541-
d3.select('#list').text('')
542-
// }
553+
if (pathname === '/251') {
554+
d3.select('#list').text(`Towns with no checklists:\n` + emptyTowns.map(x => capitalizeFirstLetters(x)).sort().join(', '))
555+
} else {
556+
d3.select('#list').text('')
557+
}
543558
}
544559
})
545560
}

0 commit comments

Comments
 (0)