Files
openlayers/test/rendering/ol/style/text.test.js
2017-08-17 15:16:58 -04:00

121 lines
3.1 KiB
JavaScript

goog.require('ol.Feature');
goog.require('ol.geom.Point');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.layer.Vector');
goog.require('ol.source.Vector');
goog.require('ol.style.Text');
goog.require('ol.style.Fill');
goog.require('ol.style.Style');
goog.require('ol.style.Stroke');
describe('ol.rendering.style.Text', function() {
var map, vectorSource;
function createMap(renderer) {
vectorSource = new ol.source.Vector();
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
map = new ol.Map({
pixelRatio: 1,
target: createMapDiv(200, 200),
renderer: renderer,
layers: [vectorLayer],
view: new ol.View({
projection: 'EPSG:4326',
center: [0, 0],
resolution: 1
})
});
}
afterEach(function() {
if (map) {
disposeMap(map);
map = null;
}
});
describe('#render', function() {
function createFeatures() {
var feature;
feature = new ol.Feature({
geometry: new ol.geom.Point([-20, 18])
});
feature.setStyle(new ol.style.Style({
text: new ol.style.Text({
text: 'hello',
font: '10px'
})
}));
vectorSource.addFeature(feature);
feature = new ol.Feature({
geometry: new ol.geom.Point([-10, 0])
});
feature.setStyle(new ol.style.Style({
text: new ol.style.Text({
text: 'hello',
fill: new ol.style.Fill({
color: 'red',
font: '12px'
}),
stroke: new ol.style.Stroke({
color: '#000',
width: 3
})
})
}));
vectorSource.addFeature(feature);
feature = new ol.Feature({
geometry: new ol.geom.Point([20, 10])
});
feature.setStyle(new ol.style.Style({
text: new ol.style.Text({
rotateWithView: true,
text: 'hello',
font: '10px',
stroke: new ol.style.Stroke({
color: [10, 10, 10, 0.5]
})
})
}));
vectorSource.addFeature(feature);
}
it('tests the canvas renderer without rotation', function(done) {
createMap('canvas');
createFeatures();
expectResemble(map, 'rendering/ol/style/expected/text-canvas.png', IMAGE_TOLERANCE, done);
});
it('tests the canvas renderer with rotation', function(done) {
createMap('canvas');
createFeatures();
map.getView().setRotation(Math.PI / 7);
expectResemble(map, 'rendering/ol/style/expected/text-rotated-canvas.png', IMAGE_TOLERANCE, done);
});
where('WebGL').it('tests the webgl renderer without rotation', function(done) {
createMap('webgl');
createFeatures();
expectResemble(map, 'rendering/ol/style/expected/text-webgl.png', 1.8, done);
});
where('WebGL').it('tests the webgl renderer with rotation', function(done) {
createMap('webgl');
createFeatures();
map.getView().setRotation(Math.PI / 7);
expectResemble(map, 'rendering/ol/style/expected/text-rotated-webgl.png', 1.8, done);
});
});
});