Merge branch 'fix_zone_edit' into storageareas

This commit is contained in:
Isaac Connor 2016-06-07 11:45:50 -04:00
commit b2dfdea66e
2 changed files with 34 additions and 1 deletions

View File

@ -247,7 +247,7 @@ function applyZoneUnits()
}
else
{
form.elements['newZone[TempArea]'].value = 100;
form.elements['newZone[TempArea]'].value = Math.round( area/monitorArea * 100 );
toPercent( form.elements['newZone[MinAlarmPixels]'], area );
toPercent( form.elements['newZone[MaxAlarmPixels]'], area );
toPercent( form.elements['newZone[MinFilterPixels]'], area );
@ -323,6 +323,7 @@ function updateZoneImage()
Point.y = zone['Points'][i].y;
Poly.points.appendItem( Point );
}
updateArea();
}
function fixActivePoint( index )
@ -356,6 +357,7 @@ function updateActivePoint( index )
var Point = $('zonePoly').points.getItem(index);
Point.x =x;
Point.y =y;
updateArea();
}
@ -379,6 +381,7 @@ function delPoint( index )
{
zone['Points'].splice( index, 1 );
drawZonePoints();
updateArea();
}
function limitPointValue( point, loVal, hiVal )
@ -386,6 +389,21 @@ function limitPointValue( point, loVal, hiVal )
point.value = constrainValue(point.value, loVal, hiVal)
}
function updateArea( ) {
area = Polygon_calcArea( zone['Points'] );
zone.Area = area;
var form = $('zoneForm');
form.elements['newZone[Area]'].value = area;
if ( form.elements['newZone[Units]'].value == 'Percent' ) {
form.elements['newZone[TempArea]'].value = Math.round( area/monitorArea*100 );
} else if ( form.elements['newZone[Units]'].value == 'Pixels' ) {
form.elements['newZone[TempArea]'].value = area;
} else {
alert("Unknown units: " + form.elements['newZone[Units]'].value );
}
}
function updateX( index )
{
limitPointValue( $('newZone[Points]['+index+'][x]'), 0, maxX );
@ -398,6 +416,7 @@ function updateX( index )
var Point = $('zonePoly').points.getItem(index);
Point.x =x;
Point.y =y;
updateArea();
}
function updateY( index )
@ -412,6 +431,7 @@ function updateY( index )
var Point = $('zonePoly').points.getItem(index);
Point.x =x;
Point.y =y;
updateArea();
}
function saveChanges( element )
@ -739,4 +759,16 @@ function initPage() {
appletRefresh.delay( appletRefreshTime*1000 );
}
function Polygon_calcArea( coords ) {
var n_coords = coords.length;
var float_area = 0.0;
for ( i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
var trap_area = ( ( coords[i].x - coords[j].x ) * ( coords[i].y + coords[j].y ) ) / 2;
float_area += trap_area;
//printf( "%.2f (%.2f)\n", float_area, trap_area );
}
return Math.round( Math.abs( float_area ) );
}
window.addEvent( 'domready', initPage );

View File

@ -48,6 +48,7 @@ zone['Points'][<?php echo $i ?>] = { 'x': <?php echo $newZone['Points'][$i]['x']
var maxX = <?php echo $monitor->Width()-1 ?>;
var maxY = <?php echo $monitor->Height()-1 ?>;
var monitorArea = <?php echo $monitor->Width() * $monitor->Height() ?>;
var selfIntersecting = <?php echo $selfIntersecting?'true':'false' ?>;
var selfIntersectingString = '<?php echo addslashes(translate('SelfIntersecting')) ?>';