Give ol.style.IconImageCache its own file
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
goog.provide('ol.style.Icon');
|
||||
goog.provide('ol.style.IconAnchorUnits');
|
||||
goog.provide('ol.style.IconOrigin');
|
||||
goog.provide('ol.style.iconImageCache');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.asserts');
|
||||
@@ -363,100 +362,3 @@ ol.style.Icon.prototype.unlistenImageChange = function(listener, thisArg) {
|
||||
ol.events.unlisten(this.iconImage_, ol.events.EventType.CHANGE,
|
||||
listener, thisArg);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @private
|
||||
*/
|
||||
ol.style.IconImageCache_ = function() {
|
||||
|
||||
/**
|
||||
* @type {Object.<string, ol.style.IconImage>}
|
||||
* @private
|
||||
*/
|
||||
this.cache_ = {};
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.cacheSize_ = 0;
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.maxCacheSize_ = 32;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} src Src.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {ol.Color} color Color.
|
||||
* @return {string} Cache key.
|
||||
*/
|
||||
ol.style.IconImageCache_.getKey = function(src, crossOrigin, color) {
|
||||
goog.DEBUG && console.assert(crossOrigin !== undefined,
|
||||
'argument crossOrigin must be defined');
|
||||
var colorString = color ? ol.color.asString(color) : 'null';
|
||||
return crossOrigin + ':' + src + ':' + colorString;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.style.IconImageCache_.prototype.clear = function() {
|
||||
this.cache_ = {};
|
||||
this.cacheSize_ = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.style.IconImageCache_.prototype.expire = function() {
|
||||
if (this.cacheSize_ > this.maxCacheSize_) {
|
||||
var i = 0;
|
||||
var key, iconImage;
|
||||
for (key in this.cache_) {
|
||||
iconImage = this.cache_[key];
|
||||
if ((i++ & 3) === 0 && !iconImage.hasListener()) {
|
||||
delete this.cache_[key];
|
||||
--this.cacheSize_;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} src Src.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {ol.Color} color Color.
|
||||
* @return {ol.style.IconImage} Icon image.
|
||||
*/
|
||||
ol.style.IconImageCache_.prototype.get = function(src, crossOrigin, color) {
|
||||
var key = ol.style.IconImageCache_.getKey(src, crossOrigin, color);
|
||||
return key in this.cache_ ? this.cache_[key] : null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} src Src.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {ol.Color} color Color.
|
||||
* @param {ol.style.IconImage} iconImage Icon image.
|
||||
*/
|
||||
ol.style.IconImageCache_.prototype.set = function(src, crossOrigin, color,
|
||||
iconImage) {
|
||||
var key = ol.style.IconImageCache_.getKey(src, crossOrigin, color);
|
||||
this.cache_[key] = iconImage;
|
||||
++this.cacheSize_;
|
||||
};
|
||||
|
||||
|
||||
ol.style.iconImageCache = new ol.style.IconImageCache_();
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
goog.provide('ol.style.IconImageCache');
|
||||
|
||||
goog.require('ol.color');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @private
|
||||
*/
|
||||
ol.style.IconImageCache = function() {
|
||||
|
||||
/**
|
||||
* @type {Object.<string, ol.style.IconImage>}
|
||||
* @private
|
||||
*/
|
||||
this.cache_ = {};
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.cacheSize_ = 0;
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.maxCacheSize_ = 32;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} src Src.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {ol.Color} color Color.
|
||||
* @return {string} Cache key.
|
||||
*/
|
||||
ol.style.IconImageCache.getKey = function(src, crossOrigin, color) {
|
||||
goog.DEBUG && console.assert(crossOrigin !== undefined,
|
||||
'argument crossOrigin must be defined');
|
||||
var colorString = color ? ol.color.asString(color) : 'null';
|
||||
return crossOrigin + ':' + src + ':' + colorString;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.style.IconImageCache.prototype.clear = function() {
|
||||
this.cache_ = {};
|
||||
this.cacheSize_ = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
ol.style.IconImageCache.prototype.expire = function() {
|
||||
if (this.cacheSize_ > this.maxCacheSize_) {
|
||||
var i = 0;
|
||||
var key, iconImage;
|
||||
for (key in this.cache_) {
|
||||
iconImage = this.cache_[key];
|
||||
if ((i++ & 3) === 0 && !iconImage.hasListener()) {
|
||||
delete this.cache_[key];
|
||||
--this.cacheSize_;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} src Src.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {ol.Color} color Color.
|
||||
* @return {ol.style.IconImage} Icon image.
|
||||
*/
|
||||
ol.style.IconImageCache.prototype.get = function(src, crossOrigin, color) {
|
||||
var key = ol.style.IconImageCache.getKey(src, crossOrigin, color);
|
||||
return key in this.cache_ ? this.cache_[key] : null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} src Src.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {ol.Color} color Color.
|
||||
* @param {ol.style.IconImage} iconImage Icon image.
|
||||
*/
|
||||
ol.style.IconImageCache.prototype.set = function(src, crossOrigin, color,
|
||||
iconImage) {
|
||||
var key = ol.style.IconImageCache.getKey(src, crossOrigin, color);
|
||||
this.cache_[key] = iconImage;
|
||||
++this.cacheSize_;
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
goog.provide('ol.style');
|
||||
|
||||
goog.require('ol.style.IconImageCache');
|
||||
|
||||
ol.style.iconImageCache = new ol.style.IconImageCache();
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Feature styles.
|
||||
*
|
||||
* If no style is defined, the following default style is used:
|
||||
* ```js
|
||||
* var fill = new ol.style.Fill({
|
||||
* color: 'rgba(255,255,255,0.4)'
|
||||
* });
|
||||
* var stroke = new ol.style.Stroke({
|
||||
* color: '#3399CC',
|
||||
* width: 1.25
|
||||
* });
|
||||
* var styles = [
|
||||
* new ol.style.Style({
|
||||
* image: new ol.style.Circle({
|
||||
* fill: fill,
|
||||
* stroke: stroke,
|
||||
* radius: 5
|
||||
* }),
|
||||
* fill: fill,
|
||||
* stroke: stroke
|
||||
* })
|
||||
* ];
|
||||
* ```
|
||||
*
|
||||
* A separate editing style has the following defaults:
|
||||
* ```js
|
||||
* var white = [255, 255, 255, 1];
|
||||
* var blue = [0, 153, 255, 1];
|
||||
* var width = 3;
|
||||
* styles[ol.geom.GeometryType.POLYGON] = [
|
||||
* new ol.style.Style({
|
||||
* fill: new ol.style.Fill({
|
||||
* color: [255, 255, 255, 0.5]
|
||||
* })
|
||||
* })
|
||||
* ];
|
||||
* styles[ol.geom.GeometryType.MULTI_POLYGON] =
|
||||
* styles[ol.geom.GeometryType.POLYGON];
|
||||
* styles[ol.geom.GeometryType.LINE_STRING] = [
|
||||
* new ol.style.Style({
|
||||
* stroke: new ol.style.Stroke({
|
||||
* color: white,
|
||||
* width: width + 2
|
||||
* })
|
||||
* }),
|
||||
* new ol.style.Style({
|
||||
* stroke: new ol.style.Stroke({
|
||||
* color: blue,
|
||||
* width: width
|
||||
* })
|
||||
* })
|
||||
* ];
|
||||
* styles[ol.geom.GeometryType.MULTI_LINE_STRING] =
|
||||
* styles[ol.geom.GeometryType.LINE_STRING];
|
||||
* styles[ol.geom.GeometryType.POINT] = [
|
||||
* new ol.style.Style({
|
||||
* image: new ol.style.Circle({
|
||||
* radius: width * 2,
|
||||
* fill: new ol.style.Fill({
|
||||
* color: blue
|
||||
* }),
|
||||
* stroke: new ol.style.Stroke({
|
||||
* color: white,
|
||||
* width: width / 2
|
||||
* })
|
||||
* }),
|
||||
* zIndex: Infinity
|
||||
* })
|
||||
* ];
|
||||
* styles[ol.geom.GeometryType.MULTI_POINT] =
|
||||
* styles[ol.geom.GeometryType.POINT];
|
||||
* styles[ol.geom.GeometryType.GEOMETRY_COLLECTION] =
|
||||
* styles[ol.geom.GeometryType.POLYGON].concat(
|
||||
* styles[ol.geom.GeometryType.POINT]
|
||||
* );
|
||||
*```
|
||||
*
|
||||
* @namespace ol.style
|
||||
*/
|
||||
Reference in New Issue
Block a user