2
* @author Patrick Schmiedel patrick.schmiedel@gmx.net
5
* @class DomNodeCache This class manages a cache of DOM nodes to improve loading times.
7
/*global Class, $, $A*/
8
var DomNodeCache = Class.create();
10
DomNodeCache.prototype = {
14
initialize: function () {
23
* @function add Adds a new DOM Node to the cache.
24
* @param {DOM Node} element The DOM Node to add.
25
* @param {Number} zoomLevel The zoom level of the element.
26
* @param {Number} xIndex The x index of the element.
27
* @param {Number} yIndex The y index of the element.
29
add: function (element, zoomLevel, xIndex, yIndex) {
30
if (!this.cache[zoomLevel]) {
31
this.cache[zoomLevel] = [];
33
if (!this.cache[zoomLevel][xIndex]) {
34
this.cache[zoomLevel][xIndex] = [];
36
this.cache[zoomLevel][xIndex][yIndex] = element;
40
* @method Returns a DOM Node in the cache.
41
* @param {Number} zoomLevel The zoom level of the element.
42
* @param {Number} xIndex The x index of the element.
43
* @param {Number} yIndex The y index of the element.
44
* @return (DOM Node} The DOM Node in the cache.
46
get: function (zoomLevel, xIndex, yIndex) {
47
if (this.cache[zoomLevel] && this.cache[zoomLevel][xIndex] && this.cache[zoomLevel][xIndex][yIndex]) {
48
return this.cache[zoomLevel][xIndex][yIndex];
54
* @method contains Returns whether the cache contains an element at the given position.
55
* @param {Number} zoomLevel The zoom level of the element.
56
* @param {Number} xIndex The x index of the element.
57
* @param {Number} yIndex The y index of the element.
58
* @return {Boolean} Whether the cache contains an element at the given position.
60
contains: function (zoomLevel, xIndex, yIndex) {
61
return (this.cache[zoomLevel]
62
&& this.cache[zoomLevel][xIndex]
63
&& this.cache[zoomLevel][xIndex][yIndex] ? true : false);
67
* @method zoomLevels Returns the number of zoom levels in the cache.
68
* @return {Number} The number of zoom levels.
70
zoomLevels: function () {
71
return this.cache.length;
75
* @method clear Clears the cache.
83
* @method remove Removes all elements from the DOM.
86
this.cache.flatten().each(function (element) {
87
if (element && element.parentNode) {
95
* @method removeAndClear Removes all elements from the DOM and clears the cache.
97
removeAndClear: function () {
98
this.remove().clear();
102
* @method setStyle Sets CSS style properties on all elements in the cache.
103
* @param {Hash} style A Hash of CSS property/value pairs.
105
setStyle: function (style) {
106
//Debug.output('setting style', this.cache.flatten().pluck('style').pluck('zIndex'), $H(style).inspect());
107
this.cache.flatten().each(function (domNode) {
108
if (domNode && domNode.style) {
109
$(domNode).setStyle(style);
112
//Debug.output('style set', this.cache.flatten().pluck('style').pluck('zIndex'), $H(style).inspect());
117
var TileCache = Class.create();
119
TileCache.prototype = Object.extend(new DomNodeCache(), {
120
initialize: function() {
121
this.cache = new Array();
125
this.cache.flatten().each(function(element) { if (element && element.domNode) element.domNode.remove(); });