Add view compass

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2026-05-24 11:52:56 -07:00
parent 8f12ac15fa
commit 37f1ae962f

View File

@@ -127,9 +127,11 @@ class AnnotationHandler extends CodeContentHandler {
'style' => 'width: 100%; height: auto;' 'style' => 'width: 100%; height: auto;'
); );
$elCompass = '';
$useCompass = '';
if (isset($metadata['view'])) { if (isset($metadata['view'])) {
$viewLabels = self::getCompassLabels($metadata['view']['direction'], $metadata['view']['rostral']); $viewLabels = self::getCompassLabels($metadata['view']['direction'], $metadata['view']['rostral']);
/*
$attrCompass = array( $attrCompass = array(
'id' => "compass{$svgID}", 'id' => "compass{$svgID}",
'viewBox' => '0 0 100 100', 'viewBox' => '0 0 100 100',
@@ -155,6 +157,38 @@ class AnnotationHandler extends CodeContentHandler {
array_push($compass, Html::rawElement('path',$attrCompBkArrow)); array_push($compass, Html::rawElement('path',$attrCompBkArrow));
array_push($compass,Html::closeElement('symbol')); array_push($compass,Html::closeElement('symbol'));
*/
$rotate = $metadata['view']['rotate'] ?? 0;
$textRotate = $rotate * -1;
$elCompass = <<<comp
<symbol id="compass$svgID" viewBox="0 0 100 100" preserveAspectRatio="xMinYMin meet" refX="left" refY="top" style="font-family:'TeX Gyre DejaVu Math';font-size:11.686px;letter-spacing:0px;line-height:125%;text-align:center;text-anchor:middle;word-spacing:0px">
<circle cx="50" cy="50" r="50" style="fill-opacity:.35;fill:#ffffff;"></circle>
<path d="M 50,81.3 41.4,58.6 18.7,50 41.4,41.4 50,18.7 58.6,41.4 81.3,50 58.6,58.6 Z" style="fill:#000000;stroke-width:1.5;stroke:#000000"></path>
<path d="m50 81.3 -8.6 -22.6 0 -8.6 -22.6 0 22.6 -8.6 8.6 0 0 -22.6 8.6 22.6 0 8.6 22.6 0 -22.6 8.6 -8.6 0z" style="fill:#ffffff;stroke-width:1.5025"></path>
<circle cx="50" cy="50" r="12.437" style="fill:#ffffff;stroke-width:1.5025;stroke:#000000;"></circle>
<text x="50.000000" y="54.000000" text-align="center" transform="rotate($textRotate)" transform-origin="center" style="transform-box: fill-box;fill:#000000;">{$viewLabels[0]}</text>
<text x="50.000000" y="13.000000" text-align="center" transform="rotate($textRotate)" transform-origin="center" style="transform-box: fill-box;fill:#000000;">{$viewLabels[1]}</text>
<text x="90.000000" y="54.000000" text-align="center" transform="rotate($textRotate)" transform-origin="center" style="transform-box: fill-box;fill:#000000;">{$viewLabels[2]}</text>
<text x="50.000000" y="96.000000" text-align="center" transform="rotate($textRotate)" transform-origin="center" style="transform-box: fill-box;fill:#000000;">{$viewLabels[3]}</text>
<text x="10.000000" y="54.000000" text-align="center" transform="rotate($textRotate)" transform-origin="center" style="transform-box: fill-box;fill:#000000;">{$viewLabels[4]}</text>
</symbol>
comp;
//TODO: Right and Bottom and/or negative positioning
$compLeft = $metadata['view']['left'] ?? 0;
$compTop = $metadata['view']['top'] ?? 0;
$compRotX = $compLeft + (($metadata['view']['size'] ?? 25) * .5);
$compRotY = $compTop + (($metadata['view']['size'] ?? 25) * .5);
$attrCompass = array(
'href'=> "#compass" . $svgID,
'transform' => "scale( $fixScale ) rotate( $rotate $compRotX $compRotY)",
'x' => $compLeft,
'y' => $compTop,
'width' => $metadata['view']['size'] ?? 25,
'height' => $metadata['view']['size'] ?? 25,
'style' => "transform-box: fill-box;"
);
$useCompass = Html::rawElement('use', $attrCompass);
} }
if (isset($metadata['annotation'])) { if (isset($metadata['annotation'])) {
@@ -163,7 +197,7 @@ class AnnotationHandler extends CodeContentHandler {
$leadLines = []; $leadLines = [];
foreach($metadata['annotation'] as $label => $annot) { foreach($metadata['annotation'] as $label => $annot) {
if (isset($annot['position'])) { if (isset($annot['position'])) {
$marker = array(Html::openElement('g',array('transform' => "scale( {$fixScale} {$fixScale})"))); $marker = array(Html::openElement('g',array('transform' => "scale( {$fixScale} )")));
$attrMask = array( $attrMask = array(
'cx' => $annot['position']['0'], 'cx' => $annot['position']['0'],
'cy' => $annot['position']['1'], 'cy' => $annot['position']['1'],
@@ -215,7 +249,7 @@ class AnnotationHandler extends CodeContentHandler {
$svgDefs = Html::rawElement('defs',array(),$markMask); $svgDefs = Html::rawElement('defs',array(),$markMask);
} }
return Html::rawElement('svg', $attrSvg, $svgDefs. implode($compass) . $elBaseImg . implode($annotations) ); return Html::rawElement('svg', $attrSvg, $svgDefs. $elCompass . $elBaseImg . implode($annotations) . $useCompass );
} }
public function validateSave( Content $content, ValidationParams $validationParams ) { public function validateSave( Content $content, ValidationParams $validationParams ) {