I'm having the same issue with a line with just four vertices. I changed the number for ol.SIMPLIFY_TOLERANCE to -1, and there was no change in the rendering of the feature. If I call geometry.getSimplifiedGeometry(0), I get back all four vertices. However when rendering, only two vertices are returned. I wonder if something else needs to be changed? Polygons seem to render fine. I'm new to OpenLayers 3, so I'm sure there's a better way to get around this.
I can get the line to display properly using a style function. I put a sample of my select style below. I also created a standard style function for the vector layer. If I didn't add the style function to the select interaction, my feature would jump from a line with 4 vertices to a line with just the start and end points.
var selectStyleFunction = function (feature, resolution) {
var styles = [];
var white = [255, 255, 255, 1];
var blue = [0, 153, 255, 1];
var width = 3;
var geometry = feature.getGeometry();
var type = geometry.getType();
if (type == 'Point') {
styles.push(new ol.style.Style({
image: new ol.style.Circle({
radius: width * 2,
fill: new ol.style.Fill({
color: blue
}),
stroke: new ol.style.Stroke({
color: white,
width: width / 2
})
}),
zIndex: Infinity
}));
}
if (type == 'LineString') {
geometry.forEachSegment(function (start, end) {
styles.push(new ol.style.Style({
geometry: new ol.geom.LineString([start, end]),
stroke: new ol.style.Stroke({
color: white,
width: width + 2
})
}));
styles.push(new ol.style.Style({
geometry: new ol.geom.LineString([start, end]),
stroke: new ol.style.Stroke({
color: blue,
width: width
})
}));
});
}
if (type == 'Polygon') {
styles.push(new ol.style.Style({
fill: new ol.style.Fill({
color: [255, 255, 255, .5]
})
}));
styles.push(new ol.style.Style({
stroke: new ol.style.Stroke({
color: white,
width: width + 2
})
}));
styles.push(new ol.style.Style({
stroke: new ol.style.Stroke({
color: blue,
width: width
})
}));
}
return styles;
}
Another style that I used for a LineString feature that I added to my style function used for my vector layer. This one adds points to each vertex, and is based off of the polygon example on the OpenLayers Examples site:
if (type == horizontal') {
var coords = geometry.getCoordinates();
geometry.forEachSegment(function (start, end) {
styles.push(new ol.style.Style({
geometry: new ol.geom.LineString([start, end]),
stroke: new ol.style.Stroke({
color: [0, 128, 0, .9],
width: width + 2
}),
zIndex: 9000
}));
});
styles.push(new ol.style.Style({
image: new ol.style.Circle({
radius: width + 2,
fill: new ol.style.Fill({
color: [0, 128, 0, 2, 1]
}),
stroke: new ol.style.Stroke({
color: [255, 255, 255, 0.75],
width: width
})
}),
geometry: function () {
return new ol.geom.MultiPoint(coords);
},
zIndex: 9000
}));
}