diff --git a/src/ol/renderer/canvas/vectorlayer.js b/src/ol/renderer/canvas/vectorlayer.js index 4f971b20c7..173bef5b37 100644 --- a/src/ol/renderer/canvas/vectorlayer.js +++ b/src/ol/renderer/canvas/vectorlayer.js @@ -181,11 +181,11 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame = function(frameState, lay ol.render.canvas.rotateAtOffset(replayContext, -rotation, width / 2, height / 2); replayGroup.replay(replayContext, transform, rotation, skippedFeatureUids); - if (vectorSource.getWrapX() && projection.canWrapX()) { + if (vectorSource.getWrapX() && projection.canWrapX() && + !ol.extent.containsExtent(projectionExtent, extent)) { var startX = extent[0]; var worldWidth = ol.extent.getWidth(projectionExtent); var world = 0; - startX -= worldWidth; var offsetX; while (startX < projectionExtent[0]) { --world; @@ -196,7 +196,6 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame = function(frameState, lay } world = 0; startX = extent[2]; - startX += worldWidth; while (startX > projectionExtent[2]) { ++world; offsetX = worldWidth * world; @@ -326,7 +325,8 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame = function(frameState, lay vectorLayerRenderBuffer * resolution); var projectionExtent = viewState.projection.getExtent(); - if (vectorSource.getWrapX() && viewState.projection.canWrapX()) { + if (vectorSource.getWrapX() && viewState.projection.canWrapX() && + !ol.extent.containsExtent(projectionExtent, frameState.extent)) { // For the replay group, we need an extent that intersects the real world // (-180° to +180°). To support geometries in a coordinate range from -540° // to +540°, we add at least 1 world width on each side of the projection diff --git a/test/spec/ol/source/vector.test.js b/test/spec/ol/source/vector.test.js index 8b6db3027d..cfbc631608 100644 --- a/test/spec/ol/source/vector.test.js +++ b/test/spec/ol/source/vector.test.js @@ -1,10 +1,12 @@ - - goog.require('ol.events'); goog.require('ol.Collection'); goog.require('ol.Feature'); +goog.require('ol.Map'); +goog.require('ol.View'); goog.require('ol.geom.Point'); goog.require('ol.geom.LineString'); +goog.require('ol.layer.Vector'); +goog.require('ol.loadingstrategy'); goog.require('ol.proj'); goog.require('ol.source.Vector'); @@ -417,6 +419,44 @@ describe('ol.source.Vector', function() { describe('#loadFeatures', function() { + describe('with the "bbox" strategy', function() { + + + it('requests the view extent plus render buffer', function(done) { + var center = [-97.6114, 38.8403]; + var source = new ol.source.Vector({ + strategy: ol.loadingstrategy.bbox, + loader: function(extent) { + setTimeout(function() { + var lonLatExtent = ol.proj.transformExtent(extent, 'EPSG:3857', 'EPSG:4326'); + expect(lonLatExtent[0]).to.roughlyEqual(-99.261474609, 1e-9); + expect(lonLatExtent[2]).to.roughlyEqual(-95.965576171, 1e-9); + done(); + }, 0); + } + }); + var div = document.createElement('div'); + div.style.width = div.style.height = '100px'; + document.body.appendChild(div); + var map = new ol.Map({ + target: div, + layers: [ + new ol.layer.Vector({ + source: source + }) + ], + view: new ol.View({ + center: ol.proj.fromLonLat(center), + zoom: 7 + }) + }); + map.renderSync(); + map.setTarget(null); + document.body.removeChild(div); + }); + + }); + describe('with no loader and the "all" strategy', function() { it('stores the infinity extent in the Rtree', function() {