Add OGC SOS Observations to a Map with Clustering

by openfirmware

HTML

<script src="http://canarie-sensor-rpi.github.io/geocens-js-api/javascripts/geocens.js"></script>
<link rel="stylesheet" href="http://canarie-sensor-rpi.github.io/geocens-js-api/stylesheets/leaflet.css">
<script src="http://canarie-sensor-rpi.github.io/geocens-js-api/javascripts/leaflet.js"></script>
<script src="http://canarie-sensor-rpi.github.io/geocens-js-api/javascripts/geocens-map.js"></script>
<link rel="stylesheet" href="http://canarie-sensor-rpi.github.io/geocens-js-api/stylesheets/MarkerCluster.css">
<link rel="stylesheet" href="http://canarie-sensor-rpi.github.io/geocens-js-api/stylesheets/MarkerCluster.Default.css">
<script src="http://canarie-sensor-rpi.github.io/geocens-js-api/javascripts/leaflet.markercluster.js"></script>
<div id="map"></div>

CSS

#map {
    height: 500px;
}

JavaScript

L.Icon.Default.imagePath = "http://canarie-sensor-rpi.github.io/geocens-js-api/images";

var map = L.map('map', {
    center: [51.07993, -114.131802],
    zoom: 3
});

var markers = new L.MarkerClusterGroup();

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var mapObservations = function (observations) {
    markers.addLayer(L.geocens(observations));
    map.addLayer(markers);
};

Geocens.SOS.getObservation({
    service_url: "http://app.geocens.ca:8171/sos",
    offering: "Temperature",
    property: "urn:ogc:def:property:noaa:ndbc:Water Temperature",
    done: mapObservations
});