var vectorSource = new ol.source.Vector({});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Vector({
source: vectorSource
})
],
target: 'map',
view: new ol.View({
center: [45, 5],
zoom:5
})
});
var points=[];
for (i = 0; i < 10; i++) {
var xx = Math.random() * (xmax - xmin) + xmin;
var yy = Math.random() * (ymax - ymin) + ymin;
points.push(ol.proj.transform([xx,yy],'EPSG:4326', 'EPSG:3857'));
}
var thing = new ol.geom.MultiLineString([points1]);
var featurething = new ol.Feature({
name: "Thing",
geometry: thing,
style : new ol.style.Style({
stroke : new ol.style.Stroke({
color : 'red'
})
})
});
vectorSource.addFeature( featurething );
Note : It is very important to put proper source and target projection systems