Skip to content

Commit

Permalink
Synview: added preload option to Type class (simple implementation)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo Sonderegger committed Aug 10, 2020
1 parent 644d806 commit 8d00bcc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]
### Added
- [preload]() to the synview's Resource class.
- [preload](https://chird.github.io/meteoJS/doc/module-meteoJS_synview_resource.Resource.html#preload) to the synview's Resource class.
- Preload options to the synview's Type class.

## [1.7.0] - 2020-07-07
### Added
Expand Down
23 changes: 22 additions & 1 deletion src/meteoJS/synview/Type.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import addEventFunctions from '../Events.js';
import ResourceCollection from './ResourceCollection.js';
import Resource from './Resource.js';

/**
* Preload options.
*
* @typedef {Object} module:meteoJS/synview/type~preloadOptions
* @property {boolean} [enabled=false] - Enable preload of the resources.
*/

/**
* Options for the constructor.
*
Expand Down Expand Up @@ -34,6 +41,8 @@ import Resource from './Resource.js';
* @param {module:meteoJS/synview/tooltip~contentFunction|undefined} [tooltip]
* Tooltip function. If color detection will be used with this type, you must
* set an unique className.
* @param {module:meteoJS/synview/type~preloadOptions} [preload]
* Preload options.
*/

/**
Expand Down Expand Up @@ -69,7 +78,8 @@ export class Type {
resources = undefined,
className = undefined,
imageSmoothingEnabled = undefined,
tooltip = undefined
tooltip = undefined,
preload = {}
} = {}) {
/**
* @type Object
Expand Down Expand Up @@ -115,6 +125,8 @@ export class Type {
this.collection.on('add:item', function (resource) {
resource.className = this.className;
this._addOLLayer(resource);
if (this._preload.enabled)
resource.preload();
}, this);
this.collection.on('remove:item', function (resource) {
this._removeOLLayer(resource);
Expand All @@ -123,9 +135,18 @@ export class Type {
if (newResource !== oldResource) {
newResource.className = this.className;
this._replaceOLLayer(newResource, oldResource);
if (this._preload.enabled)
newResource.preload();
}
}, this);

/**
* Preload options.
* @type module:meteoJS/synview/type~preloadOptions
* @private
*/
this._preload = preload;

if (this.options.resources !== undefined)
this.collection.setResources(this.options.resources);
delete this.options.resources;
Expand Down

0 comments on commit 8d00bcc

Please sign in to comment.