Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
digilib-pivaj
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel ANTELME
digilib-pivaj
Commits
351db895
Commit
351db895
authored
10 years ago
by
hertzhaft
Browse files
Options
Downloads
Patches
Plain Diff
recalculate values when units have changed or a shape was clicked
parent
8e8f201c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
webapp/src/main/webapp/jquery/jquery.digilib.measure.js
+70
-108
70 additions, 108 deletions
webapp/src/main/webapp/jquery/jquery.digilib.measure.js
with
70 additions
and
108 deletions
webapp/src/main/webapp/jquery/jquery.digilib.measure.js
+
70
−
108
View file @
351db895
...
@@ -704,22 +704,22 @@
...
@@ -704,22 +704,22 @@
// implemented measuring shape types, for select widget
// implemented measuring shape types, for select widget
implementedShapes
:
[
'
Line
'
,
'
LineString
'
,
'
Rectangle
'
,
'
Polygon
'
],
implementedShapes
:
[
'
Line
'
,
'
LineString
'
,
'
Rectangle
'
,
'
Polygon
'
],
// all measuring shape types
// all measuring shape types
shape
Types
:
{
shape
Info
:
{
Line
:
{
name
:
'
line
'
},
Line
:
{
name
:
'
line
'
,
display
:
'
length
'
,
},
LineString
:
{
name
:
'
linestring
'
},
LineString
:
{
name
:
'
linestring
'
,
display
:
'
length
'
},
Rectangle
:
{
name
:
'
rectangle
'
},
Rectangle
:
{
name
:
'
rectangle
'
,
display
:
'
area
'
},
Square
:
{
name
:
'
square
'
},
Square
:
{
name
:
'
square
'
,
display
:
'
length
'
},
Polygon
:
{
name
:
'
polygon
'
},
Polygon
:
{
name
:
'
polygon
'
,
display
:
'
area
'
},
Circle
:
{
name
:
'
circle
'
},
Circle
:
{
name
:
'
circle
'
,
display
:
'
radius
'
},
Arch
:
{
name
:
'
arch
'
},
Arch
:
{
name
:
'
arch
'
,
display
:
'
radius
'
},
Ratio
:
{
name
:
'
ratio
'
},
Ratio
:
{
name
:
'
ratio
'
,
display
:
'
ratio
'
},
InterCol
:
{
name
:
'
in
tercolumnium
'
},
Grid
:
{
name
:
'
l
in
egrid
'
,
display
:
'
spacing
'
},
Grid
:
{
name
:
'
l
in
egrid
'
}
InterCol
:
{
name
:
'
in
tercolumnium
'
,
display
:
'
ratio
'
}
},
},
// most recently selected shape
// most recently selected shape
activeShapeType
:
'
Line
'
,
activeShapeType
:
'
Line
'
,
// last measured distance
// last measured distance
lastMeasured
Distanc
e
:
0
,
lastMeasured
Valu
e
:
0
,
// measuring unit (index into unit list)
// measuring unit (index into unit list)
unitFrom
:
17
,
unitFrom
:
17
,
// converted unit (index into unit list)
// converted unit (index into unit list)
...
@@ -806,12 +806,12 @@
...
@@ -806,12 +806,12 @@
// event handler for renderShape
// event handler for renderShape
var
onRenderShape
=
function
(
event
,
shape
)
{
var
onRenderShape
=
function
(
event
,
shape
)
{
// event handler for updating shape info
// event handler for updating shape info
var
shapeI
nfo
=
function
(
event
)
{
var
i
nfo
=
function
(
event
)
{
updateInfo
(
data
,
shape
);
updateInfo
(
data
,
shape
);
};
};
var
data
=
this
;
var
data
=
this
;
var
$elem
=
shape
.
$elem
;
var
$elem
=
shape
.
$elem
;
$elem
.
on
(
'
click.measure
'
,
shapeI
nfo
);
$elem
.
on
(
'
click.measure
'
,
i
nfo
);
console
.
debug
(
'
measure: onRenderShape
'
,
data
,
shape
);
console
.
debug
(
'
measure: onRenderShape
'
,
data
,
shape
);
};
};
...
@@ -850,92 +850,61 @@
...
@@ -850,92 +850,61 @@
return
Math
.
abs
(
area
/
2
);
return
Math
.
abs
(
area
/
2
);
};
};
// convert length to second unit
var
convertLength
=
function
(
data
,
val
)
{
var
widgets
=
data
.
measureWidgets
;
var
u1
=
parseFloat
(
widgets
.
unit1
.
val
());
var
u2
=
parseFloat
(
widgets
.
unit2
.
val
());
return
val
*
u1
/
u2
;
};
// convert area to second unit
var
convertArea
=
function
(
data
,
val
)
{
var
widgets
=
data
.
measureWidgets
;
var
u1
=
parseFloat
(
widgets
.
unit1
.
val
());
var
u2
=
parseFloat
(
widgets
.
unit2
.
val
());
return
val
*
u1
*
u1
/
(
u2
*
u2
);
};
// recalculate factor after entering a new value in input element "value1"
// recalculate factor after entering a new value in input element "value1"
var
changeFactor
=
function
(
data
)
{
var
changeFactor
=
function
(
data
)
{
var
widgets
=
data
.
measureWidgets
;
var
widgets
=
data
.
measureWidgets
;
var
val
=
parseFloat
(
widgets
.
value1
.
val
());
var
val
=
parseFloat
(
widgets
.
value1
.
val
());
var
dist
=
data
.
lastMeasuredDistance
;
var
fac
=
val
/
data
.
lastMeasuredValue
;
var
fac
=
val
/
dist
;
data
.
measureFactor
=
fac
;
data
.
measureFactor
=
fac
;
// widgets.fac.text(fn.cropFloatStr(fac));
updateCalculation
(
data
);
var
conv
=
convertLength
(
data
,
val
);
};
widgets
.
value2
.
text
(
fn
.
cropFloatStr
(
mRound
(
conv
)));
};
// info window for line
// convert to second unit and display
var
infoLine
=
function
(
data
,
shape
)
{
var
updateMeasures
=
function
(
data
,
val
,
type
)
{
var
dist
=
rectifiedDist
(
data
,
shape
);
var
info
=
data
.
settings
.
shapeInfo
[
type
]
var
fac
=
data
.
measureFactor
;
var
val
=
dist
*
fac
;
var
conv
=
convertLength
(
data
,
val
);
var
widgets
=
data
.
measureWidgets
;
var
widgets
=
data
.
measureWidgets
;
var
display
=
info
.
display
;
var
u1
=
parseFloat
(
widgets
.
unit1
.
val
());
var
u2
=
parseFloat
(
widgets
.
unit2
.
val
());
var
ratio
=
u1
/
u2
;
var
result
=
(
display
===
'
area
'
)
?
val
*
ratio
*
ratio
:
val
*
ratio
;
widgets
.
shape
.
val
(
type
);
widgets
.
value1
.
val
(
fn
.
cropFloatStr
(
mRound
(
val
)));
widgets
.
value1
.
val
(
fn
.
cropFloatStr
(
mRound
(
val
)));
widgets
.
value2
.
text
(
fn
.
cropFloatStr
(
mRound
(
conv
)));
widgets
.
value2
.
text
(
fn
.
cropFloatStr
(
mRound
(
result
)));
widgets
.
info
.
text
(
'
length
'
);
widgets
.
info
.
text
(
display
);
data
.
lastMeasuredDistance
=
dist
;
};
};
// info window for polygon
// recalculate with new units
var
infoPolygon
=
function
(
data
,
shape
)
{
var
updateCalculation
=
function
(
data
)
{
var
area
=
rectifiedArea
(
data
,
shape
);
var
type
=
getActiveShapeType
(
data
);
var
display
=
data
.
settings
.
shapeInfo
[
type
].
display
;
var
val
=
data
.
lastMeasuredValue
;
var
fac
=
data
.
measureFactor
;
var
fac
=
data
.
measureFactor
;
var
val
=
area
*
fac
*
fac
;
var
result
=
(
display
===
'
area
'
)
var
conv
=
convertArea
(
data
,
val
);
?
val
*
fac
*
fac
var
widgets
=
data
.
measureWidgets
;
:
val
*
fac
;
widgets
.
value1
.
val
(
fn
.
cropFloatStr
(
mRound
(
val
)));
updateMeasures
(
data
,
result
,
type
);
widgets
.
value2
.
text
(
fn
.
cropFloatStr
(
mRound
(
conv
)));
widgets
.
info
.
text
(
'
area
'
);
};
// info window for rectangle
var
infoRect
=
function
(
data
,
shape
)
{
var
widgets
=
data
.
measureWidgets
;
widgets
.
value1
.
val
(
'
rect 1
'
);
widgets
.
value2
.
text
(
'
rect 2
'
);
};
};
//
recalculate after measuring
//
display info for shape
var
updateInfo
=
function
(
data
,
shape
)
{
var
updateInfo
=
function
(
data
,
shape
)
{
var
type
=
shape
.
geometry
.
type
;
var
type
=
shape
.
geometry
.
type
;
data
.
measureWidgets
.
shape
.
val
(
type
);
var
display
=
data
.
settings
.
shapeInfo
[
type
].
display
;
if
(
type
===
'
Line
'
)
{
var
val
=
(
display
===
'
area
'
)
return
infoLine
(
data
,
shape
);
?
rectifiedArea
(
data
,
shape
)
}
:
rectifiedDist
(
data
,
shape
);
if
(
type
===
'
LineString
'
)
{
data
.
lastMeasuredValue
=
val
;
return
infoLine
(
data
,
shape
);
setActiveShapeType
(
data
,
type
);
}
updateCalculation
(
data
);
if
(
type
===
'
Rectangle
'
)
{
return
infoRect
(
data
,
shape
);
}
if
(
type
===
'
Polygon
'
)
{
return
infoPolygon
(
data
,
shape
);
}
};
};
// recalculate after unit change
var
updateConversion
=
function
(
data
)
{
}
// return a shape of the currently selected shape type
// return a shape of the currently selected shape type
var
newShape
=
function
(
data
)
{
var
newShape
=
function
(
data
)
{
return
{
return
{
geometry
:
{
geometry
:
{
type
:
get
Selected
ShapeType
(
data
)
type
:
get
Active
ShapeType
(
data
)
},
},
properties
:
{
properties
:
{
stroke
:
getSelectedStroke
(
data
),
stroke
:
getSelectedStroke
(
data
),
...
@@ -946,19 +915,18 @@
...
@@ -946,19 +915,18 @@
};
};
// return the currently selected shape type
// return the currently selected shape type
var
get
Selected
ShapeType
=
function
(
data
)
{
var
get
Active
ShapeType
=
function
(
data
)
{
return
data
.
settings
.
activeShapeType
;
return
data
.
settings
.
activeShapeType
;
};
};
// set the currently selected shape type
// set the currently selected shape type
var
setActiv
eShapeType
=
function
(
data
)
{
var
chang
eShapeType
=
function
(
data
)
{
data
.
settings
.
activeShapeType
=
data
.
measureWidgets
.
shape
.
val
();
data
.
settings
.
activeShapeType
=
data
.
measureWidgets
.
shape
.
val
();
};
};
// set the currently selected shape type
// set the currently selected shape type
var
change
ActiveShapeType
=
function
(
data
,
type
)
{
var
set
ActiveShapeType
=
function
(
data
,
type
)
{
data
.
settings
.
activeShapeType
=
type
;
data
.
settings
.
activeShapeType
=
type
;
data
.
measureWidgets
.
shape
.
val
(
type
);
};
};
// return line color chosen by user
// return line color chosen by user
...
@@ -968,18 +936,18 @@
...
@@ -968,18 +936,18 @@
};
};
// load shapes into select element
// load shapes into select element
var
loadShapeTypes
=
function
(
data
)
{
var
populateShapeSelect
=
function
(
data
)
{
var
$shape
=
data
.
measureWidgets
.
shape
;
var
$shape
=
data
.
measureWidgets
.
shape
;
var
shape
Types
=
data
.
settings
.
shape
Types
;
var
shape
Info
=
data
.
settings
.
shape
Info
;
var
addOption
=
function
(
index
,
type
)
{
var
addOption
=
function
(
index
,
type
)
{
$shape
.
append
(
$
(
'
<option value="
'
+
type
+
'
">
'
+
shape
Types
[
type
].
name
+
'
</option>
'
));
$shape
.
append
(
$
(
'
<option value="
'
+
type
+
'
">
'
+
shape
Info
[
type
].
name
+
'
</option>
'
));
};
};
$
.
each
(
data
.
settings
.
implementedShapes
,
addOption
);
$
.
each
(
data
.
settings
.
implementedShapes
,
addOption
);
$shape
.
children
()[
0
].
selected
=
true
;
$shape
.
children
()[
0
].
selected
=
true
;
};
};
// load units into select elements
// load units into select elements
var
loadSection
s
=
function
(
data
)
{
var
populateUnitSelect
s
=
function
(
data
)
{
var
widgets
=
data
.
measureWidgets
;
var
widgets
=
data
.
measureWidgets
;
var
$u1
=
widgets
.
unit1
;
var
$u1
=
widgets
.
unit1
;
var
$u2
=
widgets
.
unit2
;
var
$u2
=
widgets
.
unit2
;
...
@@ -1029,26 +997,21 @@
...
@@ -1029,26 +997,21 @@
var
widgets
=
{
var
widgets
=
{
names
:
[
names
:
[
'
move
'
,
'
startb
'
,
'
shape
'
,
'
move
'
,
'
startb
'
,
'
shape
'
,
// 'lenlabel', 'len', 'eq1',
'
info
'
,
'
info
'
,
'
value1
'
,
'
unit1
'
,
'
eq
2
'
,
'
value1
'
,
'
unit1
'
,
'
eq
'
,
'
value2
'
,
'
unit2
'
'
value2
'
,
'
unit2
'
],
],
move
:
$
(
'
<img id="dl-measure-move" src="img/move.png" title="move measuring bar around the screen"></img>
'
),
move
:
$
(
'
<img id="dl-measure-move" src="img/move.png" title="move measuring bar around the screen"></img>
'
),
startb
:
$
(
'
<button id="dl-measure-startb" title="click to draw a measuring shape on top of the image">M</button>
'
),
startb
:
$
(
'
<button id="dl-measure-startb" title="click to draw a measuring shape on top of the image">M</button>
'
),
shape
:
$
(
'
<select id="dl-measure-shape" title="select a shape to use for measuring" />
'
),
shape
:
$
(
'
<select id="dl-measure-shape" title="select a shape to use for measuring" />
'
),
// lenlabel : $('<span class="dl-measure-label" >len</span>'),
eq
:
$
(
'
<span class="dl-measure-label">=</span>
'
),
// faclabel : $('<span class="dl-measure-label" >factor</span>'),
info
:
$
(
'
<span id="dl-measure-shapetype" class="dl-measure-label">length</span>
'
),
// eq1 : $('<span class="dl-measure-label">=</span>'),
fac
:
$
(
'
<span id="dl-measure-factor" class="dl-measure-number" />
'
),
eq2
:
$
(
'
<span class="dl-measure-label">=</span>
'
),
// len : $('<span id="dl-measure-len" class="dl-measure-number">0.0</span>'),
info
:
$
(
'
<span id="dl-measure-shapeinfo" class="dl-measure-label">length</span>
'
),
fac
:
$
(
'
<span id="dl-measure-factor" class="dl-measure-number" />
'
),
value1
:
$
(
'
<input id="dl-measure-value1" class="dl-measure-input" title="last measured value - click to change the value" value="0.0" />
'
),
value1
:
$
(
'
<input id="dl-measure-value1" class="dl-measure-input" title="last measured value - click to change the value" value="0.0" />
'
),
value2
:
$
(
'
<span id="dl-measure-value2" class="dl-measure-label" title="last measured value, converted to the secondary unit" value="0.0"/>
'
),
value2
:
$
(
'
<span id="dl-measure-value2" class="dl-measure-label" title="last measured value, converted to the secondary unit" value="0.0"/>
'
),
unit1
:
$
(
'
<select id="dl-measure-unit1" title="current measuring unit - click to change" />
'
),
unit1
:
$
(
'
<select id="dl-measure-unit1" title="current measuring unit - click to change" />
'
),
unit2
:
$
(
'
<select id="dl-measure-unit2" title="secondary measuring unit - click to change" />
'
),
unit2
:
$
(
'
<select id="dl-measure-unit2" title="secondary measuring unit - click to change" />
'
),
angle
:
$
(
'
<span id="dl-measure-angle" class="dl-measure-number" title="last measured angle" />
'
)
angle
:
$
(
'
<span id="dl-measure-angle" class="dl-measure-number" title="last measured angle" />
'
)
};
};
var
$measureBar
=
$
(
'
<div id="dl-measure-toolbar" />
'
);
var
$measureBar
=
$
(
'
<div id="dl-measure-toolbar" />
'
);
$
.
each
(
widgets
.
names
,
function
(
index
,
item
)
{
$
.
each
(
widgets
.
names
,
function
(
index
,
item
)
{
...
@@ -1058,9 +1021,8 @@
...
@@ -1058,9 +1021,8 @@
data
.
$measureBar
=
$measureBar
;
data
.
$measureBar
=
$measureBar
;
widgets
.
fac
.
text
(
fn
.
cropFloatStr
(
data
.
measureFactor
));
widgets
.
fac
.
text
(
fn
.
cropFloatStr
(
data
.
measureFactor
));
data
.
measureWidgets
=
widgets
;
data
.
measureWidgets
=
widgets
;
populateShapeSelect
(
data
);
loadShapeTypes
(
data
);
populateUnitSelects
(
data
);
loadSections
(
data
);
setupMeasureWidgets
(
data
);
setupMeasureWidgets
(
data
);
widgets
.
move
.
on
(
'
mousedown.measure
'
,
dragMeasureBar
);
widgets
.
move
.
on
(
'
mousedown.measure
'
,
dragMeasureBar
);
return
$measureBar
;
return
$measureBar
;
...
@@ -1083,17 +1045,17 @@
...
@@ -1083,17 +1045,17 @@
$elem
.
digilib
(
action
);
$elem
.
digilib
(
action
);
return
false
;
return
false
;
});
});
widgets
.
shape
.
on
(
'
change.measure
'
,
function
(
evt
)
{
setActiv
eShapeType
(
data
)
});
widgets
.
shape
.
on
(
'
change.measure
'
,
function
(
evt
)
{
chang
eShapeType
(
data
)
});
widgets
.
value1
.
on
(
'
change.measure
'
,
function
(
evt
)
{
changeFactor
(
data
)
});
widgets
.
value1
.
on
(
'
change.measure
'
,
function
(
evt
)
{
changeFactor
(
data
)
});
widgets
.
unit1
.
on
(
'
change.measure
'
,
function
(
evt
)
{
update
Info
(
data
)
});
widgets
.
unit1
.
on
(
'
change.measure
'
,
function
(
evt
)
{
update
Calculation
(
data
)
});
widgets
.
unit2
.
on
(
'
change.measure
'
,
function
(
evt
)
{
update
Info
(
data
)
});
widgets
.
unit2
.
on
(
'
change.measure
'
,
function
(
evt
)
{
update
Calculation
(
data
)
});
};
};
// event handler
// event handler
var
handleSetup
=
function
(
evt
)
{
var
handleSetup
=
function
(
evt
)
{
console
.
debug
(
"
measure: handleSetup
"
);
console
.
debug
(
"
measure: handleSetup
"
);
var
data
=
this
;
var
data
=
this
;
data
.
lastMeasured
Distanc
e
=
0
;
data
.
lastMeasured
Valu
e
=
0
;
data
.
lastMeasuredAngle
=
0
;
data
.
lastMeasuredAngle
=
0
;
data
.
measureFactor
=
1.0
,
data
.
measureFactor
=
1.0
,
setupMeasureBar
(
data
);
setupMeasureBar
(
data
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment