Add ol.style.Icon tests for getAnchor and getOrigin
This commit is contained in:
@@ -1,5 +1,116 @@
|
||||
goog.provide('ol.test.style.Icon');
|
||||
goog.provide('ol.test.style.IconImageCache');
|
||||
|
||||
goog.require('ol.style.Icon');
|
||||
goog.require('ol.style.IconAnchorUnits');
|
||||
goog.require('ol.style.IconOrigin');
|
||||
|
||||
|
||||
describe('ol.style.Icon', function() {
|
||||
var size = [36, 48];
|
||||
|
||||
describe('#getAnchor', function() {
|
||||
var fractionAnchor = [0.25, 0.25];
|
||||
|
||||
it('uses fractional units by default', function() {
|
||||
var iconStyle = new ol.style.Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
anchor: fractionAnchor
|
||||
});
|
||||
expect(iconStyle.getAnchor()).to.eql([9, 12]);
|
||||
});
|
||||
|
||||
it('uses pixels units', function() {
|
||||
var iconStyle = new ol.style.Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
anchor: [2, 18],
|
||||
anchorXUnits: ol.style.IconAnchorUnits.PIXELS,
|
||||
anchorYUnits: ol.style.IconAnchorUnits.PIXELS
|
||||
});
|
||||
expect(iconStyle.getAnchor()).to.eql([2, 18]);
|
||||
});
|
||||
|
||||
it('uses a bottom left anchor origin', function() {
|
||||
var iconStyle = new ol.style.Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
anchor: fractionAnchor,
|
||||
anchorOrigin: ol.style.IconOrigin.BOTTOM_LEFT
|
||||
});
|
||||
expect(iconStyle.getAnchor()).to.eql([9, 36]);
|
||||
});
|
||||
|
||||
it('uses a bottom right anchor origin', function() {
|
||||
var iconStyle = new ol.style.Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
anchor: fractionAnchor,
|
||||
anchorOrigin: ol.style.IconOrigin.BOTTOM_RIGHT
|
||||
});
|
||||
expect(iconStyle.getAnchor()).to.eql([27, 36]);
|
||||
});
|
||||
|
||||
it('uses a top right anchor origin', function() {
|
||||
var iconStyle = new ol.style.Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
anchor: fractionAnchor,
|
||||
anchorOrigin: ol.style.IconOrigin.TOP_RIGHT
|
||||
});
|
||||
expect(iconStyle.getAnchor()).to.eql([27, 12]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getOrigin', function() {
|
||||
var offset = [16, 20];
|
||||
var imageSize = [144, 192];
|
||||
|
||||
it('uses a top left offset origin (default)', function() {
|
||||
var iconStyle = new ol.style.Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
offset: offset
|
||||
});
|
||||
expect(iconStyle.getOrigin()).to.eql([16, 20]);
|
||||
});
|
||||
|
||||
it('uses a bottom left offset origin', function() {
|
||||
var iconStyle = new ol.style.Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
offset: offset,
|
||||
offsetOrigin: ol.style.IconOrigin.BOTTOM_LEFT
|
||||
});
|
||||
iconStyle.iconImage_.size_ = imageSize;
|
||||
expect(iconStyle.getOrigin()).to.eql([16, 124]);
|
||||
});
|
||||
|
||||
it('uses a bottom right offset origin', function() {
|
||||
var iconStyle = new ol.style.Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
offset: offset,
|
||||
offsetOrigin: ol.style.IconOrigin.BOTTOM_RIGHT
|
||||
});
|
||||
iconStyle.iconImage_.size_ = imageSize;
|
||||
expect(iconStyle.getOrigin()).to.eql([92, 124]);
|
||||
});
|
||||
|
||||
it('uses a top right offset origin', function() {
|
||||
var iconStyle = new ol.style.Icon({
|
||||
src: 'test.png',
|
||||
size: size,
|
||||
offset: offset,
|
||||
offsetOrigin: ol.style.IconOrigin.TOP_RIGHT
|
||||
});
|
||||
iconStyle.iconImage_.size_ = imageSize;
|
||||
expect(iconStyle.getOrigin()).to.eql([92, 20]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.style.IconImageCache', function() {
|
||||
var originalMaxCacheSize;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user