Commit c48f9cc4 authored by hertzhaft's avatar hertzhaft

toggle SVG and key handler according to visibility of measure bar

parent 8b34e2bb
...@@ -773,7 +773,9 @@ ...@@ -773,7 +773,9 @@
$measureBar = setupMeasureBar(data); $measureBar = setupMeasureBar(data);
}; };
$measureBar.toggle(); $measureBar.toggle();
setScreenPosition(data, $measureBar); var on = $measureBar.is(":visible");
setKeyHandler(data, on);
showSVG(data, on);
return; return;
}, },
drawshape : function(data) { drawshape : function(data) {
...@@ -1017,6 +1019,17 @@ ...@@ -1017,6 +1019,17 @@
$u2.children(':not(:disabled)')[data.settings.unitTo].selected = true; $u2.children(':not(:disabled)')[data.settings.unitTo].selected = true;
}; };
// show or hide SVG element
var showSVG = function(data, on) {
var layers = data.vectorLayers;
if (layers == null) return;
$svg = layers[0].$elem;
if (on) {
$svg.removeAttr("display"); }
else {
$svg.attr("display", "none"); }
};
// initial position of measure bar (bottom left of browser window) // initial position of measure bar (bottom left of browser window)
var setScreenPosition = function(data, $div) { var setScreenPosition = function(data, $div) {
if ($div == null) return; if ($div == null) return;
...@@ -1041,6 +1054,21 @@ ...@@ -1041,6 +1054,21 @@
return false; return false;
}; };
// keydown handler when measure bar is visible
var onKeyDown = function(event, data) {
console.debug('measure: keyDown', event.key)
};
// setup a div for accessing the measure functionality
var setKeyHandler = function(data, on) {
if (on) {
$(document.body).on('keydown.measure',
function(evt) { onKeyDown(evt, data) }
)}
else {
$(document.body).off('keydown.measure') }
};
// setup a div for accessing the measure functionality // setup a div for accessing the measure functionality
var setupMeasureBar = function(data) { var setupMeasureBar = function(data) {
console.debug('measure: setupMeasureBar'); console.debug('measure: setupMeasureBar');
...@@ -1074,6 +1102,7 @@ ...@@ -1074,6 +1102,7 @@
populateShapeSelect(data); populateShapeSelect(data);
populateUnitSelects(data); populateUnitSelects(data);
setupMeasureWidgets(data); setupMeasureWidgets(data);
setScreenPosition(data, $measureBar);
widgets.move.on('mousedown.measure', dragMeasureBar); widgets.move.on('mousedown.measure', dragMeasureBar);
return $measureBar; return $measureBar;
}; };
......
...@@ -55,12 +55,12 @@ ...@@ -55,12 +55,12 @@
var digilib = null; var digilib = null;
// SVG namespace // SVG namespace
var svgNS = 'http://www.w3.org/2000/svg'; var svgNS = 'http://www.w3.org/2000/svg';
// implemented shape types
var supportedShapeTypes = ['Line', 'Rectangle', 'LineString', 'Polygon', 'Circle', 'Ellipse'];
var defaults = { var defaults = {
// is vector active? // is vector active?
'isVectorActive' : true, 'isVectorActive' : true,
// implemented shape types
'supportedShapeTypes' : ['Line', 'Rectangle', 'LineString', 'Polygon', 'Circle', 'Ellipse'],
// default SVG stroke // default SVG stroke
'defaultStroke' : 'red', 'defaultStroke' : 'red',
// default SVG stroke-width // default SVG stroke-width
...@@ -298,7 +298,7 @@ ...@@ -298,7 +298,7 @@
'style': 'position:absolute; z-index:10; pointer-events:none;'}); 'style': 'position:absolute; z-index:10; pointer-events:none;'});
$svg = $(svgElem); $svg = $(svgElem);
layer.svgElem = svgElem; layer.svgElem = svgElem;
layer.$elem = $svg; layer.$elem = $svg;
for (var i = 0; i < shapes.length; ++i) { for (var i = 0; i < shapes.length; ++i) {
var shape = shapes[i]; var shape = shapes[i];
renderShape(data, shape, layer); renderShape(data, shape, layer);
...@@ -546,7 +546,7 @@ ...@@ -546,7 +546,7 @@
} }
} }
// update shape object and trigger drag event // update shape object and trigger drag event
if (isSupported(shapeType)) { if (isSupported(data, shapeType)) {
var p = data.imgTrafo.invtransform(pt); var p = data.imgTrafo.invtransform(pt);
shape.geometry.coordinates[vtx] = [p.x, p.y]; shape.geometry.coordinates[vtx] = [p.x, p.y];
$(data).trigger('dragShape', shape); $(data).trigger('dragShape', shape);
...@@ -563,7 +563,7 @@ ...@@ -563,7 +563,7 @@
pt.clipTo(imgRect); pt.clipTo(imgRect);
var p1 = data.imgTrafo.invtransform(pt); var p1 = data.imgTrafo.invtransform(pt);
// update shape object // update shape object
if (isSupported(shapeType)) { if (isSupported(data, shapeType)) {
shape.geometry.coordinates[vtx] = [p1.x, p1.y]; shape.geometry.coordinates[vtx] = [p1.x, p1.y];
} }
// remove move/end handler // remove move/end handler
...@@ -590,8 +590,8 @@ ...@@ -590,8 +590,8 @@
* *
* @param shapeType shapeType to test * @param shapeType shapeType to test
*/ */
var isSupported = function(shapeType) { var isSupported = function(data, shapeType) {
return $.inArray(shapeType, supportedShapeTypes) > -1; return $.inArray(shapeType, data.settings.supportedShapeTypes) > -1;
}; };
/** /**
...@@ -625,7 +625,7 @@ ...@@ -625,7 +625,7 @@
var vtxidx = 1; var vtxidx = 1;
if (shapeType === 'Point') { if (shapeType === 'Point') {
shape.geometry.coordinates = [[p.x, p.y]]; shape.geometry.coordinates = [[p.x, p.y]];
} else if (isSupported(shapeType)) { } else if (isSupported(data, shapeType)) {
shape.geometry.coordinates = [[p.x, p.y], [p.x, p.y]]; shape.geometry.coordinates = [[p.x, p.y], [p.x, p.y]];
} else { } else {
console.error("defineShape: unsupported shape type: "+shapeType); console.error("defineShape: unsupported shape type: "+shapeType);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment