Left Mouse Button: Press "t" to cycle through tools
Active Tool: Wwwc
Right Mouse Button: drag >> Zoom || drag + Ctrl >> Pan
let demoFiles = [];
let counter = 0;
const getDemoFileNames = function () {
let demoFileList = [];
for (let i = 1; i < 25; i++) {
let filename = "anon" + i;
demoFileList.push(filename);
}
return demoFileList;
};
// init all
larvitar.initializeImageLoader();
larvitar.initializeCSTools();
larvitar.store.initialize();
larvitar.store.addViewport("viewer");
async function createFile(fileName, cb) {
let response = await fetch("./demo/" + fileName);
let data = await response.blob();
let file = new File([data], fileName);
demoFiles.push(file);
counter++;
if (counter == 24) {
cb();
}
}
function renderSerie() {
larvitar
.readFiles(demoFiles)
.then(seriesStack => {
let seriesId = _.keys(seriesStack)[0];
let serie = seriesStack[seriesId];
larvitar.renderImage(serie, "viewer").then(() => {
console.log("Image has been rendered");
});
larvitar.addDefaultTools();
let mouseConfig = {
keyboard_shortcuts: {
KEY_A: "Angle",
KEY_L: "Length"
},
mouse_button_left: {
ctrl: "Pan",
default: "Wwwc"
},
mouse_button_right: {
ctrl: "Pan",
default: "Zoom"
},
debug: true
};
// NOTE: this also activate the tools marked as default for each mouse button
larvitar.addMouseKeyHandlers(mouseConfig);
})
.catch(err => console.log(err));
}
let demoFileList = getDemoFileNames();
_.each(demoFileList, function (demoFile) {
createFile(demoFile, renderSerie);
});
let tool_counter = 0;
document.onkeypress = function (e) {
e = e || window.event;
if (e.keyCode == 116 || e.keyCode == 84) {
let tools = _.map(larvitar.DEFAULT_TOOLS, "name");
// remove useless tools for the live example
tools = _.without(
tools,
"StackScrollMouseWheel",
"TextMarker",
"ZoomTouchPinch",
"PanMultiTouch",
"OrientationMarkers",
"ScaleOverlay"
);
// remove not working tools for the live example
// see open issue
tools = _.without(
tools,
"Brush",
"ThresholdsBrush",
"RectangleScissors",
"FreehandScissors",
"CircleScissors",
"CorrectionScissors",
"PolylineScissors"
);
let increment = e.shiftKey ? -1 : 1;
tool_counter =
tool_counter == tools.length - 1 ? 0 : tool_counter + increment;
tool_counter = tool_counter < 0 ? 0 : tool_counter;
let tool = tools[tool_counter];
larvitar.setToolActive(tool);
$("#active-tool").html("Active Tool: " + tool);
}
};