I need to make a heatmap with a bunch of linestrings using AngularJS and Open Layers 3. I didn't find any examples, just a question answered here but that don't worked for me! I have a service that creates all the layers on my map, I need this heatmap to be a layer, so that way I can set it visible or not. LayerService:
/**
* Routes is the list of routes that contains the linestring
* inside the "geom" property.
*/
LayerService.routesHeatMap = function (routes, blur, radius) {
const centroids = [];
routes.forEach(route => {
const geometry = route.geom;
if (!!geometry) {
const point_feature = new ol.Feature({ weight: route.expansion });
point_feature.setGeometry(new ol.geom.LineString(geometry.coordinates));
point_feature.setProperties({ projection: "EPSG:4326" });
centroids.push(point_feature);
}
});
let vector = new ol.layer.Heatmap({
title: 'Routes. Heatmap',
source: new ol.source.Vector({
features: new ol.Collection(centroids),
overlaps: true,
opacity: 1,
visible: false,
format: new ol.format.GeoJSON({
dataProjection: 'EPSG:4326'
})
}),
zIndex: 1,
gradient: ['#007700', '#6ce200', '#efef00', '#ffff00', '#ff6600', '#ff0000'],
blur: parseInt(blur.value, 10),
radius: parseInt(radius.value, 10)
});
return vector;
};
My controller that have my map:
var blur = document.getElementById('blur');
var radius = document.getElementById('radius');
heat = LayerService.routesHeatMap(response, blur, radius);
vm.map.addLayer(heat);