-
Notifications
You must be signed in to change notification settings - Fork 9
dataSources
The dataSources section of main.js is where you enter APIs where you will get data and related records for an address.
The parameters for any data source include:
parameter | description or example |
---|---|
id | an id for the data source |
type | one of the 4 data source types |
url | the url endpoint |
options | an object for adding details for the ajax call |
|options|an object for adding details for the ajax call|
There are different kinds of dataSource retrievals:
For instance, Office of Property Assessment (OPA) data for the City of Philadelphia can be accessed through the API with the URL 'https://data.phila.gov/resource/w7rb-qrn8.json'. To make an 'ajax' call to this URL, you can create a dataSource (which you could call 'opa'), and give it a 'type' of 'http-get' (the generic type for a general 'ajax' call), and a 'url' of the URL above.
Further details about options for each type of dataSource retrieval are documented in the individual pages linked above.
Example:
dataSources: {
// each source has a unique key, e.g. `opa`
opa: {
// the type of call to make
type: 'http-get',
// the base url of the api
url: 'https://data.phila.gov/resource/w7rb-qrn8.json',
// all options
options: {
// query string parameters to be added to the url
params: {
// each param is mapped to a function that gets passed the current
// address feature. use attributes from this feature to form data queries.
// in this case, a param of `?parcel_number=<opa_account_num>` will be
// appended to the url.
parcel_number: function (feature) { return feature.properties.opa_account_num; }
},
// a callback that unpacks the desired record(s) from the api. this
// data will be kept in state and made available in the topic panel.
success: function (data) {
return data[0];
}
}
}
},