Created
May 13, 2020 04:10
-
-
Save philsmy/7365139dbe0063fd53cbdcb197b88081 to your computer and use it in GitHub Desktop.
Getting the data for the Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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