@orbat-mapper/point-symbols 0.1.22 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +52 -2
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -10,6 +10,7 @@ function stableValue(value) {
10
10
  function pointSymbolDrawingKey(symbol, capabilityOptions, resolvedOptions) {
11
11
  const drawingStyle = { ...symbol.style ?? {} };
12
12
  delete drawingStyle.opacity;
13
+ delete drawingStyle.overallOpacity;
13
14
  return JSON.stringify(stableValue({
14
15
  sidc: symbol.sidc.trim(),
15
16
  textAmplifiers: normalizeTextAmplifiers(symbol.textAmplifiers),
@@ -73,12 +74,19 @@ function resolveMilsymbolOptions(symbol, capabilityOptions, resolvedOptions) {
73
74
  options.size = CANONICAL_OCTAGON_SIZE;
74
75
  return options;
75
76
  }
77
+ function constructBodySymbol(sidc, options) {
78
+ return new ms.Symbol(sidc, {
79
+ ...options,
80
+ hqStaffLength: Object(0)
81
+ });
82
+ }
76
83
  function renderPointSymbolWithRevision(symbol, revision, capabilityOptions, resolvedOptions) {
77
- const rendered = new ms.Symbol(symbol.sidc.trim(), resolveMilsymbolOptions(symbol, capabilityOptions, resolvedOptions));
84
+ const options = resolveMilsymbolOptions(symbol, capabilityOptions, resolvedOptions);
85
+ const rendered = new ms.Symbol(symbol.sidc.trim(), options);
78
86
  const { width, height } = rendered.getSize();
79
87
  const valid = rendered.isValid() === true;
80
88
  const validation = rendered.isValid(true);
81
- return {
89
+ const result = {
82
90
  resourceId: `milsymbol-${revision}-${hashKey(pointSymbolDrawingKey(symbol, capabilityOptions, resolvedOptions))}`,
83
91
  svg: rendered.asSVG(),
84
92
  octagonSize: CANONICAL_OCTAGON_SIZE,
@@ -89,6 +97,48 @@ function renderPointSymbolWithRevision(symbol, revision, capabilityOptions, reso
89
97
  valid,
90
98
  ...valid ? {} : { validation }
91
99
  };
100
+ const metadata = rendered.getMetadata();
101
+ const bbox = metadata.baseGeometry.bbox;
102
+ const framed = bbox.x2 > bbox.x1 && bbox.y2 > bbox.y1;
103
+ if (valid) {
104
+ const bodySymbol = metadata.headquarters ? constructBodySymbol(symbol.sidc.trim(), options) : rendered;
105
+ const bodyRegistration = framed ? bodySymbol.getOctagonAnchor() : bodySymbol.getAnchor();
106
+ const body = {
107
+ ...result,
108
+ resourceId: `${result.resourceId}-body`,
109
+ svg: bodySymbol.asSVG(),
110
+ ...bodySymbol.getSize(),
111
+ anchor: bodyRegistration,
112
+ octagonAnchor: bodySymbol.getOctagonAnchor()
113
+ };
114
+ const local = (x, y) => ({
115
+ x: body.octagonAnchor.x + x - 100,
116
+ y: body.octagonAnchor.y + y - 100
117
+ });
118
+ const resolveAttachment = () => {
119
+ if (!framed) return bodyRegistration;
120
+ if (!metadata.headquarters) return local(100, bbox.y2);
121
+ const squareFrame = metadata.affiliation === "Friend" || metadata.affiliation === "Neutral";
122
+ return local(bbox.x1, squareFrame ? bbox.y2 : 100);
123
+ };
124
+ const attachment = resolveAttachment();
125
+ const colors = rendered.getColors();
126
+ result.offset = {
127
+ body,
128
+ ordinaryRegistration: framed ? result.octagonAnchor : result.anchor,
129
+ attachment,
130
+ indicator: {
131
+ direction: {
132
+ x: 0,
133
+ y: 1
134
+ },
135
+ length: 100
136
+ },
137
+ strokeColor: symbol.style?.monoColor ?? symbol.style?.colors?.frame ?? colors.iconColor[metadata.affiliation] ?? "#000000",
138
+ strokeWidth: Number(options.strokeWidth ?? 4)
139
+ };
140
+ }
141
+ return result;
92
142
  }
93
143
  function renderPointSymbol(symbol) {
94
144
  return renderPointSymbolWithRevision(symbol, 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/point-symbols",
3
- "version": "0.1.22",
3
+ "version": "0.2.0",
4
4
  "description": "Milsymbol-backed MIL-STD-2525 and APP-6 point symbols for tactical-draw.",
5
5
  "license": "MIT",
6
6
  "author": "Orbat Mapper",
@@ -24,8 +24,8 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@orbat-mapper/control-measures": "^0.23.0",
28
- "@orbat-mapper/tactical-draw": "^0.7.0"
27
+ "@orbat-mapper/control-measures": "^0.24.0",
28
+ "@orbat-mapper/tactical-draw": "^0.8.0"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "milsymbol": ">=3.0.4 <4.0.0"