Giter Site home page Giter Site logo

ragtagopen / marchon-map Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 6.0 1.24 MB

Map for March On https://www.wearemarchon.org

License: MIT License

HTML 24.94% CSS 3.97% JavaScript 23.23% Python 47.00% Makefile 0.86%
mapbox-gl-js activism aws-lambda google-api vuejs2

marchon-map's Introduction

March On map

Draw March On affilates and allied events on a Mapbox map, for embedding on March On.

Google Sheets to GeoJSON

Mapbox GL JS doesn't allow access to the entire feature set, only features in the current view (mapbox/mapbox-gl-js#2481). This map has a small number of features, and we need access to all of them to find the nearest to a user's location. Run an AWS Lambda script daily to get data from a Google sheet and save as GeoJSON on S3.

AWS Lambda function creates GeoJSON from a Google sheet:

  • get data from Google Sheets via Google API
  • get GeoJSON from public S3 URL
  • geocode locations with Mapbox's Geocoder API
  • write GeoJSON to S3

GeoJSON to map

map.js uses Vue.js and Mapbox GL JS to create the map.

  • create Mapbox GL map with MarchOn's custom style
  • load GeoJSON with affiliate data from S3 (updated daily by Lambda function)
  • request user's location; if available zoom map to closest affiliate
  • zoom to closest affiliate on results from Mapbox Geocoder control
  • use Haversine formula to find closest affiliate
  • show nearest/clicked/moused over affiliate info in card to the right of map

Deployment

Build deployment package

The image resizing code uses Pillow, which contains platform-specific C code. When deploying, make sure you include the Linux version in the zip file. The easiest way to do this is to create the deployment package on Linux; get a Docker container if you don't have access to a Linux box. Alternatively, you can pip install Pillow -t linux-pillow on Linux, then copy the resulting packages into the zip. You can do this just once, then freshen marchon.py as needed.

create directories for Linux deployment package

mkdir lambda-linux
mkdir lambda-linux/lambda
cp lambda/marchon.py lambda/requirements.txt lambda-linux/lambda

run Ubuntu docker container with python 3.6

docker run -v /path-to/marchon-map/lambda-linux:/lambda-linux -it --rm tomersha/docker-ubuntu-14.04-python-3.6.2

activate python 3.6, install zip, install packages, and create zip archive

pyenv shell 3.6.2
apt-get install zip
cd lambda-linux/lambda
pip install -r requirements.txt -t .
zip ../linux-lambda.zip -r .
exit

Deploy to AWS

Upload linux-lambda.zip to AWS function definitions, through AWS console or using the following CLI command

aws lambda update-function-code --function-name marchon-events-geojson --zip-file fileb://linux-lambda.zip
aws lambda update-function-code --function-name marchon-map-geojson    --zip-file fileb://linux-lambda.zip

Local setup for testing

Google sheet to GeoJSON (python)

Clone this repo and get python 3.6 set up.

Create a Google project and get API key

Set these in environment

GOOGLE_API_KEY
SHEET_ID
MAPBOX_ACCESS_TOKEN

From the lambda directory:

  • install requirements: pip install -r requirements.txt -t .
  • run python test_events.py > ../events.json

map (Vue.js)

Run a local web server: python -m SimpleHTTPServer

Go http://localhost:8000 in browser

To load a different GeoJSON data file, edit const geojson = pegasus(https://s3.amazonaws.com/ragtag-marchon/${mapjs.getAttribute('data-filename')}`);` in map.js

marchon-map's People

Contributors

colodzin avatar dependabot[bot] avatar dryan avatar iandees avatar jillh510 avatar kielni avatar lperson avatar marionnewlevant avatar mikelmaron avatar phalverson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

marchon-map's Issues

Create a map to display upcoming protests

Requirements:

  • a map like the events map in events.html, but using the output of the lambda function described in #29
  • Events should gray out the day after the event
  • For the moment, use the star image as the map marker

notify on geocoding failure

Sometimes MarchOn puts locations in the spreadsheets that the Mapbox Geocoder can't geocode (for example: Loudon County, TN). The Lambda function logs a warning, but it'd be nice to also notify MarchOn somehow so they can update the spreadsheet data.

The Lambda runs twice a day (10am/10pm PST), and ideally would send only one notification containing all geocoding errors. Email is probably the best way to get in touch with MarchOn (addresses TBD).

Portland ME event showing up in Portland OR

This event

    {
      "properties": {
        "source": "events",
        "affiliate": false,
        "name": "WM First Anniversary Celebration",
        "eventDate": "1/21/2018",
        "eventLink": "https://www.facebook.com/events/918996544925020",
        "location": "Portland, ME",
        "host": "Women's March--ME",
        "contactName": "Genevieve Morgan",
        "contactEmail": "[email protected]",
        "facebook": "",
        "twitter": "",
        "instagram": "",
        "motpLink": "https://marchonthepolls.org/event/womens-march-on-washington-maine/"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          -122.588947,
          45.485973
        ]
      },
      "type": "Feature"
    },

is showing up in Portland OR, but pretty clearly belongs in Portland ME

Gray out past events

Need a grayed-out version of the star, and display it if the event is in the past.

Event with no link or location showing up on the map

In the JSON, it appears to be the first item. I'm guessing we need to skip both the header rows in the Google sheet.

{
"id": "81f7e285696a20daf4649e70e19d5bd9",
"properties": {
"name": "Name",
"eventDate": "Date",
"eventLink": "Link",
"city": "City",
"state": "State",
"country": "Country",
"street_address": "Address",
"placeName": "Address 148&150, San Vicente, Nayarit, Mexico"
},
"geometry": {
"type": "Point",
"coordinates": [
-105.25766200000001,
20.746404
]
},
"type": "Feature"
},

Make Ragtag link open in a new tab

The Ragtag link in the map itself opens the ragtag.org page within the iframe. Please make it open either in another tab/page, or just not inside the iframe.

we_are_march_on

add filter by source to map

Add some sort of widget to filter by event type (source = "events" vs source = "actionnetwork")

  • show filter widget only on events map, not affiliate map
  • on filter, show events only from selected source

Vue error and displaying wrong data

Poking around Oregon, I notice that the Springfield/Eugene star is showing what looks like the Coos Bay popup, and giving errors inthe console:

vue.js:584 [Vue warn]: Error in render: "TypeError: Cannot read property 'month' of undefined"

(found in )
warn @ vue.js:584
logError @ vue.js:1715
globalHandleError @ vue.js:1710
handleError @ vue.js:1699
Vue._render @ vue.js:4467
updateComponent @ vue.js:2765
get @ vue.js:3113
run @ vue.js:3190
flushSchedulerQueue @ vue.js:2954
(anonymous) @ vue.js:1815
flushCallbacks @ vue.js:1736
Async Call
microTimerFunc @ vue.js:1784
nextTick @ vue.js:1828
queueWatcher @ vue.js:3041
update @ vue.js:3180
notify @ vue.js:690
reactiveSetter @ vue.js:1015
proxySetter @ vue.js:3271
showFeature @ map.js:280
boundFn @ vue.js:196
(anonymous) @ map.js:186
e @ lodash.js:10350
a @ lodash.js:10397
f @ lodash.js:10385
setTimeout (async)
Cs @ lodash.js:6663
s @ lodash.js:10434
s @ map.js:632
Evented.fire @ evented.js:94
h @ bind_handlers.js:144
u @ bind_handlers.js:80

vue.js:1719 TypeError: Cannot read property 'month' of undefined
at Proxy.eval (eval at createFunction (vue.js:10518), :2:503)
at Vue$3.Vue._render (vue.js:4465)
at Vue$3.updateComponent (vue.js:2765)
at Watcher.get (vue.js:3113)
at Watcher.run (vue.js:3190)
at flushSchedulerQueue (vue.js:2954)
at Array. (vue.js:1815)
at flushCallbacks (vue.js:1736)
at

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.