diff --git a/src/ol/featureoverlay.js b/src/ol/featureoverlay.js index 3aa6b1e045..39644d15f8 100644 --- a/src/ol/featureoverlay.js +++ b/src/ol/featureoverlay.js @@ -10,7 +10,7 @@ goog.require('ol.CollectionEventType'); goog.require('ol.Feature'); goog.require('ol.feature'); goog.require('ol.render.EventType'); -goog.require('ol.style.ImageState'); +goog.require('ol.renderer.vector'); @@ -101,37 +101,6 @@ ol.FeatureOverlay.prototype.addFeature = function(feature) { }; -/** - * @param {ol.render.IVectorContext|undefined} vectorContext Vector context. - * @param {ol.Feature} feature Feature. - * @param {ol.style.Style} style Style. - * @private - */ -ol.FeatureOverlay.prototype.drawFeature_ = function(vectorContext, feature, - style) { - var imageStyle = style.getImage(); - if (!goog.isNull(imageStyle)) { - var imageState = imageStyle.getImageState(); - if (imageState == ol.style.ImageState.LOADED || - imageState == ol.style.ImageState.ERROR) { - imageStyle.unlistenImageChange(this.handleImageChange_, this); - if (imageState == ol.style.ImageState.LOADED) { - vectorContext.drawFeature(feature, style); - } - } else { - if (imageState == ol.style.ImageState.IDLE) { - imageStyle.load(); - } - imageState = imageStyle.getImageState(); - goog.asserts.assert(imageState == ol.style.ImageState.LOADING); - imageStyle.listenImageChange(this.handleImageChange_, this); - } - } else { - vectorContext.drawFeature(feature, style); - } -}; - - /** * @return {ol.Collection} Features collection. * @todo api @@ -199,8 +168,14 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) { if (!goog.isDef(styleFunction)) { styleFunction = ol.feature.defaultStyleFunction; } - var resolution = event.frameState.view2DState.resolution; - var vectorContext = event.vectorContext; + var replayGroup = /** @type {ol.render.IReplayGroup} */ + (event.replayGroup); + goog.asserts.assert(goog.isDef(replayGroup)); + var frameState = event.frameState; + var pixelRatio = frameState.pixelRatio; + var resolution = frameState.view2DState.resolution; + var squaredTolerance = + resolution * resolution / (4 * pixelRatio * pixelRatio); var i, ii, styles; this.features_.forEach(function(feature) { styles = styleFunction(feature, resolution); @@ -209,7 +184,8 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) { } ii = styles.length; for (i = 0; i < ii; ++i) { - this.drawFeature_(vectorContext, feature, styles[i]); + ol.renderer.vector.renderFeature(replayGroup, feature, styles[i], + squaredTolerance, feature, this.handleImageChange_, this); } }, this); }; diff --git a/test/spec/ol/featureoverlay.test.js b/test/spec/ol/featureoverlay.test.js deleted file mode 100644 index fe46d74f4f..0000000000 --- a/test/spec/ol/featureoverlay.test.js +++ /dev/null @@ -1,70 +0,0 @@ -goog.provide('ol.test.FeatureOverlay'); - -describe('ol.Feature', function() { - var featureOverlay; - - beforeEach(function() { - featureOverlay = new ol.FeatureOverlay(); - }); - - afterEach(function() { - ol.style.IconImageCache.getInstance().clear(); - }); - - describe('#drawFeature_ style with no image', function() { - it('calls vectorContext.drawFeature', function() { - var vectorContext = new ol.render.canvas.Immediate( - null, // context - 1, // pixelRatio - [], // extent - goog.vec.Mat4.createNumberIdentity(), // transform - 0 // viewRotation - ); - var feature = new ol.Feature(); - var style = new ol.style.Style({ - fill: new ol.style.Fill({ - color: '#ffffff' - }) - }); - - var spy = sinon.spy(vectorContext, 'drawFeature'); - featureOverlay.drawFeature_(vectorContext, feature, style); - expect(spy.calledOnce).to.be.ok(); - }); - }); - - describe('#drawFeature_ style with unloaded image', function() { - it('calls image.load', function() { - var vectorContext = new ol.render.canvas.Immediate( - null, // context - 1, // pixelRatio - [], // extent - goog.vec.Mat4.createNumberIdentity(), // transform - 0 // viewRotation - ); - var feature = new ol.Feature(); - var style = new ol.style.Style({ - image: new ol.style.Icon({ - src: 'http://example.com/icon.png' - }) - }); - - var stub = sinon.stub(style.getImage(), 'load', function() { - style.getImage().iconImage_.imageState_ = - ol.style.ImageState.LOADING; - }); - featureOverlay.drawFeature_(vectorContext, feature, style); - expect(stub.calledOnce).to.be.ok(); - }); - }); -}); - -goog.require('goog.vec.Mat4'); -goog.require('ol.Feature'); -goog.require('ol.FeatureOverlay'); -goog.require('ol.style.ImageState'); -goog.require('ol.render.canvas.Immediate'); -goog.require('ol.style.Fill'); -goog.require('ol.style.Icon'); -goog.require('ol.style.IconImageCache'); -goog.require('ol.style.Style');