→ spatial storage as a service !
Usually, you implement and deploy a backend...
With Daybed, you just plug your app !
A simple REST API... for any HTTP client!
That you deploy once!
And use intuitively...
→ REST endpoints /models/<id>/definition
/models/<id>/records
Optional matrix, by model:
<script src="//js.daybed.io/build/daybed.js"></script>
var definition = { title: 'FOSDEM', description: 'Simple locations', fields : [ {name: 'location', type: 'point'}, {name: 'label', type: 'string'}, ] }; var permissions = { 'Everyone': ['create_record', 'read_all_records', 'update_all_records', 'delete_all_records'] };
var model = { definition: definition, permissions: permissions }; var server = 'https://daybed.io'; var modelId = 'a-simple-location-model-with-label'; Daybed.startSession(server) .then(function (session) { return session.saveModel(modelId, model); });
var session = new Daybed.Session(server); session.getRecords(modelId, { format: 'application/vnd.geo+json', }) .then(function (geojson) { L.geoJson(geojson).addTo(map); });
map.on('dblclick', function(e) { // LatLng to [x, y] var point = [e.latlng.lng, e.latlng.lat]; session.saveRecord(modelId, { label: 'Building', location: point }) .then(function(record) { var layer = L.marker(e.latlng).addTo(map); // Keep record id layer._recordId = record.id; }); });
layer.on('click', function () { // Using record id session.deleteRecord(model, layer._recordId) .then(function () { map.removeLayer(layer); }); });
For example, via URL hash:
var token = window.location.hash.slice(1); Daybed.startSession(server, {token: token}) .then(function (session) { window.location.hash = session.token; }) .catch(function (e) { console.error("Could not start session", e); });
The best Web companion !
var query = { ... filter: { geo_bounding_box : { location: { top: bbox.getNorthWest().lat, left: bbox.getNorthWest().lng, bottom: bbox.getSouthEast().lat, right: bbox.getSouthEast().lng } } } ... }; session.searchRecords(modelId, query) .then(function (response) { alert(response.hits.hits.length + ' results!'); });
→ Daybed on server + Turf.js on client ?
→ Think twice before implementing a custom backend!
See also
Table of contents | t |
---|---|
Exposé | ESC |
Autoscale | e |
Full screen slides | f |
Presenter view | p |
Source files | s |
Slide numbers | n |
Blank screen | b |
Notes | 2 |
Help | h |