diff --git a/examples/dynamic-data.js b/examples/dynamic-data.js index 26f4f3fc1c..41a3d3431a 100644 --- a/examples/dynamic-data.js +++ b/examples/dynamic-data.js @@ -25,11 +25,13 @@ var map = new ol.Map({ }) }); -var imageStyle = new ol.style.Circle({ - radius: 5, - snapToPixel: false, - fill: new ol.style.Fill({color: 'yellow'}), - stroke: new ol.style.Stroke({color: 'red', width: 1}) +var imageStyle = new ol.style.Style({ + image: new ol.style.Circle({ + radius: 5, + snapToPixel: false, + fill: new ol.style.Fill({color: 'yellow'}), + stroke: new ol.style.Stroke({color: 'red', width: 1}) + }) }); var headInnerImageStyle = new ol.style.Style({ @@ -40,10 +42,12 @@ var headInnerImageStyle = new ol.style.Style({ }) }); -var headOuterImageStyle = new ol.style.Circle({ - radius: 5, - snapToPixel: false, - fill: new ol.style.Fill({color: 'black'}) +var headOuterImageStyle = new ol.style.Style({ + image: new ol.style.Circle({ + radius: 5, + snapToPixel: false, + fill: new ol.style.Fill({color: 'black'}) + }) }); var n = 200; @@ -63,16 +67,16 @@ map.on('postcompose', function(event) { var y = (R + r) * Math.sin(t) + p * Math.sin((R + r) * t / r); coordinates.push([x, y]); } - vectorContext.setImageStyle(imageStyle); - vectorContext.drawMultiPointGeometry( - new ol.geom.MultiPoint(coordinates), null); + vectorContext.setStyle(imageStyle); + vectorContext.drawGeometry(new ol.geom.MultiPoint(coordinates)); var headPoint = new ol.geom.Point(coordinates[coordinates.length - 1]); - var headFeature = new ol.Feature(headPoint); - vectorContext.drawFeature(headFeature, headInnerImageStyle); - vectorContext.setImageStyle(headOuterImageStyle); - vectorContext.drawMultiPointGeometry(headPoint, null); + vectorContext.setStyle(headOuterImageStyle); + vectorContext.drawGeometry(headPoint); + + vectorContext.setStyle(headInnerImageStyle); + vectorContext.drawGeometry(headPoint); map.render(); }); diff --git a/examples/earthquake-custom-symbol.js b/examples/earthquake-custom-symbol.js index 6d0016a174..bbe4c56827 100644 --- a/examples/earthquake-custom-symbol.js +++ b/examples/earthquake-custom-symbol.js @@ -25,13 +25,14 @@ var styleFunction = function(feature) { if (!style) { var canvas = /** @type {HTMLCanvasElement} */ (document.createElement('canvas')); - var render = ol.render.toContext( + var vectorContext = ol.render.toContext( /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d')), {size: [size + 2, size + 2], pixelRatio: size / 10}); - render.setFillStrokeStyle( - new ol.style.Fill({color: 'rgba(255, 153, 0, 0.4)'}), - new ol.style.Stroke({color: 'rgba(255, 204, 0, 0.2)', width: 1})); - render.drawPolygonGeometry(new ol.geom.Polygon( + vectorContext.setStyle(new ol.style.Style({ + fill: new ol.style.Fill({color: 'rgba(255, 153, 0, 0.4)'}), + stroke: new ol.style.Stroke({color: 'rgba(255, 204, 0, 0.2)', width: 1}) + })); + vectorContext.drawGeometry(new ol.geom.Polygon( [[[0, 0], [4, 2], [6, 0], [10, 5], [6, 3], [4, 5], [0, 0]]])); style = new ol.style.Style({ image: new ol.style.Icon({ diff --git a/examples/feature-animation.js b/examples/feature-animation.js index e6ba2c15f3..e3211d8f67 100644 --- a/examples/feature-animation.js +++ b/examples/feature-animation.js @@ -12,6 +12,7 @@ goog.require('ol.source.OSM'); goog.require('ol.source.Vector'); goog.require('ol.style.Circle'); goog.require('ol.style.Stroke'); +goog.require('ol.style.Style'); var map = new ol.Map({ @@ -67,17 +68,19 @@ function flash(feature) { var radius = ol.easing.easeOut(elapsedRatio) * 25 + 5; var opacity = ol.easing.easeOut(1 - elapsedRatio); - var flashStyle = new ol.style.Circle({ - radius: radius, - snapToPixel: false, - stroke: new ol.style.Stroke({ - color: 'rgba(255, 0, 0, ' + opacity + ')', - width: 1 + var style = new ol.style.Style({ + image: new ol.style.Circle({ + radius: radius, + snapToPixel: false, + stroke: new ol.style.Stroke({ + color: 'rgba(255, 0, 0, ' + opacity + ')', + width: 0.25 + opacity + }) }) }); - vectorContext.setImageStyle(flashStyle); - vectorContext.drawPointGeometry(flashGeom, null); + vectorContext.setStyle(style); + vectorContext.drawGeometry(flashGeom); if (elapsed > duration) { ol.Observable.unByKey(listenerKey); return; diff --git a/examples/flight-animation.js b/examples/flight-animation.js index d6c5fd5a56..c48b97071e 100644 --- a/examples/flight-animation.js +++ b/examples/flight-animation.js @@ -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; } diff --git a/examples/igc.js b/examples/igc.js index fabe56dad5..2658abc951 100644 --- a/examples/igc.js +++ b/examples/igc.js @@ -152,27 +152,26 @@ map.on('click', function(evt) { displaySnap(evt.coordinate); }); -var imageStyle = new ol.style.Circle({ - radius: 5, - fill: null, - stroke: new ol.style.Stroke({ - color: 'rgba(255,0,0,0.9)', - width: 1 - }) -}); -var strokeStyle = new ol.style.Stroke({ +var stroke = new ol.style.Stroke({ color: 'rgba(255,0,0,0.9)', width: 1 +}) +var style = new ol.style.Style({ + stroke: stroke, + image: new ol.style.Circle({ + radius: 5, + fill: null, + stroke: stroke + }) }); map.on('postcompose', function(evt) { var vectorContext = evt.vectorContext; + vectorContext.setStyle(style); if (point !== null) { - vectorContext.setImageStyle(imageStyle); - vectorContext.drawPointGeometry(point); + vectorContext.drawGeometry(point); } if (line !== null) { - vectorContext.setFillStrokeStyle(null, strokeStyle); - vectorContext.drawLineStringGeometry(line); + vectorContext.drawGeometry(line); } }); @@ -184,8 +183,7 @@ var featureOverlay = new ol.layer.Vector({ radius: 5, fill: new ol.style.Fill({ color: 'rgba(255,0,0,0.9)' - }), - stroke: null + }) }) }) }); diff --git a/examples/render-geometry.js b/examples/render-geometry.js index 0540a66a81..0dd1eb1620 100644 --- a/examples/render-geometry.js +++ b/examples/render-geometry.js @@ -5,21 +5,25 @@ goog.require('ol.render'); goog.require('ol.style.Circle'); goog.require('ol.style.Fill'); goog.require('ol.style.Stroke'); +goog.require('ol.style.Style'); var canvas = document.getElementById('canvas'); -var render = ol.render.toContext(canvas.getContext('2d'), {size: [100, 100]}); +var vectorContext = ol.render.toContext(canvas.getContext('2d'), {size: [100, 100]}); var fill = new ol.style.Fill({color: 'blue'}); var stroke = new ol.style.Stroke({color: 'black'}); -render.setFillStrokeStyle(fill, stroke); -render.setImageStyle(new ol.style.Circle({ - radius: 10, +var style = new ol.style.Style({ fill: fill, - stroke: stroke -})); + stroke: stroke, + image: new ol.style.Circle({ + radius: 10, + fill: fill, + stroke: stroke + }) +}) +vectorContext.setStyle(style); -render.drawLineStringGeometry(new ol.geom.LineString([[10, 10], [90, 90]])); -render.drawPolygonGeometry( - new ol.geom.Polygon([[[2, 2], [98, 2], [2, 98], [2, 2]]])); -render.drawPointGeometry(new ol.geom.Point([88, 88])); +vectorContext.drawGeometry(new ol.geom.LineString([[10, 10], [90, 90]])); +vectorContext.drawGeometry(new ol.geom.Polygon([[[2, 2], [98, 2], [2, 98], [2, 2]]])); +vectorContext.drawGeometry(new ol.geom.Point([88, 88])); diff --git a/examples/synthetic-points.js b/examples/synthetic-points.js index 21c1eaf713..4c1e672bf0 100644 --- a/examples/synthetic-points.js +++ b/examples/synthetic-points.js @@ -96,27 +96,26 @@ map.on('click', function(evt) { displaySnap(evt.coordinate); }); -var imageStyle = new ol.style.Circle({ - radius: 10, - fill: null, - stroke: new ol.style.Stroke({ - color: 'rgba(255,255,0,0.9)', - width: 3 - }) -}); -var strokeStyle = new ol.style.Stroke({ +var stroke = new ol.style.Stroke({ color: 'rgba(255,255,0,0.9)', width: 3 }); +var style = new ol.style.Style({ + stroke: stroke, + image: new ol.style.Circle({ + radius: 10, + stroke: stroke + }) +}); + map.on('postcompose', function(evt) { var vectorContext = evt.vectorContext; + vectorContext.setStyle(style); if (point !== null) { - vectorContext.setImageStyle(imageStyle); - vectorContext.drawPointGeometry(point); + vectorContext.drawGeometry(point); } if (line !== null) { - vectorContext.setFillStrokeStyle(null, strokeStyle); - vectorContext.drawLineStringGeometry(line); + vectorContext.drawGeometry(line); } });