Javascript is a very popular programming language. Once started to make web sites more dynamic, it has grown into a powerful and fast language, with several runtime environments (client- and server-side!), and support for procedural, functional, object-oriented, and modular programming paradigms. How cool is that? Moreover it is easy to learn and the basics are very simple. But most importantly, it can be executed by any web browser today! Therefore it naturally is used widely also in 52°North communities, and the Sensor Web community is no exception. However, for many good reasons, the existing Sensor Web browser client utilizes Google Web Toolkit (GWT), which compiles Java to browser-specific Javascript, and utilizes server side rendering.
But wait, today you will find an alternative to explore time series data from the standardized Sensor Observation Service (SOS): SOS.js.A Bit of History
The idea of a lightweight SOS client based only on Javascript was on the roadmap – no, let’s say “wishlist” of the Sensor Web community for some time. The existing approaches mostly utilizes the great OpenLayers SOS extension, but what if you want to integrate SOS data without a map, or with another mapping library?
Paul Breen from British Antarctic Survey (BAS) wanted to develop a more lightweight alternative with a plain Javascript solution and including client side rendering. And so he did! Made aware of his developments, 52°North approached him and the BAS agreed to make this project a 52°North open source project under the Apache License. Yay! We are extremely glad about this and in today’s blog post we want to give a quick introduction into SOS.js and encourage you to try it out and reach out to us if you also connect to OGC SOS services from Javascript – we’re looking for collaborators!
Introduction to SOS.js
The project already contains very good documentation and therefore we’ll just take some highlights from the introduction and invite you to fork the repository and try yourself.
There are two main components/files in the project: SOS.js for interaction with the server, and SOS.UI.js for generating user interface elements based on SOS concepts such as offerings and procedures.
To get the list of all offerings you can simply call the following functions:
var sos = new SOS({url: 'http://sosmet.nerc-bas.ac.uk:8080/sosmet/sos'}); sos.getCapabilities(); var offIds = sos.getOfferingIds();
Then, you can request observations and handle the results with a callback function, which using the following shorthand is just one more line of Javascript:
offering.getObservations(startDatetime, endDatetime, obsHandler);
The resulting Javascript object represents the O&M result and can be used directly:
for(var i = 0, len = offering.getCountOfObservations(); i < len; i++) { var ob = offering.getObservationRecord(i); tbody += '<tr>'; tbody += '<td>' + ob.observedPropertyTitle + '</td>'; tbody += '<td>' + ob.time + '</td>'; tbody += '<td>' + ob.result.value + ' ' + ob.uomTitle + '</td>'; tbody += '</tr>'; }
The full documentation is available on GitHub: https://github.com/52North/sos-js/blob/master/README.rst
Developers – get started right now:
git clone https://github.com/52North/sos-js.git
Live demo: http://basmet.nerc-bas.ac.uk/sos/examples/index.html
Example App
BAS shows how the library can be uses in their app for observations at several stations in the Antarctic. You can select stations interactively and then plot and explore the time series for different variables, also in a tabular view. You can even plot wind roses or calculate and display monthly means.
Goals and Next Steps
We want SOS.js to become the standard library for accessing sensor data from standardized interfaces in Javascript. It now integrates very well with OpenLayers, but other mapping and data visualisation frameworks should be supported in the future, too.
Naturally there are some limitations, such as with SOS.js you have to transfer all data values to a client – and advantage of rendering on the server side. But since you can reduce the number of data points considerably without loosing information (see great algorithms here: http://flot.base.is/), we’re thinking about tackling this on the server side as well.
We look for contributors and are very optimistic to find them – we already know there are many other projects out there using the SOS for sensor data storage and developing Javascript clients for it. Get in touch! We’re also considering aligning SOS.js with wps-js – another very new software project in the geoprocessing community – and have some ideas of connecting it to the timeseries-api. As of now SOS.js and the Javascript libraries using the timeseries-api are complementary products, but we’ll investigate how they can work together.
Leave a Reply