Use setStyle() and drawGeometry() in examples

This commit is contained in:
Tim Schaub
2016-03-18 09:54:31 -06:00
parent cf0c4dcf3f
commit ef40f66c93
7 changed files with 86 additions and 79 deletions

View File

@@ -27,12 +27,11 @@ var map = new ol.Map({
})
});
var defaultStroke = new ol.style.Stroke({
color: '#EAE911',
width: 2
});
var defaultStyle = new ol.style.Style({
stroke: defaultStroke
var style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#EAE911',
width: 2
})
});
var flightsSource;
@@ -47,14 +46,13 @@ var pointsPerMs = 0.1;
var animateFlights = function(event) {
var vectorContext = event.vectorContext;
var frameState = event.frameState;
vectorContext.setFillStrokeStyle(null, defaultStroke);
vectorContext.setStyle(style);
var features = flightsSource.getFeatures();
for (var i = 0; i < features.length; i++) {
var feature = features[i];
if (!feature.get('finished')) {
// only draw the lines for which the animation has not
// finished yet
// only draw the lines for which the animation has not finished yet
var coords = feature.getGeometry().getCoordinates();
var elapsedTime = frameState.time - feature.get('start');
var elapsedPoints = elapsedTime * pointsPerMs;
@@ -67,10 +65,10 @@ var animateFlights = function(event) {
var currentLine = new ol.geom.LineString(coords.slice(0, maxIndex));
// directly draw the line with the vector context
vectorContext.drawLineStringGeometry(currentLine, feature);
vectorContext.drawGeometry(currentLine);
}
}
// tell OL3 to continue the postcompose animation
// tell OL3 to continue the animation
map.render();
};
@@ -119,7 +117,7 @@ var flightsLayer = new ol.layer.Vector({
// if the animation is still active for a feature, do not
// render the feature with the layer style
if (feature.get('finished')) {
return defaultStyle;
return style;
} else {
return null;
}