Plugin Draw Resonators: Create callback function in render

This commit is contained in:
Xelio
2013-09-06 22:24:13 +08:00
parent a0dff90e7a
commit 79f0bda15f

View File

@ -2,7 +2,7 @@
// @id iitc-plugin-draw-resonators@xelio // @id iitc-plugin-draw-resonators@xelio
// @name IITC plugin: Draw resonators // @name IITC plugin: Draw resonators
// @category Layer // @category Layer
// @version 0.2.0.@@DATETIMEVERSION@@ // @version 0.2.1.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL @@UPDATEURL@@ // @updateURL @@UPDATEURL@@
// @downloadURL @@DOWNLOADURL@@ // @downloadURL @@DOWNLOADURL@@
@ -56,6 +56,7 @@ window.plugin.drawResonators.Render = function(options) {
this.deleteResonatorEntities = this.deleteResonatorEntities.bind(this); this.deleteResonatorEntities = this.deleteResonatorEntities.bind(this);
this.handleResonatorEntitiesBeforeZoom = this.handleResonatorEntitiesBeforeZoom.bind(this); this.handleResonatorEntitiesBeforeZoom = this.handleResonatorEntitiesBeforeZoom.bind(this);
this.handleResonatorEntitiesAfterZoom = this.handleResonatorEntitiesAfterZoom.bind(this); this.handleResonatorEntitiesAfterZoom = this.handleResonatorEntitiesAfterZoom.bind(this);
this.handleEnableZoomLevelChange = this.handleEnableZoomLevelChange.bind(this);
this.portalSelectionChange = this.portalSelectionChange.bind(this); this.portalSelectionChange = this.portalSelectionChange.bind(this);
}; };
@ -161,12 +162,36 @@ window.plugin.drawResonators.Render.prototype.handleResonatorEntitiesBeforeZoom
window.plugin.drawResonators.Render.prototype.handleResonatorEntitiesAfterZoom = function() { window.plugin.drawResonators.Render.prototype.handleResonatorEntitiesAfterZoom = function() {
if(!this.isResonatorsShow()) { if(!this.isResonatorsShow()) {
this.clearAllResonators();
return;
}
// Draw all resonators if they were not drawn
if(!this.isResonatorsShowBeforeZoom()) {
this.drawAllResonators();
}
}
window.plugin.drawResonators.Render.prototype.handleEnableZoomLevelChange = function(zoomLevel) {
this.enableZoomLevel = zoomLevel;
if(!this.isResonatorsShow()) {
this.clearAllResonators();
return;
}
// Draw all resonators if they were not drawn
if(!Object.keys(this.resonators).length > 0) {
this.drawAllResonators();
}
}
window.plugin.drawResonators.Render.prototype.clearAllResonators = function() {
this.resonatorLayerGroup.clearLayers(); this.resonatorLayerGroup.clearLayers();
this.resonators = {}; this.resonators = {};
} else { }
// Redraw all resonators if they were deleted
if(this.isResonatorsShowBeforeZoom()) return;
window.plugin.drawResonators.Render.prototype.drawAllResonators = function() {
var render = this; var render = this;
// loop through level of portals, only draw if the portal is shown on map // loop through level of portals, only draw if the portal is shown on map
@ -178,8 +203,6 @@ window.plugin.drawResonators.Render.prototype.handleResonatorEntitiesAfterZoom =
render.createResonatorEntities(portal); render.createResonatorEntities(portal);
} }
} }
}
} }
window.plugin.drawResonators.Render.prototype.portalSelectionChange = function(data) { window.plugin.drawResonators.Render.prototype.portalSelectionChange = function(data) {
@ -299,8 +322,6 @@ window.plugin.drawResonators.Styler.prototype.defaultConnectorStyle = function(r
//////// Options for storing and loading options //////// //////// Options for storing and loading options ////////
// TODO: add callback to notify option changes
window.plugin.drawResonators.Options = function() { window.plugin.drawResonators.Options = function() {
this._options = {}; this._options = {};
this._callbacks = {}; this._callbacks = {};
@ -328,7 +349,7 @@ window.plugin.drawResonators.Options.prototype.changeOption = function(name, val
this._options[name] = value; this._options[name] = value;
this.storeLocal(name, this._options[name]); this.storeLocal(name, this._options[name]);
if (!this._callbacks[name]) { if (this._callbacks[name] !== null) {
for(var i in this._callbacks[name]) { for(var i in this._callbacks[name]) {
this._callbacks[name][i](value); this._callbacks[name][i](value);
} }
@ -372,6 +393,8 @@ var setup = function() {
window.plugin.drawResonators.render.registerHook(); window.plugin.drawResonators.render.registerHook();
window.addLayerGroup('Resonators', window.plugin.drawResonators.render.resonatorLayerGroup, true); window.addLayerGroup('Resonators', window.plugin.drawResonators.render.resonatorLayerGroup, true);
window.plugin.drawResonators.options.addCallback('enableZoomLevel', window.plugin.drawResonators.render.handleEnableZoomLevelChange);
// TODO: add options dialog to change options // TODO: add options dialog to change options
} }