turf-isolines
Takes a FeatureCollection of points with z values and an array of value breaks and generates isolines. These are commonly used to create elevation maps, but can be used for general data interpolation as well.
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://rawcdn.githack.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
<link rel="stylesheet" href="assets/css/styles.css" type="text/css">
<script src="//cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>
<script src="https://rawcdn.githack.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js" type="text/javascript"></script>
<script src="assets/js/es6-promise.min.js"></script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,fetch"></script>
<script src="assets/js/helpers.js"></script>
<title>Turf and OpenLayers 3 - Isolines</title>
</head>
<body>
<div id="map" class="map"></div>
<script type="text/javascript">
// Declare a source and directly embed the GeoJSON using the
// "experimental parameter "object"
var vectorSource = new ol.source.Vector();
// Declare a vector layer with the already
// created source containing added features
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
// Instanciate a map and add layers
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vectorLayer
],
view: new ol.View({
center: ol.proj.fromLonLat([4.52475, 45.47611]),
zoom: 7
})
});
fetch('assets/data/france_meteo.geojson').then(function(response) {
return response.json().then(function(points_fc) {
var breaks = [
990, 992, 994, 996, 998,
1000, 1002, 1004, 1006, 1008,
1010, 1012, 1014, 1016, 1018,
1020, 1022, 1024, 1026, 1028,
1030, 1032
];
var isolines = turf.isolines(points_fc, 'pressure', 100, breaks);
vectorSource.addFeatures(geojsonToFeatures(isolines, {
featureProjection: 'EPSG:3857'
}));
});
});
</script>
</body>
</html>