Skip to content

Instantly share code, notes, and snippets.

@philsmy
Created May 13, 2020 04:10
Show Gist options
  • Save philsmy/7365139dbe0063fd53cbdcb197b88081 to your computer and use it in GitHub Desktop.
Save philsmy/7365139dbe0063fd53cbdcb197b88081 to your computer and use it in GitHub Desktop.
Getting the data for the Map
# frozen_string_literal: true
class OntarioController < ApplicationController
protect_from_forgery except: :map_data
def map_data
@patients = PatientDatum.where(region: 'ON').group(:reporter, :reporter_latitude, :reporter_longitude, :reporter_website).count
@patient_map = @patients.keys.map do |key|
{
'type': 'Feature',
"geometry": {
"type": 'Point',
"coordinates": [
key[2],
key[1]
]
},
"properties": {
'reporter': key[0],
'num_cases': @patients[key],
'website': key[3]
}
}
end
result_string = "eqfeed_callback({ 'type': 'FeatureCollection', 'features': #{@patient_map.to_json} });"
respond_to do |format|
format.js { render json: result_string }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment