I wrote a small script that shows/hides a specific layer.
I would like the button icon to change depending on the state of the layer. For example: ToggleSpitLayer.svg when the layer is visible and ToggleSpitLayer-off.svg when it is not.
Code: Select all
include("scripts/Layer/Layer.js");
function ToggleSpitLayer(guiAction) {
Layer.call(this, guiAction);
}
ToggleSpitLayer.prototype = new Layer();
ToggleSpitLayer.init = function(basePath) {
var action = new RGuiAction(qsTr("Show/Hide Spit layer"), RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/ToggleSpitLayer.js");
action.setIcon(basePath + "/ToggleSpitLayer.svg");
action.setStatusTip(qsTr("Show/Hide Spit layer"));
action.setDefaultShortcut(new QKeySequence("s,p,i"));
action.setDefaultCommands(["spi"]);
action.setGroupSortOrder(80100);
action.setSortOrder(300);
action.setWidgetNames(["MenuSpit", "ToolBarSpit"]);
};
ToggleSpitLayer.prototype.togglevue = function(layerName, operation) {
try {
var layer = this.getDocument().queryLayer(layerName);
layer.setFrozen(!layer.isOff());
layer.setOff(!layer.isOff());
operation.addObject(layer);
}catch(error){}
}
ToggleSpitLayer.prototype.beginEvent = function() {
Layer.prototype.beginEvent.call(this);
var operation = new RModifyObjectsOperation();
this.togglevue("SPIT", operation);
var di = this.getDocumentInterface();
di.applyOperation(operation);
this.terminate();
};
Thanks in advance!