Get rid of ol.FeatureOverlay

This also introduces a wrapX option to the Draw, Modify and Select
interaction.
This commit is contained in:
Andreas Hocevar
2015-06-09 13:25:51 +02:00
parent 54da473991
commit 53d5d8c1d9
28 changed files with 177 additions and 676 deletions

View File

@@ -1,42 +0,0 @@
goog.provide('ol.test.FeatureOverlay');
describe('ol.FeatureOverlay', function() {
describe('constructor', function() {
it('creates an new feature overlay', function() {
var featureOverlay = new ol.FeatureOverlay();
expect(featureOverlay).to.be.a(ol.FeatureOverlay);
});
it('takes features', function() {
var featureOverlay = new ol.FeatureOverlay({
features: [new ol.Feature(new ol.geom.Point([0, 0]))]
});
expect(featureOverlay.getFeatures().getLength()).to.be(1);
});
it('takes a style', function() {
var style = [new ol.style.Style()];
var featureOverlay = new ol.FeatureOverlay({
style: [new ol.style.Style()]
});
expect(featureOverlay.getStyle()).to.eql(style);
expect(featureOverlay.getStyleFunction()()).to.eql(style);
});
it('takes a map', function() {
var map = new ol.Map({});
var featureOverlay = new ol.FeatureOverlay({
map: map
});
expect(featureOverlay.getMap()).to.eql(map);
});
});
});
goog.require('ol.Feature');
goog.require('ol.FeatureOverlay');
goog.require('ol.Map');
goog.require('ol.geom.Point');
goog.require('ol.style.Style');

View File

@@ -619,17 +619,19 @@ describe('ol.interaction.Draw', function() {
describe('#setActive(false)', function() {
it('unsets the map from the feature overlay', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setActive(false);
expect(interaction.overlay_.map_).to.be(null);
expect(spy.getCall(0).args[0]).to.be(null);
});
it('aborts the drawing', function() {
interaction.setActive(false);
expect(interaction.sketchFeature_).to.be(null);
});
it('fires change:active', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
var listenerSpy = sinon.spy(function() {
// test that the interaction's change:active listener is called first
expect(interaction.overlay_.map_).to.be(null);
expect(spy.getCall(0).args[0]).to.be(null);
});
interaction.on('change:active', listenerSpy);
interaction.setActive(false);
@@ -642,13 +644,15 @@ describe('ol.interaction.Draw', function() {
interaction.setActive(false);
});
it('sets the map into the feature overlay', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setActive(true);
expect(interaction.overlay_.map_).to.be(map);
expect(spy.getCall(0).args[0]).to.be(map);
});
it('fires change:active', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
var listenerSpy = sinon.spy(function() {
// test that the interaction's change:active listener is called first
expect(interaction.overlay_.map_).not.to.be(null);
expect(spy.getCall(0).args[0]).to.be(map);
});
interaction.on('change:active', listenerSpy);
interaction.setActive(true);
@@ -682,8 +686,9 @@ describe('ol.interaction.Draw', function() {
});
describe('#setMap(null) when interaction is active', function() {
it('unsets the map from the feature overlay', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setMap(null);
expect(interaction.overlay_.map_).to.be(null);
expect(spy.getCall(0).args[0]).to.be(null);
});
it('aborts the drawing', function() {
interaction.setMap(null);
@@ -695,15 +700,17 @@ describe('ol.interaction.Draw', function() {
describe('#setMap(map)', function() {
describe('#setMap(map) when interaction is active', function() {
it('sets the map into the feature overlay', function() {
var spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setMap(map);
expect(interaction.overlay_.map_).to.be(map);
expect(spy.getCall(0).args[0]).to.be(map);
});
});
describe('#setMap(map) when interaction is not active', function() {
it('does not set the map into the feature overlay', function() {
interaction.setActive(false);
var spy = sinon.spy(interaction.overlay_, 'setMap');
interaction.setMap(map);
expect(interaction.overlay_.map_).to.be(null);
expect(spy.getCall(0).args[0]).to.be(null);
});
});

View File

@@ -219,15 +219,8 @@ describe('ol.interaction.Select', function() {
beforeEach(function() {
interaction.setActive(false);
});
it('sets the map into the feature overlay', function() {
interaction.setActive(true);
expect(interaction.featureOverlay_.map_).to.be(map);
});
it('fires change:active', function() {
var listenerSpy = sinon.spy(function() {
// test that the interaction's change:active listener is called first
expect(interaction.featureOverlay_.map_).not.to.be(null);
});
var listenerSpy = sinon.spy();
interaction.on('change:active', listenerSpy);
interaction.setActive(true);
expect(listenerSpy.callCount).to.be(1);
@@ -253,8 +246,9 @@ describe('ol.interaction.Select', function() {
});
describe('#setMap(null) when interaction is active', function() {
it('unsets the map from the feature overlay', function() {
var spy = sinon.spy(interaction.featureOverlay_, 'setMap');
interaction.setMap(null);
expect(interaction.featureOverlay_.map_).to.be(null);
expect(spy.getCall(0).args[0]).to.be(null);
});
});
});
@@ -262,8 +256,9 @@ describe('ol.interaction.Select', function() {
describe('#setMap(map)', function() {
describe('#setMap(map) when interaction is active', function() {
it('sets the map into the feature overlay', function() {
var spy = sinon.spy(interaction.featureOverlay_, 'setMap');
interaction.setMap(map);
expect(interaction.featureOverlay_.map_).to.be(map);
expect(spy.getCall(0).args[0]).to.be(map);
});
});
});

View File

@@ -31,52 +31,6 @@ describe('ol.renderer.canvas.Map', function() {
renderer.layerRenderers_[goog.getUid(layer)] = layerRenderer;
});
it('uses correct extent and offset on wrapped worlds', function() {
var spy = sinon.spy(renderer, 'getTransform');
var proj = new ol.proj.Projection({
code: 'foo',
extent: [-180, -90, 180, 90],
global: true
});
var frameState = {
coordinateToPixelMatrix: map.coordinateToPixelMatrix_,
pixelToCoordinateMatrix: map.pixelToCoordinateMatrix_,
pixelRatio: 1,
size: [100, 100],
skippedFeatureUids: {},
extent: proj.getExtent(),
viewState: {
center: [0, 0],
projection: proj,
resolution: 1,
rotation: 0
},
layerStates: {},
layerStatesArray: [{
layer: layer,
sourceState: 'ready',
visible: true,
minResolution: 1,
maxResolution: 2
}],
postRenderFunctions: []
};
frameState.focus = [0, 0];
// focus is on real world
renderer.renderFrame(frameState);
expect(spy.getCall(0).args[1]).to.be(0);
expect(renderer.replayGroup.maxExtent_).to.eql([-180, -90, 180, 90]);
frameState.focus = [-200, 0];
// focus is one world left of the real world
renderer.renderFrame(frameState);
expect(spy.getCall(1).args[1]).to.be(360);
expect(renderer.replayGroup.maxExtent_).to.eql([180, -90, 540, 90]);
frameState.focus = [200, 0];
// focus is one world right of the real world
renderer.renderFrame(frameState);
expect(spy.getCall(2).args[1]).to.be(-360);
expect(renderer.replayGroup.maxExtent_).to.eql([-540, -90, -180, 90]);
});
});
});
@@ -84,7 +38,6 @@ describe('ol.renderer.canvas.Map', function() {
goog.require('ol.layer.Vector');
goog.require('ol.Map');
goog.require('ol.proj.Projection');
goog.require('ol.renderer.canvas.Layer');
goog.require('ol.renderer.canvas.Map');
goog.require('ol.source.Vector');