OpenMaine / maineballot

The goal of MaineBallot.org is to provide concise, non-partisan information to make it easy to understand the ballot questions pending in Maine.
https://maineballot.org
MIT License
13 stars 10 forks source link

Revisit candidates feature #188

Open shannonmcharg opened 3 years ago

shannonmcharg commented 3 years ago

Need to decide whether it's worth keeping and if we can make improvements with the data we have.

shannonmcharg commented 3 years ago

We want to get to a point where you can input your address and out pops a list of your candidates and ballot questions. @robkorobkin did some work figuring out how to replicate the state's district lookup tool in this site: http://groundgamer.org/

Can we replicate this on Maine Ballot?

Details from Rob about what he did below:

Nothing's minified, and there are comments and variable / function names that actually make sense, so whoever's coding for you should hopefully have an okay time reading it?

If you're curious how I handle going from an address to identifying the legislative district for that address, here's the technobabble:

So, the first thing I did was get the GIS lat/lon boundary points of each legislative region out of the State's GIS archive, which I then wrote a script to convert to JSON: http://groundgamer.org/data/turfs/senate_districts.js http://groundgamer.org/data/turfs/house_districts.js

For data files, they're actually not that hard to read. Just a bunch of (lat,long) coordinates that pin out the boundaries of each legislative district.

Then, since I now had the districts as JSON, it wasn't all that hard to feed them into the Google Maps JS SDK to create the district overlay polygons that you see when you load the app.

The UI for the app contains a little form that takes an address, and then pings it to Google's geocode API, which spits back the lat/lon of the target address: https://maps.googleapis.com/maps/api/geocode/json?address=85%20Fessenden%20St,%20Portland,%20ME%2004103&key=AIzaSyDxvSHxYEcCAseWokSJ4HyTE0g9xA0IH0w

Then, this is where the magic happens, there's a little javascript function that iterates through the list of displayed polygons to see if each polygon contains the specified location. Ie: it goes through all the districts (which are now loaded onto the map) and checks to see if your address (which you just got back from the API) is contained within it.

--

Hopefully this won't be too hard for you guys to implement into your thing.

Basically all you should need to do so is:

--

Hope this helps.

All the stuff for GroundGamer.org is here: https://github.com/OpenMaine/GroundGamer_maine

shannonmcharg commented 3 years ago

More from Rob: Now that I think about it, Google or somebody probably just has an endpoint now that you can submit an address to and it’ll send back all the political district data for that address as some sort of big JSON dump.

That’s probably what you actually want.

It’s a fun dataset to have the boundaries of all the legislative districts in the state, like I’m working with here, and you obviously need it if you want to map out all the districts on a single map, etc. But if that’s not what you’re trying to do, that’s some serious overkill. It’s effectively drawing a detailed map of the state before you can find out about a single place on that map.

Just ping this: https://developers.google.com/civic-information

shannonmcharg commented 3 years ago

This is the spreadsheet we use for local websites: https://docs.google.com/spreadsheets/d/1dk58MD0qBAM37BDOZwKIz10hp5AARAIX8u_qvuDnYaI/edit?usp=sharing

And candidates: https://docs.google.com/spreadsheets/d/14RapVz5_AlGRza-MsSzzu6cOQRIX_oSu-mcNQy8ytyo/edit?usp=sharing

shannonmcharg commented 3 years ago

@mfras3r started working on this, if anyone wants to pick up where he left off.

https://github.com/mfras3r/maineballot-sandbox

shannonmcharg commented 2 years ago

There is a spreadsheet of candidates for the June election, if anyone wants to play around with it. https://www.maine.gov/sos/cec/elec/upcoming/index.html