Developing with ArcGIS Open Data
Mike Juniper :: Washington DC R&D Center
Brooks Robertson :: Washington DC R&D Center
Daniel Fenton :: Washington DC R&D Center
ArcGIS Open Data
Make your authoritative data:
Discoverable
Explorable
Accessible
but what if...
site customization capabilities insufficient
bring AGO OD into existing website
expose data from other systems in ArcGIS OD
koop
Feature Services from APIs
Open Source (github.com/Esri/koop ) R & D
node js
geojson (& others) ==> feature services
feature services ==> geojson
export as kml, csv, shp
OpenSearch & DCAT
Daniel Fenton
Open Data API
Brooks Robertson
What is an API?
"In computer programming, an application programming interface (API) is a set of routines, protocols, and tools for building software applications. An API expresses a software component in terms of its operations, inputs, outputs, and underlying types."
Totally clear right?
Simple API example
http://opendata.arcgis.com
/datasets
.json
?q=water&sort_by=relevance&page=1
OpenData V1 API (beta)
HTTP protocol (GET, POST, PUT, DELETE)
opendata.arcgis.com
OR
imap.maryland.opendata.arcgis.com
Available resources /datasets, /sites
JSON format
Who consumes the OpenData API?
Opendata "Umbrella" (Backbone)
OpenData Custom Sites (Backbone)
OpenData Admin (Angular)
OpenData V2 API (public)
Versioning via URL or Headers
/api/v2/...
Accept: application/vnd.arcgis+json; version=2
OpenData V2 API (public) continued..
Consistent return of an object or list of objects based on resource
/api/v2/datasets.json -> {"datasets": []}
/api/v2/datasets/:id.json -> {"dataset": {}}
OpenData V2 API (public) continued..
Authenticated access
Caching via Etag and If-None-Match header
Appropriate HTTP Status codes
Well documented
What can you do with it?
Build an app!
Open Data is built against the same API
A static website that makes http requests for data
$.getJSON('http://my.api.url')
.done(function (response, status, xhr) {
/* stuff it into the DOM... */
})
.fail(function (xhr, status, error) {
/* do something about the error! */
});
if you're familiar with jquery, you might do something like this
$.getJSON('http://my.api.url')
.done(function (response, status, xhr) {
/* do something with the response! */
})
.fail(function (xhr, status, error) {
/* do something about the error! */
});
but unless you're building a trivial app, don't do it that way
MV*
use an mvc framework instead
Choosing the Best JavaScript Framework for You
Friday, 13 Mar 2015, 1:00pm - 2:00pm
Key endpoints:
/datasets.json?q=<search string>&page=<page number>
$.getJSON(MyApiUrl + '/datasets.json?q=water&page=1');
$.getJSON(MyApiUrl + '/datasets/abc123.json');
jsonview
overall structure of the JSON
key attributes:
id
item_type
type
url - which is another api from which you can get the actual data
And maybe:
/datasets/<id>/related.json
$.getJSON(MyApiUrl + '/datasets/abc123/related.json');
And:
/datasets/autocomplete?query=<search string>
$.getJSON(MyApiUrl + '/datasets/autocomplete?query=wat');
Errors...
errors are handled how you'd expect - http status code
$.getJSON('http://my.api.url')
.done(function (response, status, xhr) {
if (response.error) {
/* you don't have to do this! */
}
})
.fail(function (xhr, status, error) {
switch (xhr.status) {
case 404:
/* handle 404 */
default:
/* handle other errors */
}
});
so you can handle errors like you'd expect
Gotcha's:
Currently no JSONP support
Does support CORS
But ... IE < 10
Backbone & Marionette because I know them well and could build it quickly
Also because even if you don't use them, it's pretty easy to understand
Bootstrap because it's widely known, well documented, and extensible
Ok,... how?
$ git clone
$ cd opendata-backbone
$ npm install
$ bower install
$ gulp serve
DatasetCollection = Backbone.Collection.extend({
url: function () {
//get the params (q=, page=, etc) from somewhere...
var queryParams = '';
return MyOD.config.api + 'datasets.json?' + queryParams;
},
parse: function (resp) {
return resp.data;
}
});
and
DatasetModel = Backbone.Model.extend({
url: function () {
return MyOD.config.api + 'datasets/' + this.get('id') + '.json';
},
parse: function (response) {
return response.data;
}
});