@ngageoint/mage.service 6.2.9 → 6.2.10-beta.1

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 (139) hide show
  1. package/lib/@types/express/index.d.ts +1 -1
  2. package/lib/adapters/icons/adapters.icons.db.mongoose.js.map +1 -1
  3. package/lib/adapters/observations/adapters.observations.controllers.web.js +2 -2
  4. package/lib/adapters/observations/adapters.observations.controllers.web.js.map +1 -1
  5. package/lib/adapters/observations/adapters.observations.dto.ecma404-json.d.ts +1 -1
  6. package/lib/adapters/observations/adapters.observations.dto.ecma404-json.js +1 -1
  7. package/lib/api/attachment.d.ts +3 -0
  8. package/lib/api/attachment.d.ts.map +1 -1
  9. package/lib/api/attachment.js +3 -0
  10. package/lib/api/attachment.js.map +1 -1
  11. package/lib/api/icon.d.ts +51 -20
  12. package/lib/api/icon.js +1 -1
  13. package/lib/api/icon.js.map +1 -1
  14. package/lib/api/location.d.ts +1 -3
  15. package/lib/api/location.d.ts.map +1 -1
  16. package/lib/app.api/observations/app.api.observations.js +1 -1
  17. package/lib/app.api/observations/app.api.observations.js.map +1 -1
  18. package/lib/app.d.ts +2 -2
  19. package/lib/app.d.ts.map +1 -1
  20. package/lib/app.impl/observations/app.impl.observations.d.ts.map +1 -1
  21. package/lib/app.impl/observations/app.impl.observations.js +2 -1
  22. package/lib/app.impl/observations/app.impl.observations.js.map +1 -1
  23. package/lib/app.js +5 -3
  24. package/lib/app.js.map +1 -1
  25. package/lib/authentication/saml.d.ts.map +1 -1
  26. package/lib/authentication/saml.js +15 -14
  27. package/lib/authentication/saml.js.map +1 -1
  28. package/lib/dist-package.json +45 -45
  29. package/lib/docs/auth/local.yaml +1 -2
  30. package/lib/entities/authorization/entities.permissions.d.ts +7 -1
  31. package/lib/entities/authorization/entities.permissions.d.ts.map +1 -1
  32. package/lib/entities/authorization/entities.permissions.js +7 -2
  33. package/lib/entities/authorization/entities.permissions.js.map +1 -1
  34. package/lib/entities/entities.global.d.ts +6 -0
  35. package/lib/entities/entities.global.d.ts.map +1 -1
  36. package/lib/entities/entities.global.js +12 -1
  37. package/lib/entities/entities.global.js.map +1 -1
  38. package/lib/entities/events/entities.events.d.ts.map +1 -1
  39. package/lib/entities/events/entities.events.forms.d.ts +9 -1
  40. package/lib/entities/events/entities.events.forms.d.ts.map +1 -1
  41. package/lib/entities/events/entities.events.forms.js +24 -3
  42. package/lib/entities/events/entities.events.forms.js.map +1 -1
  43. package/lib/entities/events/entities.events.js.map +1 -1
  44. package/lib/entities/locations/entities.locations.d.ts +30 -0
  45. package/lib/entities/locations/entities.locations.d.ts.map +1 -0
  46. package/lib/entities/locations/entities.locations.js +3 -0
  47. package/lib/entities/locations/entities.locations.js.map +1 -0
  48. package/lib/entities/observations/entities.observations.d.ts +4 -4
  49. package/lib/entities/observations/entities.observations.d.ts.map +1 -1
  50. package/lib/entities/observations/entities.observations.js +16 -15
  51. package/lib/entities/observations/entities.observations.js.map +1 -1
  52. package/lib/environment/env.js +1 -1
  53. package/lib/environment/env.js.map +1 -1
  54. package/lib/export/csv.d.ts +19 -9
  55. package/lib/export/csv.d.ts.map +1 -1
  56. package/lib/export/csv.js +254 -231
  57. package/lib/export/csv.js.map +1 -1
  58. package/lib/export/exporter.d.ts +37 -10
  59. package/lib/export/exporter.d.ts.map +1 -1
  60. package/lib/export/exporter.js +67 -35
  61. package/lib/export/exporter.js.map +1 -1
  62. package/lib/export/geojson.d.ts +9 -8
  63. package/lib/export/geojson.d.ts.map +1 -1
  64. package/lib/export/geojson.js +162 -143
  65. package/lib/export/geojson.js.map +1 -1
  66. package/lib/export/geopackage.d.ts +29 -23
  67. package/lib/export/geopackage.d.ts.map +1 -1
  68. package/lib/export/geopackage.js +657 -589
  69. package/lib/export/geopackage.js.map +1 -1
  70. package/lib/export/index.d.ts +17 -0
  71. package/lib/export/index.d.ts.map +1 -0
  72. package/lib/export/index.js +28 -0
  73. package/lib/export/index.js.map +1 -0
  74. package/lib/export/kml.d.ts +11 -8
  75. package/lib/export/kml.d.ts.map +1 -1
  76. package/lib/export/kml.js +152 -106
  77. package/lib/export/kml.js.map +1 -1
  78. package/lib/export/kmlWriter.d.ts +23 -22
  79. package/lib/export/kmlWriter.d.ts.map +1 -1
  80. package/lib/export/kmlWriter.js +258 -181
  81. package/lib/export/kmlWriter.js.map +1 -1
  82. package/lib/express.js +2 -4
  83. package/lib/express.js.map +1 -1
  84. package/lib/migrations/030-saml-settings.d.ts +4 -0
  85. package/lib/migrations/030-saml-settings.d.ts.map +1 -0
  86. package/lib/migrations/030-saml-settings.js +96 -0
  87. package/lib/migrations/030-saml-settings.js.map +1 -0
  88. package/lib/models/authentication.js +1 -1
  89. package/lib/models/authenticationconfiguration.js +0 -1
  90. package/lib/models/authenticationconfiguration.js.map +1 -1
  91. package/lib/models/event.d.ts +4 -2
  92. package/lib/models/event.js +1 -1
  93. package/lib/models/event.js.map +1 -1
  94. package/lib/models/export.d.ts +56 -17
  95. package/lib/models/export.d.ts.map +1 -1
  96. package/lib/models/export.js.map +1 -1
  97. package/lib/models/icon.d.ts +24 -9
  98. package/lib/models/icon.d.ts.map +1 -1
  99. package/lib/models/icon.js +3 -6
  100. package/lib/models/icon.js.map +1 -1
  101. package/lib/models/location.d.ts +40 -8
  102. package/lib/models/location.d.ts.map +1 -1
  103. package/lib/models/location.js +2 -0
  104. package/lib/models/location.js.map +1 -1
  105. package/lib/models/observation.d.ts +27 -0
  106. package/lib/models/observation.js.map +1 -1
  107. package/lib/models/user.d.ts +3 -0
  108. package/lib/models/user.js +1 -1
  109. package/lib/provision/index.js +1 -1
  110. package/lib/provision/index.js.map +1 -1
  111. package/lib/routes/authenticationconfigurations.d.ts.map +1 -1
  112. package/lib/routes/authenticationconfigurations.js +4 -5
  113. package/lib/routes/authenticationconfigurations.js.map +1 -1
  114. package/lib/routes/events.d.ts.map +1 -1
  115. package/lib/routes/events.js +19 -10
  116. package/lib/routes/events.js.map +1 -1
  117. package/lib/routes/exports.d.ts +3 -2
  118. package/lib/routes/exports.d.ts.map +1 -1
  119. package/lib/routes/exports.js +121 -79
  120. package/lib/routes/exports.js.map +1 -1
  121. package/lib/routes/imports.d.ts.map +1 -1
  122. package/lib/routes/imports.js +4 -2
  123. package/lib/routes/imports.js.map +1 -1
  124. package/lib/routes/layers.d.ts.map +1 -1
  125. package/lib/routes/layers.js +11 -45
  126. package/lib/routes/layers.js.map +1 -1
  127. package/lib/routes/locations.d.ts.map +1 -1
  128. package/lib/routes/locations.js +7 -3
  129. package/lib/routes/locations.js.map +1 -1
  130. package/lib/routes/routes.types.d.ts +9 -0
  131. package/lib/routes/setup.js +1 -1
  132. package/lib/routes/setup.js.map +1 -1
  133. package/lib/tsconfig.tsbuildinfo +1 -1
  134. package/npm-shrinkwrap.json +4411 -7493
  135. package/package.json +45 -45
  136. package/lib/export/exporterFactory.d.ts +0 -11
  137. package/lib/export/exporterFactory.d.ts.map +0 -1
  138. package/lib/export/exporterFactory.js +0 -17
  139. package/lib/export/exporterFactory.js.map +0 -1
@@ -1,20 +1,73 @@
1
1
  'use strict';
2
- const moment = require('moment'), path = require('path'), mgrs = require('mgrs'), { default: turfCentroid } = require('@turf/centroid'), { fragment } = require('xmlbuilder2');
3
- function KmlWriter() { }
4
- module.exports = new KmlWriter();
5
- function hexToParts(hex) {
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getFieldByName = exports.generatePlacemarkCoordinates = exports.generateDescription = exports.generateKMLClose = exports.generateKMLFolderClose = exports.generateKMLDocumentClose = exports.generateLocationPlacemark = exports.generateObservationPlacemark = exports.generateObservationStyles = exports.generateFormStyles = exports.generateEventStyle = exports.generateUserStyle = exports.generateKMLFolderStart = exports.generateKMLDocument = void 0;
7
+ const mgrs = require('mgrs');
8
+ const moment_1 = __importDefault(require("moment"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const centroid_1 = __importDefault(require("@turf/centroid"));
11
+ const xmlbuilder2_1 = require("xmlbuilder2");
12
+ const entities_events_forms_1 = require("../entities/events/entities.events.forms");
13
+ const defaultStyle = {
14
+ fill: '#5278A2',
15
+ stroke: '#5278A2',
16
+ fillOpacity: 0.2,
17
+ strokeOpacity: 1,
18
+ strokeWidth: 2
19
+ };
20
+ function requiredStyle(style) {
21
+ const dup = (0, entities_events_forms_1.copyBaseFormStyle)(style);
22
+ dup.fill = style.fill || defaultStyle.fill,
23
+ dup.stroke = style.stroke || defaultStyle.stroke,
24
+ dup.fillOpacity = isNumber(style.fillOpacity) ? style.fillOpacity : defaultStyle.fillOpacity,
25
+ dup.strokeOpacity = isNumber(style.strokeOpacity) ? style.strokeOpacity : defaultStyle.strokeOpacity,
26
+ dup.strokeWidth = isNumber(style.strokeWidth) ? style.strokeWidth : defaultStyle.strokeWidth;
27
+ return dup;
28
+ }
29
+ function isNumber(x) {
30
+ return !isNaN(x) && typeof x === 'number';
31
+ }
32
+ function splitRGBHexColor(hex) {
6
33
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
7
- return result ? {
8
- r: result[1],
9
- g: result[2],
10
- b: result[3]
11
- } : null;
34
+ if (result) {
35
+ return { r: result[1], g: result[2], b: result[3] };
36
+ }
37
+ return { r: '00', g: '00', b: '00' };
12
38
  }
13
- function convert(integer) {
39
+ function hexStringForInt(integer) {
14
40
  const str = Number(integer).toString(16);
15
41
  return str.length === 1 ? "0" + str : str;
16
42
  }
17
- KmlWriter.prototype.generateKMLDocument = function () {
43
+ function rgbIntForDecimal(maybeDec) {
44
+ return ~~(numberOrDefault(maybeDec, 1) * 255);
45
+ }
46
+ function colorHexForDecimal(maybeDec) {
47
+ return hexStringForInt(rgbIntForDecimal(maybeDec));
48
+ }
49
+ function numberOrDefault(maybeNumber, def) {
50
+ return typeof maybeNumber === 'number' && !Number.isNaN(maybeNumber) ? maybeNumber : def;
51
+ }
52
+ function kmlColor(rgb, opacityDecimal) {
53
+ const opacityHex = colorHexForDecimal(opacityDecimal);
54
+ return opacityHex + rgb.b + rgb.g + rgb.r;
55
+ }
56
+ /**
57
+ * Return the stroke opacity decimal for the given style if present, or the
58
+ * default stroke opacity.
59
+ */
60
+ function ensureStrokeOpacity(maybe) {
61
+ return numberOrDefault(maybe === null || maybe === void 0 ? void 0 : maybe.strokeOpacity, defaultStyle.strokeOpacity);
62
+ }
63
+ /**
64
+ * Return the fill opacity decimal for the given style if present, or the
65
+ * default fill opacity.
66
+ */
67
+ function ensureFillOpacity(maybe) {
68
+ return numberOrDefault(maybe === null || maybe === void 0 ? void 0 : maybe.fillOpacity, defaultStyle.fillOpacity);
69
+ }
70
+ function generateKMLDocument() {
18
71
  return "<?xml version='1.0' encoding='UTF-8'?>" +
19
72
  "<kml xmlns='http://www.opengis.net/kml/2.2' " +
20
73
  "xmlns:gx='http://www.google.com/kml/ext/2.2' " +
@@ -23,61 +76,64 @@ KmlWriter.prototype.generateKMLDocument = function () {
23
76
  "<Document>" +
24
77
  "<name>MAGE-Export.kml</name>" +
25
78
  "<open>1</open>";
26
- };
27
- KmlWriter.prototype.generateKMLFolderStart = function (name) {
79
+ }
80
+ exports.generateKMLDocument = generateKMLDocument;
81
+ function generateKMLFolderStart(name) {
28
82
  return `<Folder><name>${name}</name>`;
29
- };
30
- KmlWriter.prototype.generateUserStyle = function (user) {
31
- let userStyle = '';
83
+ }
84
+ exports.generateKMLFolderStart = generateKMLFolderStart;
85
+ function generateUserStyle(user) {
32
86
  if (user.icon && user.icon.relativePath) {
33
- userStyle = fragment({
87
+ return (0, xmlbuilder2_1.fragment)({
34
88
  Style: {
35
89
  '@id': `user-${user._id.toString()}`,
36
90
  IconStyle: {
37
91
  Icon: {
38
- href: path.join('icons/users', user._id.toString())
92
+ href: path_1.default.join('icons/users', user._id.toString())
39
93
  }
40
94
  }
41
95
  }
42
96
  }).end();
43
97
  }
44
- return userStyle;
45
- };
46
- KmlWriter.prototype.generateEventStyle = function (event, icons) {
98
+ return '';
99
+ }
100
+ exports.generateUserStyle = generateUserStyle;
101
+ function generateEventStyle(event, icons) {
47
102
  const defaultIcon = icons.find(icon => !icon.formId && !icon.primary && !icon.variant);
48
- const strokeParts = hexToParts(event.style.stroke);
49
- const fillParts = hexToParts(event.style.fill);
50
- const strokeOpacity = convert(~~(event.style.strokeOpacity * 255));
51
- const fillOpacity = convert(~~(event.style.fillOpacity * 255));
52
- return fragment({
103
+ const strokeParts = splitRGBHexColor(event.style.stroke || '');
104
+ const fillParts = splitRGBHexColor(event.style.fill || '');
105
+ const strokeOpacity = ensureStrokeOpacity(event.style);
106
+ const fillOpacity = ensureFillOpacity(event.style);
107
+ return (0, xmlbuilder2_1.fragment)({
53
108
  Style: {
54
- '@id': event._id.toString(),
109
+ '@id': String(event._id),
55
110
  IconStyle: {
56
111
  Icon: {
57
- href: path.join('icons', defaultIcon.relativePath)
112
+ href: path_1.default.join('icons', defaultIcon.relativePath)
58
113
  }
59
114
  },
60
115
  LineStyle: {
61
116
  width: event.style.strokeWidth,
62
- color: strokeOpacity + strokeParts.b + strokeParts.g + strokeParts.r
117
+ color: kmlColor(strokeParts, strokeOpacity)
63
118
  },
64
119
  PolyStyle: {
65
- color: fillOpacity + fillParts.b + fillParts.g + fillParts.r
120
+ color: kmlColor(fillParts, fillOpacity)
66
121
  }
67
122
  }
68
123
  }).end();
69
- };
70
- KmlWriter.prototype.generateFormStyles = function (event, form, icons) {
71
- const styles = [];
72
- const style = form.style || event.style;
73
- let defaultIconPath = "";
124
+ }
125
+ exports.generateEventStyle = generateEventStyle;
126
+ function generateFormStyles(event, form, icons) {
127
+ const styleKmlFragments = [];
128
+ const style = requiredStyle(form.style || event.style);
129
+ let defaultIconPath = '';
74
130
  const primaryPathMap = {};
75
131
  const secondaryPathMap = {};
76
132
  let strokeWidth = style.strokeWidth;
77
- let strokeParts = hexToParts(style.stroke);
78
- let fillParts = hexToParts(style.fill);
79
- let strokeOpacity = convert(~~(style.strokeOpacity * 255));
80
- let fillOpacity = convert(~~(style.fillOpacity * 255));
133
+ let strokeParts = splitRGBHexColor(style.stroke || '');
134
+ let fillParts = splitRGBHexColor(style.fill || '');
135
+ let strokeOpacity = ensureStrokeOpacity(style);
136
+ let fillOpacity = ensureFillOpacity(style);
81
137
  icons.forEach(icon => {
82
138
  if (icon.variant) {
83
139
  secondaryPathMap[icon.primary] = secondaryPathMap[icon.primary] || {};
@@ -91,56 +147,57 @@ KmlWriter.prototype.generateFormStyles = function (event, form, icons) {
91
147
  }
92
148
  });
93
149
  // default form style
94
- const defaultStyle = fragment({
150
+ const defaultStyleKml = (0, xmlbuilder2_1.fragment)({
95
151
  Style: {
96
- '@id': [event._id.toString(), form._id.toString()].join("-"),
152
+ '@id': `${event._id}-${form._id}`,
97
153
  IconStyle: {
98
154
  Icon: {
99
- href: path.join('icons', defaultIconPath)
155
+ href: path_1.default.join('icons', defaultIconPath)
100
156
  }
101
157
  },
102
158
  LineStyle: {
103
159
  width: strokeWidth,
104
- color: strokeOpacity + strokeParts.b + strokeParts.g + strokeParts.r
160
+ color: kmlColor(strokeParts, strokeOpacity)
105
161
  },
106
162
  PolyStyle: {
107
- color: fillOpacity + fillParts.b + fillParts.g + fillParts.r
163
+ color: kmlColor(fillParts, fillOpacity)
108
164
  }
109
165
  }
110
166
  }).end();
111
- styles.push(defaultStyle);
112
- const primaryField = this.getFieldByName(form, form.primaryField);
113
- if (primaryField) {
167
+ styleKmlFragments.push(defaultStyleKml);
168
+ const primaryField = form.primaryField ? getFieldByName(form, form.primaryField) : undefined;
169
+ if (primaryField && Array.isArray(primaryField.choices)) {
114
170
  primaryField.choices.forEach(choice => {
115
171
  let iconPath = primaryPathMap[choice.title] ? primaryPathMap[choice.title] : defaultIconPath;
116
- if (style[choice.title]) {
117
- strokeWidth = style[choice.title].strokeWidth;
118
- strokeParts = hexToParts(style[choice.title].stroke);
119
- fillParts = hexToParts(style[choice.title].fill);
120
- strokeOpacity = convert(~~(style[choice.title].strokeOpacity * 255));
121
- fillOpacity = convert(~~(style[choice.title].fillOpacity * 255));
172
+ const primaryChoiceStyle = style[choice.title];
173
+ if (primaryChoiceStyle) {
174
+ strokeWidth = numberOrDefault(primaryChoiceStyle.strokeWidth, strokeWidth);
175
+ strokeParts = splitRGBHexColor(primaryChoiceStyle.stroke || defaultStyle.stroke);
176
+ fillParts = splitRGBHexColor(primaryChoiceStyle.fill || defaultStyle.fill);
177
+ strokeOpacity = ensureStrokeOpacity(primaryChoiceStyle);
178
+ fillOpacity = ensureFillOpacity(primaryChoiceStyle);
122
179
  }
123
- const primaryStyle = fragment({
180
+ const primaryStyleKml = (0, xmlbuilder2_1.fragment)({
124
181
  Style: {
125
- '@id': [event._id.toString(), form._id.toString(), choice.title].join("-"),
182
+ '@id': `${event._id}-${form._id.toString()}-${choice.title}`,
126
183
  IconStyle: {
127
184
  Icon: {
128
- href: path.join('icons', iconPath)
185
+ href: path_1.default.join('icons', iconPath)
129
186
  }
130
187
  },
131
188
  LineStyle: {
132
189
  width: strokeWidth,
133
- color: strokeOpacity + strokeParts.b + strokeParts.g + strokeParts.r
190
+ color: kmlColor(strokeParts, strokeOpacity)
134
191
  },
135
192
  PolyStyle: {
136
- color: fillOpacity + fillParts.b + fillParts.g + fillParts.r
193
+ color: kmlColor(fillParts, fillOpacity)
137
194
  }
138
195
  }
139
196
  }).end();
140
- styles.push(primaryStyle);
197
+ styleKmlFragments.push(primaryStyleKml);
141
198
  // secondary styles for each type
142
- const secondaryField = this.getFieldByName(form, form.variantField);
143
- if (secondaryField) {
199
+ const secondaryField = getFieldByName(form, form.variantField || '');
200
+ if (secondaryField && Array.isArray(secondaryField.choices)) {
144
201
  secondaryField.choices.forEach(secondaryChoice => {
145
202
  if (secondaryPathMap[choice.title] && secondaryPathMap[choice.title][secondaryChoice.title]) {
146
203
  iconPath = secondaryPathMap[choice.title][secondaryChoice.title];
@@ -151,102 +208,106 @@ KmlWriter.prototype.generateFormStyles = function (event, form, icons) {
151
208
  else {
152
209
  iconPath = defaultIconPath;
153
210
  }
154
- if (style[choice.title] && style[choice.title][secondaryChoice.title]) {
155
- strokeWidth = style[choice.title][secondaryChoice.title].strokeWidth;
156
- strokeParts = hexToParts(style[choice.title][secondaryChoice.title].stroke);
157
- fillParts = hexToParts(style[choice.title][secondaryChoice.title].fill);
158
- strokeOpacity = convert(~~(style[choice.title][secondaryChoice.title].strokeOpacity * 255));
159
- fillOpacity = convert(~~(style[choice.title][secondaryChoice.title].fillOpacity * 255));
211
+ const variantStyle = primaryChoiceStyle === null || primaryChoiceStyle === void 0 ? void 0 : primaryChoiceStyle[secondaryChoice.title];
212
+ if (variantStyle) {
213
+ strokeWidth = variantStyle.strokeWidth;
214
+ strokeParts = splitRGBHexColor(variantStyle.stroke);
215
+ fillParts = splitRGBHexColor(variantStyle.fill);
216
+ strokeOpacity = ensureStrokeOpacity(variantStyle);
217
+ fillOpacity = ensureFillOpacity(variantStyle);
160
218
  }
161
- const secondaryStyle = fragment({
219
+ const variantStyleKml = (0, xmlbuilder2_1.fragment)({
162
220
  Style: {
163
- '@id': [event._id.toString(), form._id.toString(), choice.title, secondaryChoice.title].join("-"),
221
+ '@id': `${event._id}-${form._id.toString()}-${choice.title}-${secondaryChoice.title}`,
164
222
  IconStyle: {
165
223
  Icon: {
166
- href: path.join('icons', iconPath)
224
+ href: path_1.default.join('icons', iconPath)
167
225
  }
168
226
  },
169
227
  LineStyle: {
170
228
  width: strokeWidth,
171
- color: strokeOpacity + strokeParts.b + strokeParts.g + strokeParts.r
229
+ color: kmlColor(strokeParts, strokeOpacity)
172
230
  },
173
231
  PolyStyle: {
174
- color: fillOpacity + fillParts.b + fillParts.g + fillParts.r
232
+ color: kmlColor(fillParts, fillOpacity)
175
233
  }
176
234
  }
177
235
  }).end();
178
- styles.push(secondaryStyle);
236
+ styleKmlFragments.push(variantStyleKml);
179
237
  });
180
238
  }
181
239
  });
182
240
  }
183
- return styles;
184
- };
185
- KmlWriter.prototype.generateObservationStyles = function (event, icons) {
241
+ return styleKmlFragments;
242
+ }
243
+ exports.generateFormStyles = generateFormStyles;
244
+ function generateObservationStyles(event, icons) {
186
245
  const formStyles = event.forms.map(form => {
187
- return this.generateFormStyles(event, form, icons.filter(icon => icon.formId === form._id));
246
+ return generateFormStyles(event, form, icons.filter(icon => icon.formId === form._id));
188
247
  });
189
- return [this.generateEventStyle(event, icons), ...formStyles].join("");
190
- };
191
- KmlWriter.prototype.generateObservationPlacemark = function (observation, event) {
192
- const forms = event.formMap;
248
+ return [generateEventStyle(event, icons), ...formStyles].join('');
249
+ }
250
+ exports.generateObservationStyles = generateObservationStyles;
251
+ function generateObservationPlacemark(observation, event) {
193
252
  const names = [];
194
- const firstForm = (observation.properties.forms && observation.properties.forms.length) ? observation.properties.forms[0] : null;
195
- if (firstForm) {
196
- const form = event.formMap[firstForm.formId];
197
- if (firstForm[form.primaryFeedField]) {
198
- names.push(firstForm[form.primaryFeedField]);
253
+ const firstFormEntry = (observation.properties.forms && observation.properties.forms.length) ? observation.properties.forms[0] : null;
254
+ if (firstFormEntry) {
255
+ const form = event.formFor(firstFormEntry.formId);
256
+ if ((form === null || form === void 0 ? void 0 : form.primaryFeedField) && firstFormEntry[form.primaryFeedField]) {
257
+ names.push(firstFormEntry[form.primaryFeedField]);
199
258
  }
200
- if (firstForm[form.secondaryFeedField]) {
201
- names.push(firstForm[form.secondaryFeedField]);
259
+ if ((form === null || form === void 0 ? void 0 : form.secondaryFeedField) && firstFormEntry[form === null || form === void 0 ? void 0 : form.secondaryFeedField]) {
260
+ names.push(firstFormEntry[form.secondaryFeedField]);
202
261
  }
203
262
  }
204
- let sections = [];
205
- if (observation.properties.forms) {
206
- sections = observation.properties.forms.map(observationForm => {
207
- const form = forms[observationForm.formId];
208
- const properties = form.fields
209
- .filter(field => !field.archived && field.type !== 'password' && field.type !== 'geometry')
210
- .filter(field => {
211
- let hasValue = false;
212
- switch (field.type) {
213
- case 'attachment': {
214
- hasValue = observation.attachments.some(attachment => {
215
- return attachment.fieldName === field.name &&
216
- attachment.observationFormId.toString() === observationForm._id.toString();
217
- });
218
- break;
219
- }
220
- case 'checkbox': {
221
- hasValue = field.value != null;
222
- }
223
- default: {
224
- hasValue = observationForm[field.name];
225
- }
226
- }
227
- return hasValue;
228
- })
229
- .sort((a, b) => a.id - b.id)
230
- .map(field => {
231
- let value = observationForm[field.name];
232
- if (field.type === 'attachment') {
233
- value = observation.attachments.filter(attachment => {
263
+ const formEntries = observation.properties.forms;
264
+ const sections = formEntries.reduce((sections, formEntry) => {
265
+ const form = event.formFor(formEntry.formId);
266
+ if (!form) {
267
+ return sections;
268
+ }
269
+ const properties = form.fields
270
+ .filter(field => !field.archived && field.type !== 'password' && field.type !== 'geometry')
271
+ .filter(field => {
272
+ let hasValue = false;
273
+ switch (field.type) {
274
+ case 'attachment':
275
+ hasValue = observation.attachments.some(attachment => {
234
276
  return attachment.fieldName === field.name &&
235
- attachment.observationFormId.toString() === observationForm._id.toString();
277
+ attachment.observationFormId.toString() === formEntry._id.toString();
236
278
  });
237
- }
238
- return {
239
- key: field.title,
240
- type: field.type,
241
- value: value
242
- };
243
- });
279
+ break;
280
+ case 'checkbox':
281
+ hasValue = field.value != null;
282
+ break;
283
+ default:
284
+ hasValue = !!formEntry[field.name];
285
+ }
286
+ return hasValue;
287
+ })
288
+ .sort((a, b) => a.id - b.id)
289
+ .map(field => {
290
+ let value = formEntry[field.name];
291
+ if (field.type === 'attachment') {
292
+ value = observation.attachments.filter(attachment => {
293
+ return attachment.fieldName === field.name &&
294
+ attachment.observationFormId.toString() === formEntry._id.toString();
295
+ });
296
+ }
244
297
  return {
245
- title: form.name,
246
- properties: properties
298
+ key: field.title,
299
+ type: field.type,
300
+ value: value
247
301
  };
248
302
  });
249
- }
303
+ return [
304
+ ...sections,
305
+ {
306
+ title: form.name,
307
+ properties: properties
308
+ }
309
+ ];
310
+ }, []);
250
311
  const gpsProperties = [];
251
312
  const { provider, accuracy } = observation.properties;
252
313
  if (provider)
@@ -256,32 +317,35 @@ KmlWriter.prototype.generateObservationPlacemark = function (observation, event)
256
317
  if (gpsProperties.length) {
257
318
  sections.push({ title: 'GPS', properties: gpsProperties });
258
319
  }
259
- const styles = [event._id.toString()];
260
- if (firstForm) {
261
- const form = forms[observation.properties.forms[0].formId];
262
- styles.push(form._id.toString());
263
- if (firstForm[form.primaryField]) {
264
- styles.push(firstForm[form.primaryField]);
265
- if (firstForm[form.secondaryField]) {
266
- styles.push(firstForm[form.secondaryField]);
320
+ const styles = [String(event.id)];
321
+ if (firstFormEntry) {
322
+ const form = event.formFor(firstFormEntry.formId);
323
+ if (form) {
324
+ styles.push(String(form.id));
325
+ if (form.primaryField && firstFormEntry[form.primaryField]) {
326
+ styles.push(String(firstFormEntry[form.primaryField]));
327
+ if (form.variantField && firstFormEntry[form.variantField]) {
328
+ styles.push(String(firstFormEntry[form.variantField]));
329
+ }
267
330
  }
268
331
  }
269
332
  }
270
- const coordinates = this.generatePlacemarkCoordinates(observation);
271
- const description = this.generateDescription(observation, sections, observation.attachments);
333
+ const coordinates = generatePlacemarkCoordinates(observation);
334
+ const description = generateDescription(observation, sections);
272
335
  const placemark = {
273
336
  name: names.length ? names.join(' - ') : event.name,
274
337
  visibility: 0,
275
338
  styleUrl: '#' + styles.join('-'),
276
339
  TimeStamp: {
277
- when: moment(observation.properties.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z'
340
+ when: (0, moment_1.default)(observation.properties.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z'
278
341
  }
279
342
  };
280
- return fragment({
343
+ return (0, xmlbuilder2_1.fragment)({
281
344
  Placemark: Object.assign(Object.assign(Object.assign({}, placemark), coordinates), description)
282
345
  }).end();
283
- };
284
- KmlWriter.prototype.generateLocationPlacemark = function (user, location) {
346
+ }
347
+ exports.generateObservationPlacemark = generateObservationPlacemark;
348
+ function generateLocationPlacemark(user, location) {
285
349
  const properties = Object.entries(location.properties).map(([key, value]) => {
286
350
  return {
287
351
  key,
@@ -291,41 +355,50 @@ KmlWriter.prototype.generateLocationPlacemark = function (user, location) {
291
355
  const sections = [{
292
356
  properties: properties
293
357
  }];
294
- const coordinates = this.generatePlacemarkCoordinates(location);
295
- const description = this.generateDescription(location, sections);
358
+ const coordinates = generatePlacemarkCoordinates(location);
359
+ const description = generateDescription(location, sections);
296
360
  const placemark = {
297
- name: moment(location.properties.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z',
361
+ name: (0, moment_1.default)(location.properties.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z',
298
362
  visibility: 0,
299
363
  styleUrl: '#user-' + user._id.toString(),
300
364
  TimeStamp: {
301
- when: moment(location.properties.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z'
365
+ when: (0, moment_1.default)(location.properties.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z'
302
366
  }
303
367
  };
304
- return fragment({
368
+ return (0, xmlbuilder2_1.fragment)({
305
369
  Placemark: Object.assign(Object.assign(Object.assign({}, placemark), coordinates), description)
306
370
  }).end();
307
- };
308
- KmlWriter.prototype.generateKMLDocumentClose = function () {
309
- return "</Document>";
310
- };
311
- KmlWriter.prototype.generateKMLFolderClose = function () {
312
- return "</Folder>";
313
- };
314
- KmlWriter.prototype.generateKMLClose = function () {
315
- return "</kml>";
316
- };
317
- KmlWriter.prototype.generateDescription = function (geojson, sections) {
318
- const centroid = turfCentroid(geojson);
371
+ }
372
+ exports.generateLocationPlacemark = generateLocationPlacemark;
373
+ function generateKMLDocumentClose() {
374
+ return '</Document>';
375
+ }
376
+ exports.generateKMLDocumentClose = generateKMLDocumentClose;
377
+ function generateKMLFolderClose() {
378
+ return '</Folder>';
379
+ }
380
+ exports.generateKMLFolderClose = generateKMLFolderClose;
381
+ function generateKMLClose() {
382
+ return '</kml>';
383
+ }
384
+ exports.generateKMLClose = generateKMLClose;
385
+ function generateDescription(feature, sections) {
386
+ const centroid = (0, centroid_1.default)(feature);
319
387
  const header = [{
320
- section: [{
321
- span: [{ label: 'Timestamp' }, moment(geojson.properties.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z']
322
- }, {
388
+ section: [
389
+ {
390
+ span: [{ label: 'Timestamp' }, (0, moment_1.default)(feature.properties.timestamp).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z']
391
+ },
392
+ {
323
393
  span: [{ label: 'Latitude' }, centroid.geometry.coordinates[1]]
324
- }, {
394
+ },
395
+ {
325
396
  span: [{ label: 'Longitude' }, centroid.geometry.coordinates[0]]
326
- }, {
397
+ },
398
+ {
327
399
  span: [{ label: 'MGRS' }, mgrs.forward(centroid.geometry.coordinates)]
328
- }]
400
+ }
401
+ ]
329
402
  }];
330
403
  const properties = [];
331
404
  sections.forEach(section => {
@@ -334,12 +407,12 @@ KmlWriter.prototype.generateDescription = function (geojson, sections) {
334
407
  h4: section.title
335
408
  });
336
409
  }
337
- section.properties.forEach(property => {
410
+ section.properties.forEach((property) => {
338
411
  if (property.type === 'attachment') {
339
412
  properties.push({
340
413
  span: { label: property.key }
341
414
  });
342
- property.value.forEach(attachment => {
415
+ property.value.forEach((attachment) => {
343
416
  const group = [];
344
417
  group.push({
345
418
  a: {
@@ -372,7 +445,7 @@ KmlWriter.prototype.generateDescription = function (geojson, sections) {
372
445
  };
373
446
  return {
374
447
  description: {
375
- '$': fragment({
448
+ $: (0, xmlbuilder2_1.fragment)({
376
449
  html: {
377
450
  head: {
378
451
  style: {
@@ -385,18 +458,19 @@ KmlWriter.prototype.generateDescription = function (geojson, sections) {
385
458
  }).end()
386
459
  }
387
460
  };
388
- };
389
- KmlWriter.prototype.generatePlacemarkCoordinates = function (geojson) {
390
- if (geojson.geometry.type === 'Point') {
461
+ }
462
+ exports.generateDescription = generateDescription;
463
+ function generatePlacemarkCoordinates(feature) {
464
+ if (feature.geometry.type === 'Point') {
391
465
  return {
392
466
  Point: {
393
- coordinates: geojson.geometry.coordinates.join(',')
467
+ coordinates: feature.geometry.coordinates.join(',')
394
468
  }
395
469
  };
396
470
  }
397
- else if (geojson.geometry.type === 'Polygon') {
471
+ else if (feature.geometry.type === 'Polygon') {
398
472
  // Ignore holes, no holes in MAGE observations
399
- const coordinates = geojson.geometry.coordinates[0].reduce((coordinates, points) => {
473
+ const coordinates = feature.geometry.coordinates[0].reduce((coordinates, points) => {
400
474
  return coordinates.concat(points.join(','));
401
475
  }, []);
402
476
  return {
@@ -410,8 +484,8 @@ KmlWriter.prototype.generatePlacemarkCoordinates = function (geojson) {
410
484
  }
411
485
  };
412
486
  }
413
- else if (geojson.geometry.type === 'LineString') {
414
- const coordinates = geojson.geometry.coordinates.reduce((coordinates, points) => {
487
+ else if (feature.geometry.type === 'LineString') {
488
+ const coordinates = feature.geometry.coordinates.reduce((coordinates, points) => {
415
489
  return coordinates.concat(points.join(','));
416
490
  }, []);
417
491
  return {
@@ -423,9 +497,12 @@ KmlWriter.prototype.generatePlacemarkCoordinates = function (geojson) {
423
497
  }
424
498
  };
425
499
  }
426
- return coordinates;
427
- };
428
- KmlWriter.prototype.getFieldByName = function (form, name) {
500
+ // TODO: not sure if this ever happens or what will happen if it does ¯\_(ツ)_/¯
501
+ return {};
502
+ }
503
+ exports.generatePlacemarkCoordinates = generatePlacemarkCoordinates;
504
+ function getFieldByName(form, name) {
429
505
  return form.fields.find(field => field.name === name);
430
- };
506
+ }
507
+ exports.getFieldByName = getFieldByName;
431
508
  //# sourceMappingURL=kmlWriter.js.map