Named export for ol/style

This commit is contained in:
Frederic Junod
2017-12-18 16:14:50 +01:00
parent afa99f5788
commit dc70c4376d
5 changed files with 32 additions and 43 deletions

View File

@@ -9,7 +9,7 @@ import {getWidth} from '../extent.js';
import {TRUE} from '../functions.js'; import {TRUE} from '../functions.js';
import _ol_layer_Layer_ from '../layer/Layer.js'; import _ol_layer_Layer_ from '../layer/Layer.js';
import _ol_plugins_ from '../plugins.js'; import _ol_plugins_ from '../plugins.js';
import _ol_style_ from '../style.js'; import {iconImageCache} from '../style.js';
import _ol_transform_ from '../transform.js'; import _ol_transform_ from '../transform.js';
/** /**
@@ -84,8 +84,7 @@ _ol_renderer_Map_.prototype.removeLayerRenderers = function() {
* @private * @private
*/ */
_ol_renderer_Map_.expireIconCache_ = function(map, frameState) { _ol_renderer_Map_.expireIconCache_ = function(map, frameState) {
var cache = _ol_style_.iconImageCache; iconImageCache.expire();
cache.expire();
}; };

View File

@@ -2,11 +2,9 @@
* @module ol/style * @module ol/style
*/ */
import IconImageCache from './style/IconImageCache.js'; import IconImageCache from './style/IconImageCache.js';
var _ol_style_ = {};
/** /**
* The {@link ol.style.IconImageCache} for {@link ol.style.Icon} images. * The {@link ol.style.IconImageCache} for {@link ol.style.Icon} images.
* @api * @api
*/ */
_ol_style_.iconImageCache = new IconImageCache(); export var iconImageCache = new IconImageCache();
export default _ol_style_;

View File

@@ -7,7 +7,7 @@ import _ol_events_ from '../events.js';
import EventTarget from '../events/EventTarget.js'; import EventTarget from '../events/EventTarget.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import ImageState from '../ImageState.js'; import ImageState from '../ImageState.js';
import _ol_style_ from '../style.js'; import {iconImageCache} from '../style.js';
/** /**
* @constructor * @constructor
@@ -103,7 +103,6 @@ inherits(_ol_style_IconImage_, EventTarget);
*/ */
_ol_style_IconImage_.get = function(image, src, size, crossOrigin, imageState, _ol_style_IconImage_.get = function(image, src, size, crossOrigin, imageState,
color) { color) {
var iconImageCache = _ol_style_.iconImageCache;
var iconImage = iconImageCache.get(src, crossOrigin, color); var iconImage = iconImageCache.get(src, crossOrigin, color);
if (!iconImage) { if (!iconImage) {
iconImage = new _ol_style_IconImage_( iconImage = new _ol_style_IconImage_(

View File

@@ -1,5 +1,5 @@
import {getUid} from '../../../../src/ol/index.js'; import {getUid} from '../../../../src/ol/index.js';
import _ol_style_ from '../../../../src/ol/style.js'; import {iconImageCache} from '../../../../src/ol/style.js';
import _ol_style_Icon_ from '../../../../src/ol/style/Icon.js'; import _ol_style_Icon_ from '../../../../src/ol/style/Icon.js';
import _ol_style_IconImage_ from '../../../../src/ol/style/IconImage.js'; import _ol_style_IconImage_ from '../../../../src/ol/style/IconImage.js';
@@ -226,10 +226,9 @@ describe('ol.style.Icon', function() {
it('takes the real image size', function() { it('takes the real image size', function() {
// pretend that the image is already in the cache, // pretend that the image is already in the cache,
// this image will be used for the icon. // this image will be used for the icon.
var cache = _ol_style_.iconImageCache;
var src = 'test.png'; var src = 'test.png';
var iconImage = new _ol_style_IconImage_(null, 'test.png', imgSize); var iconImage = new _ol_style_IconImage_(null, 'test.png', imgSize);
cache.set(src, null, null, iconImage); iconImageCache.set(src, null, null, iconImage);
var iconStyle = new _ol_style_Icon_({ var iconStyle = new _ol_style_Icon_({
src: 'test.png' src: 'test.png'

View File

@@ -1,86 +1,80 @@
import {nullFunction} from '../../../../src/ol/index.js'; import {nullFunction} from '../../../../src/ol/index.js';
import _ol_events_ from '../../../../src/ol/events.js'; import _ol_events_ from '../../../../src/ol/events.js';
import _ol_style_ from '../../../../src/ol/style.js'; import {iconImageCache} from '../../../../src/ol/style.js';
import _ol_style_IconImage_ from '../../../../src/ol/style/IconImage.js'; import _ol_style_IconImage_ from '../../../../src/ol/style/IconImage.js';
describe('ol.style.IconImageCache', function() { describe('ol.style.IconImageCache', function() {
var originalMaxCacheSize; var originalMaxCacheSize;
beforeEach(function() { beforeEach(function() {
var cache = _ol_style_.iconImageCache; iconImageCache.clear();
cache.clear(); originalMaxCacheSize = iconImageCache.maxCacheSize;
originalMaxCacheSize = cache.maxCacheSize; iconImageCache.maxCacheSize_ = 4;
cache.maxCacheSize_ = 4;
}); });
afterEach(function() { afterEach(function() {
var cache = _ol_style_.iconImageCache; iconImageCache.maxCacheSize_ = originalMaxCacheSize;
cache.maxCacheSize_ = originalMaxCacheSize; iconImageCache.clear();
cache.clear();
}); });
describe('#expire', function() { describe('#expire', function() {
it('expires images when expected', function() { it('expires images when expected', function() {
var cache = _ol_style_.iconImageCache;
var i, src, iconImage; var i, src, iconImage;
for (i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
src = i + ''; src = i + '';
iconImage = new _ol_style_IconImage_(null, src); iconImage = new _ol_style_IconImage_(null, src);
cache.set(src, null, null, iconImage); iconImageCache.set(src, null, null, iconImage);
} }
expect(cache.cacheSize_).to.eql(4); expect(iconImageCache.cacheSize_).to.eql(4);
cache.expire(); iconImageCache.expire();
expect(cache.cacheSize_).to.eql(4); expect(iconImageCache.cacheSize_).to.eql(4);
src = '4'; src = '4';
iconImage = new _ol_style_IconImage_(null, src); iconImage = new _ol_style_IconImage_(null, src);
cache.set(src, null, null, iconImage); iconImageCache.set(src, null, null, iconImage);
expect(cache.cacheSize_).to.eql(5); expect(iconImageCache.cacheSize_).to.eql(5);
cache.expire(); // remove '0' and '4' iconImageCache.expire(); // remove '0' and '4'
expect(cache.cacheSize_).to.eql(3); expect(iconImageCache.cacheSize_).to.eql(3);
src = '0'; src = '0';
iconImage = new _ol_style_IconImage_(null, src); iconImage = new _ol_style_IconImage_(null, src);
_ol_events_.listen(iconImage, 'change', nullFunction, false); _ol_events_.listen(iconImage, 'change', nullFunction, false);
cache.set(src, null, null, iconImage); iconImageCache.set(src, null, null, iconImage);
expect(cache.cacheSize_).to.eql(4); expect(iconImageCache.cacheSize_).to.eql(4);
src = '4'; src = '4';
iconImage = new _ol_style_IconImage_(null, src); iconImage = new _ol_style_IconImage_(null, src);
_ol_events_.listen(iconImage, 'change', nullFunction, false); _ol_events_.listen(iconImage, 'change', nullFunction, false);
cache.set(src, null, null, iconImage); iconImageCache.set(src, null, null, iconImage);
expect(cache.cacheSize_).to.eql(5); expect(iconImageCache.cacheSize_).to.eql(5);
// check that '0' and '4' are not removed from the cache // check that '0' and '4' are not removed from the cache
cache.expire(); iconImageCache.expire();
expect(cache.get('0', null, null)).to.not.be(null); expect(iconImageCache.get('0', null, null)).to.not.be(null);
expect(cache.get('4', null, null)).to.not.be(null); expect(iconImageCache.get('4', null, null)).to.not.be(null);
}); });
}); });
describe('#setSize', function() { describe('#setSize', function() {
it('sets max cache size and expires cache', function() { it('sets max cache size and expires cache', function() {
var cache = _ol_style_.iconImageCache;
var i, src, iconImage; var i, src, iconImage;
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
src = i + ''; src = i + '';
iconImage = new _ol_style_IconImage_(null, src); iconImage = new _ol_style_IconImage_(null, src);
cache.set(src, null, null, iconImage); iconImageCache.set(src, null, null, iconImage);
} }
expect(cache.cacheSize_).to.eql(3); expect(iconImageCache.cacheSize_).to.eql(3);
cache.setSize(2); iconImageCache.setSize(2);
expect(cache.maxCacheSize_).to.eql(2); expect(iconImageCache.maxCacheSize_).to.eql(2);
expect(cache.cacheSize_).to.eql(2); expect(iconImageCache.cacheSize_).to.eql(2);
}); });
}); });
}); });