Named export for ol/style
This commit is contained in:
@@ -9,7 +9,7 @@ import {getWidth} from '../extent.js';
|
||||
import {TRUE} from '../functions.js';
|
||||
import _ol_layer_Layer_ from '../layer/Layer.js';
|
||||
import _ol_plugins_ from '../plugins.js';
|
||||
import _ol_style_ from '../style.js';
|
||||
import {iconImageCache} from '../style.js';
|
||||
import _ol_transform_ from '../transform.js';
|
||||
|
||||
/**
|
||||
@@ -84,8 +84,7 @@ _ol_renderer_Map_.prototype.removeLayerRenderers = function() {
|
||||
* @private
|
||||
*/
|
||||
_ol_renderer_Map_.expireIconCache_ = function(map, frameState) {
|
||||
var cache = _ol_style_.iconImageCache;
|
||||
cache.expire();
|
||||
iconImageCache.expire();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
* @module ol/style
|
||||
*/
|
||||
import IconImageCache from './style/IconImageCache.js';
|
||||
var _ol_style_ = {};
|
||||
|
||||
/**
|
||||
* The {@link ol.style.IconImageCache} for {@link ol.style.Icon} images.
|
||||
* @api
|
||||
*/
|
||||
_ol_style_.iconImageCache = new IconImageCache();
|
||||
export default _ol_style_;
|
||||
export var iconImageCache = new IconImageCache();
|
||||
|
||||
@@ -7,7 +7,7 @@ import _ol_events_ from '../events.js';
|
||||
import EventTarget from '../events/EventTarget.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import ImageState from '../ImageState.js';
|
||||
import _ol_style_ from '../style.js';
|
||||
import {iconImageCache} from '../style.js';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -103,7 +103,6 @@ inherits(_ol_style_IconImage_, EventTarget);
|
||||
*/
|
||||
_ol_style_IconImage_.get = function(image, src, size, crossOrigin, imageState,
|
||||
color) {
|
||||
var iconImageCache = _ol_style_.iconImageCache;
|
||||
var iconImage = iconImageCache.get(src, crossOrigin, color);
|
||||
if (!iconImage) {
|
||||
iconImage = new _ol_style_IconImage_(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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_IconImage_ from '../../../../src/ol/style/IconImage.js';
|
||||
|
||||
@@ -226,10 +226,9 @@ describe('ol.style.Icon', function() {
|
||||
it('takes the real image size', function() {
|
||||
// pretend that the image is already in the cache,
|
||||
// this image will be used for the icon.
|
||||
var cache = _ol_style_.iconImageCache;
|
||||
var src = 'test.png';
|
||||
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_({
|
||||
src: 'test.png'
|
||||
|
||||
@@ -1,86 +1,80 @@
|
||||
import {nullFunction} from '../../../../src/ol/index.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';
|
||||
|
||||
describe('ol.style.IconImageCache', function() {
|
||||
var originalMaxCacheSize;
|
||||
|
||||
beforeEach(function() {
|
||||
var cache = _ol_style_.iconImageCache;
|
||||
cache.clear();
|
||||
originalMaxCacheSize = cache.maxCacheSize;
|
||||
cache.maxCacheSize_ = 4;
|
||||
iconImageCache.clear();
|
||||
originalMaxCacheSize = iconImageCache.maxCacheSize;
|
||||
iconImageCache.maxCacheSize_ = 4;
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
var cache = _ol_style_.iconImageCache;
|
||||
cache.maxCacheSize_ = originalMaxCacheSize;
|
||||
cache.clear();
|
||||
iconImageCache.maxCacheSize_ = originalMaxCacheSize;
|
||||
iconImageCache.clear();
|
||||
});
|
||||
|
||||
describe('#expire', function() {
|
||||
it('expires images when expected', function() {
|
||||
var cache = _ol_style_.iconImageCache;
|
||||
|
||||
var i, src, iconImage;
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
src = i + '';
|
||||
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();
|
||||
expect(cache.cacheSize_).to.eql(4);
|
||||
iconImageCache.expire();
|
||||
expect(iconImageCache.cacheSize_).to.eql(4);
|
||||
|
||||
src = '4';
|
||||
iconImage = new _ol_style_IconImage_(null, src);
|
||||
cache.set(src, null, null, iconImage);
|
||||
expect(cache.cacheSize_).to.eql(5);
|
||||
iconImageCache.set(src, null, null, iconImage);
|
||||
expect(iconImageCache.cacheSize_).to.eql(5);
|
||||
|
||||
cache.expire(); // remove '0' and '4'
|
||||
expect(cache.cacheSize_).to.eql(3);
|
||||
iconImageCache.expire(); // remove '0' and '4'
|
||||
expect(iconImageCache.cacheSize_).to.eql(3);
|
||||
|
||||
src = '0';
|
||||
iconImage = new _ol_style_IconImage_(null, src);
|
||||
_ol_events_.listen(iconImage, 'change', nullFunction, false);
|
||||
cache.set(src, null, null, iconImage);
|
||||
expect(cache.cacheSize_).to.eql(4);
|
||||
iconImageCache.set(src, null, null, iconImage);
|
||||
expect(iconImageCache.cacheSize_).to.eql(4);
|
||||
|
||||
src = '4';
|
||||
iconImage = new _ol_style_IconImage_(null, src);
|
||||
_ol_events_.listen(iconImage, 'change', nullFunction, false);
|
||||
cache.set(src, null, null, iconImage);
|
||||
expect(cache.cacheSize_).to.eql(5);
|
||||
iconImageCache.set(src, null, null, iconImage);
|
||||
expect(iconImageCache.cacheSize_).to.eql(5);
|
||||
|
||||
// check that '0' and '4' are not removed from the cache
|
||||
cache.expire();
|
||||
expect(cache.get('0', null, null)).to.not.be(null);
|
||||
expect(cache.get('4', null, null)).to.not.be(null);
|
||||
iconImageCache.expire();
|
||||
expect(iconImageCache.get('0', null, null)).to.not.be(null);
|
||||
expect(iconImageCache.get('4', null, null)).to.not.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setSize', function() {
|
||||
it('sets max cache size and expires cache', function() {
|
||||
var cache = _ol_style_.iconImageCache;
|
||||
|
||||
var i, src, iconImage;
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
src = i + '';
|
||||
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(cache.cacheSize_).to.eql(2);
|
||||
expect(iconImageCache.maxCacheSize_).to.eql(2);
|
||||
expect(iconImageCache.cacheSize_).to.eql(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user