Add vectorContext.setStyle() method
This commit is contained in:
@@ -461,6 +461,20 @@ ol.render.canvas.Immediate.prototype.drawCircleGeometry = function(circleGeometr
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the rendering style. Note that since this is an immediate rendering API,
|
||||
* any `zIndex` on the provided style will be ignored.
|
||||
*
|
||||
* @param {ol.style.Style} style The rendering style.
|
||||
* @api
|
||||
*/
|
||||
ol.render.canvas.Immediate.prototype.setStyle = function(style) {
|
||||
this.setFillStrokeStyle(style.getFill(), style.getStroke());
|
||||
this.setImageStyle(style.getImage());
|
||||
this.setTextStyle(style.getText());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Render a feature into the canvas. In order to respect the zIndex of the
|
||||
* style this method draws asynchronously and thus *after* calls to
|
||||
|
||||
@@ -25,6 +25,33 @@ describe('ol.render.canvas.Immediate', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setStyle()', function() {
|
||||
it('calls the more specific methods with style parts', function() {
|
||||
var context = new ol.render.canvas.Immediate();
|
||||
sinon.spy(context, 'setFillStrokeStyle');
|
||||
sinon.spy(context, 'setImageStyle');
|
||||
sinon.spy(context, 'setTextStyle');
|
||||
var fill = new ol.style.Fill({});
|
||||
var stroke = new ol.style.Stroke({});
|
||||
var text = new ol.style.Text({});
|
||||
var image = new ol.style.Circle({});
|
||||
var style = new ol.style.Style({
|
||||
fill: fill,
|
||||
stroke: stroke,
|
||||
image: image,
|
||||
text: text
|
||||
});
|
||||
|
||||
context.setStyle(style);
|
||||
expect(context.setFillStrokeStyle.calledOnce).to.be(true);
|
||||
expect(context.setFillStrokeStyle.firstCall.calledWithExactly(fill, stroke)).to.be(true);
|
||||
expect(context.setImageStyle.calledOnce).to.be(true);
|
||||
expect(context.setImageStyle.firstCall.calledWithExactly(image)).to.be(true);
|
||||
expect(context.setTextStyle.calledOnce).to.be(true);
|
||||
expect(context.setTextStyle.firstCall.calledWithExactly(text)).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#drawMultiPolygonGeometry', function() {
|
||||
it('creates the correct canvas instructions for 3D geometries', function() {
|
||||
var log = {
|
||||
@@ -120,3 +147,8 @@ describe('ol.render.canvas.Immediate', function() {
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.render.VectorContext');
|
||||
goog.require('ol.render.canvas.Immediate');
|
||||
goog.require('ol.style.Circle');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
goog.require('ol.style.Text');
|
||||
|
||||
Reference in New Issue
Block a user