@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.
- package/lib/@types/express/index.d.ts +1 -1
- package/lib/adapters/icons/adapters.icons.db.mongoose.js.map +1 -1
- package/lib/adapters/observations/adapters.observations.controllers.web.js +2 -2
- package/lib/adapters/observations/adapters.observations.controllers.web.js.map +1 -1
- package/lib/adapters/observations/adapters.observations.dto.ecma404-json.d.ts +1 -1
- package/lib/adapters/observations/adapters.observations.dto.ecma404-json.js +1 -1
- package/lib/api/attachment.d.ts +3 -0
- package/lib/api/attachment.d.ts.map +1 -1
- package/lib/api/attachment.js +3 -0
- package/lib/api/attachment.js.map +1 -1
- package/lib/api/icon.d.ts +51 -20
- package/lib/api/icon.js +1 -1
- package/lib/api/icon.js.map +1 -1
- package/lib/api/location.d.ts +1 -3
- package/lib/api/location.d.ts.map +1 -1
- package/lib/app.api/observations/app.api.observations.js +1 -1
- package/lib/app.api/observations/app.api.observations.js.map +1 -1
- package/lib/app.d.ts +2 -2
- package/lib/app.d.ts.map +1 -1
- package/lib/app.impl/observations/app.impl.observations.d.ts.map +1 -1
- package/lib/app.impl/observations/app.impl.observations.js +2 -1
- package/lib/app.impl/observations/app.impl.observations.js.map +1 -1
- package/lib/app.js +5 -3
- package/lib/app.js.map +1 -1
- package/lib/authentication/saml.d.ts.map +1 -1
- package/lib/authentication/saml.js +15 -14
- package/lib/authentication/saml.js.map +1 -1
- package/lib/dist-package.json +45 -45
- package/lib/docs/auth/local.yaml +1 -2
- package/lib/entities/authorization/entities.permissions.d.ts +7 -1
- package/lib/entities/authorization/entities.permissions.d.ts.map +1 -1
- package/lib/entities/authorization/entities.permissions.js +7 -2
- package/lib/entities/authorization/entities.permissions.js.map +1 -1
- package/lib/entities/entities.global.d.ts +6 -0
- package/lib/entities/entities.global.d.ts.map +1 -1
- package/lib/entities/entities.global.js +12 -1
- package/lib/entities/entities.global.js.map +1 -1
- package/lib/entities/events/entities.events.d.ts.map +1 -1
- package/lib/entities/events/entities.events.forms.d.ts +9 -1
- package/lib/entities/events/entities.events.forms.d.ts.map +1 -1
- package/lib/entities/events/entities.events.forms.js +24 -3
- package/lib/entities/events/entities.events.forms.js.map +1 -1
- package/lib/entities/events/entities.events.js.map +1 -1
- package/lib/entities/locations/entities.locations.d.ts +30 -0
- package/lib/entities/locations/entities.locations.d.ts.map +1 -0
- package/lib/entities/locations/entities.locations.js +3 -0
- package/lib/entities/locations/entities.locations.js.map +1 -0
- package/lib/entities/observations/entities.observations.d.ts +4 -4
- package/lib/entities/observations/entities.observations.d.ts.map +1 -1
- package/lib/entities/observations/entities.observations.js +16 -15
- package/lib/entities/observations/entities.observations.js.map +1 -1
- package/lib/environment/env.js +1 -1
- package/lib/environment/env.js.map +1 -1
- package/lib/export/csv.d.ts +19 -9
- package/lib/export/csv.d.ts.map +1 -1
- package/lib/export/csv.js +254 -231
- package/lib/export/csv.js.map +1 -1
- package/lib/export/exporter.d.ts +37 -10
- package/lib/export/exporter.d.ts.map +1 -1
- package/lib/export/exporter.js +67 -35
- package/lib/export/exporter.js.map +1 -1
- package/lib/export/geojson.d.ts +9 -8
- package/lib/export/geojson.d.ts.map +1 -1
- package/lib/export/geojson.js +162 -143
- package/lib/export/geojson.js.map +1 -1
- package/lib/export/geopackage.d.ts +29 -23
- package/lib/export/geopackage.d.ts.map +1 -1
- package/lib/export/geopackage.js +657 -589
- package/lib/export/geopackage.js.map +1 -1
- package/lib/export/index.d.ts +17 -0
- package/lib/export/index.d.ts.map +1 -0
- package/lib/export/index.js +28 -0
- package/lib/export/index.js.map +1 -0
- package/lib/export/kml.d.ts +11 -8
- package/lib/export/kml.d.ts.map +1 -1
- package/lib/export/kml.js +152 -106
- package/lib/export/kml.js.map +1 -1
- package/lib/export/kmlWriter.d.ts +23 -22
- package/lib/export/kmlWriter.d.ts.map +1 -1
- package/lib/export/kmlWriter.js +258 -181
- package/lib/export/kmlWriter.js.map +1 -1
- package/lib/express.js +2 -4
- package/lib/express.js.map +1 -1
- package/lib/migrations/030-saml-settings.d.ts +4 -0
- package/lib/migrations/030-saml-settings.d.ts.map +1 -0
- package/lib/migrations/030-saml-settings.js +96 -0
- package/lib/migrations/030-saml-settings.js.map +1 -0
- package/lib/models/authentication.js +1 -1
- package/lib/models/authenticationconfiguration.js +0 -1
- package/lib/models/authenticationconfiguration.js.map +1 -1
- package/lib/models/event.d.ts +4 -2
- package/lib/models/event.js +1 -1
- package/lib/models/event.js.map +1 -1
- package/lib/models/export.d.ts +56 -17
- package/lib/models/export.d.ts.map +1 -1
- package/lib/models/export.js.map +1 -1
- package/lib/models/icon.d.ts +24 -9
- package/lib/models/icon.d.ts.map +1 -1
- package/lib/models/icon.js +3 -6
- package/lib/models/icon.js.map +1 -1
- package/lib/models/location.d.ts +40 -8
- package/lib/models/location.d.ts.map +1 -1
- package/lib/models/location.js +2 -0
- package/lib/models/location.js.map +1 -1
- package/lib/models/observation.d.ts +27 -0
- package/lib/models/observation.js.map +1 -1
- package/lib/models/user.d.ts +3 -0
- package/lib/models/user.js +1 -1
- package/lib/provision/index.js +1 -1
- package/lib/provision/index.js.map +1 -1
- package/lib/routes/authenticationconfigurations.d.ts.map +1 -1
- package/lib/routes/authenticationconfigurations.js +4 -5
- package/lib/routes/authenticationconfigurations.js.map +1 -1
- package/lib/routes/events.d.ts.map +1 -1
- package/lib/routes/events.js +19 -10
- package/lib/routes/events.js.map +1 -1
- package/lib/routes/exports.d.ts +3 -2
- package/lib/routes/exports.d.ts.map +1 -1
- package/lib/routes/exports.js +121 -79
- package/lib/routes/exports.js.map +1 -1
- package/lib/routes/imports.d.ts.map +1 -1
- package/lib/routes/imports.js +4 -2
- package/lib/routes/imports.js.map +1 -1
- package/lib/routes/layers.d.ts.map +1 -1
- package/lib/routes/layers.js +11 -45
- package/lib/routes/layers.js.map +1 -1
- package/lib/routes/locations.d.ts.map +1 -1
- package/lib/routes/locations.js +7 -3
- package/lib/routes/locations.js.map +1 -1
- package/lib/routes/routes.types.d.ts +9 -0
- package/lib/routes/setup.js +1 -1
- package/lib/routes/setup.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/npm-shrinkwrap.json +4411 -7493
- package/package.json +45 -45
- package/lib/export/exporterFactory.d.ts +0 -11
- package/lib/export/exporterFactory.d.ts.map +0 -1
- package/lib/export/exporterFactory.js +0 -17
- package/lib/export/exporterFactory.js.map +0 -1
package/lib/export/kmlWriter.js
CHANGED
|
@@ -1,20 +1,73 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
r: result[1],
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
39
|
+
function hexStringForInt(integer) {
|
|
14
40
|
const str = Number(integer).toString(16);
|
|
15
41
|
return str.length === 1 ? "0" + str : str;
|
|
16
42
|
}
|
|
17
|
-
|
|
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
|
-
|
|
79
|
+
}
|
|
80
|
+
exports.generateKMLDocument = generateKMLDocument;
|
|
81
|
+
function generateKMLFolderStart(name) {
|
|
28
82
|
return `<Folder><name>${name}</name>`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
83
|
+
}
|
|
84
|
+
exports.generateKMLFolderStart = generateKMLFolderStart;
|
|
85
|
+
function generateUserStyle(user) {
|
|
32
86
|
if (user.icon && user.icon.relativePath) {
|
|
33
|
-
|
|
87
|
+
return (0, xmlbuilder2_1.fragment)({
|
|
34
88
|
Style: {
|
|
35
89
|
'@id': `user-${user._id.toString()}`,
|
|
36
90
|
IconStyle: {
|
|
37
91
|
Icon: {
|
|
38
|
-
href:
|
|
92
|
+
href: path_1.default.join('icons/users', user._id.toString())
|
|
39
93
|
}
|
|
40
94
|
}
|
|
41
95
|
}
|
|
42
96
|
}).end();
|
|
43
97
|
}
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
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 =
|
|
49
|
-
const fillParts =
|
|
50
|
-
const strokeOpacity =
|
|
51
|
-
const fillOpacity =
|
|
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
|
|
109
|
+
'@id': String(event._id),
|
|
55
110
|
IconStyle: {
|
|
56
111
|
Icon: {
|
|
57
|
-
href:
|
|
112
|
+
href: path_1.default.join('icons', defaultIcon.relativePath)
|
|
58
113
|
}
|
|
59
114
|
},
|
|
60
115
|
LineStyle: {
|
|
61
116
|
width: event.style.strokeWidth,
|
|
62
|
-
color:
|
|
117
|
+
color: kmlColor(strokeParts, strokeOpacity)
|
|
63
118
|
},
|
|
64
119
|
PolyStyle: {
|
|
65
|
-
color:
|
|
120
|
+
color: kmlColor(fillParts, fillOpacity)
|
|
66
121
|
}
|
|
67
122
|
}
|
|
68
123
|
}).end();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
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 =
|
|
78
|
-
let fillParts =
|
|
79
|
-
let strokeOpacity =
|
|
80
|
-
let fillOpacity =
|
|
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
|
|
150
|
+
const defaultStyleKml = (0, xmlbuilder2_1.fragment)({
|
|
95
151
|
Style: {
|
|
96
|
-
'@id':
|
|
152
|
+
'@id': `${event._id}-${form._id}`,
|
|
97
153
|
IconStyle: {
|
|
98
154
|
Icon: {
|
|
99
|
-
href:
|
|
155
|
+
href: path_1.default.join('icons', defaultIconPath)
|
|
100
156
|
}
|
|
101
157
|
},
|
|
102
158
|
LineStyle: {
|
|
103
159
|
width: strokeWidth,
|
|
104
|
-
color:
|
|
160
|
+
color: kmlColor(strokeParts, strokeOpacity)
|
|
105
161
|
},
|
|
106
162
|
PolyStyle: {
|
|
107
|
-
color:
|
|
163
|
+
color: kmlColor(fillParts, fillOpacity)
|
|
108
164
|
}
|
|
109
165
|
}
|
|
110
166
|
}).end();
|
|
111
|
-
|
|
112
|
-
const 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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
|
180
|
+
const primaryStyleKml = (0, xmlbuilder2_1.fragment)({
|
|
124
181
|
Style: {
|
|
125
|
-
'@id':
|
|
182
|
+
'@id': `${event._id}-${form._id.toString()}-${choice.title}`,
|
|
126
183
|
IconStyle: {
|
|
127
184
|
Icon: {
|
|
128
|
-
href:
|
|
185
|
+
href: path_1.default.join('icons', iconPath)
|
|
129
186
|
}
|
|
130
187
|
},
|
|
131
188
|
LineStyle: {
|
|
132
189
|
width: strokeWidth,
|
|
133
|
-
color:
|
|
190
|
+
color: kmlColor(strokeParts, strokeOpacity)
|
|
134
191
|
},
|
|
135
192
|
PolyStyle: {
|
|
136
|
-
color:
|
|
193
|
+
color: kmlColor(fillParts, fillOpacity)
|
|
137
194
|
}
|
|
138
195
|
}
|
|
139
196
|
}).end();
|
|
140
|
-
|
|
197
|
+
styleKmlFragments.push(primaryStyleKml);
|
|
141
198
|
// secondary styles for each type
|
|
142
|
-
const secondaryField =
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
|
219
|
+
const variantStyleKml = (0, xmlbuilder2_1.fragment)({
|
|
162
220
|
Style: {
|
|
163
|
-
'@id':
|
|
221
|
+
'@id': `${event._id}-${form._id.toString()}-${choice.title}-${secondaryChoice.title}`,
|
|
164
222
|
IconStyle: {
|
|
165
223
|
Icon: {
|
|
166
|
-
href:
|
|
224
|
+
href: path_1.default.join('icons', iconPath)
|
|
167
225
|
}
|
|
168
226
|
},
|
|
169
227
|
LineStyle: {
|
|
170
228
|
width: strokeWidth,
|
|
171
|
-
color:
|
|
229
|
+
color: kmlColor(strokeParts, strokeOpacity)
|
|
172
230
|
},
|
|
173
231
|
PolyStyle: {
|
|
174
|
-
color:
|
|
232
|
+
color: kmlColor(fillParts, fillOpacity)
|
|
175
233
|
}
|
|
176
234
|
}
|
|
177
235
|
}).end();
|
|
178
|
-
|
|
236
|
+
styleKmlFragments.push(variantStyleKml);
|
|
179
237
|
});
|
|
180
238
|
}
|
|
181
239
|
});
|
|
182
240
|
}
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
|
|
241
|
+
return styleKmlFragments;
|
|
242
|
+
}
|
|
243
|
+
exports.generateFormStyles = generateFormStyles;
|
|
244
|
+
function generateObservationStyles(event, icons) {
|
|
186
245
|
const formStyles = event.forms.map(form => {
|
|
187
|
-
return
|
|
246
|
+
return generateFormStyles(event, form, icons.filter(icon => icon.formId === form._id));
|
|
188
247
|
});
|
|
189
|
-
return [
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
248
|
+
return [generateEventStyle(event, icons), ...formStyles].join('');
|
|
249
|
+
}
|
|
250
|
+
exports.generateObservationStyles = generateObservationStyles;
|
|
251
|
+
function generateObservationPlacemark(observation, event) {
|
|
193
252
|
const names = [];
|
|
194
|
-
const
|
|
195
|
-
if (
|
|
196
|
-
const form = event.
|
|
197
|
-
if (
|
|
198
|
-
names.push(
|
|
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 (
|
|
201
|
-
names.push(
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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() ===
|
|
277
|
+
attachment.observationFormId.toString() === formEntry._id.toString();
|
|
236
278
|
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
|
|
246
|
-
|
|
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.
|
|
260
|
-
if (
|
|
261
|
-
const form =
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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 =
|
|
271
|
-
const description =
|
|
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:
|
|
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
|
-
|
|
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 =
|
|
295
|
-
const description =
|
|
358
|
+
const coordinates = generatePlacemarkCoordinates(location);
|
|
359
|
+
const description = generateDescription(location, sections);
|
|
296
360
|
const placemark = {
|
|
297
|
-
name:
|
|
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:
|
|
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
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
390
|
-
|
|
461
|
+
}
|
|
462
|
+
exports.generateDescription = generateDescription;
|
|
463
|
+
function generatePlacemarkCoordinates(feature) {
|
|
464
|
+
if (feature.geometry.type === 'Point') {
|
|
391
465
|
return {
|
|
392
466
|
Point: {
|
|
393
|
-
coordinates:
|
|
467
|
+
coordinates: feature.geometry.coordinates.join(',')
|
|
394
468
|
}
|
|
395
469
|
};
|
|
396
470
|
}
|
|
397
|
-
else if (
|
|
471
|
+
else if (feature.geometry.type === 'Polygon') {
|
|
398
472
|
// Ignore holes, no holes in MAGE observations
|
|
399
|
-
const coordinates =
|
|
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 (
|
|
414
|
-
const coordinates =
|
|
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
|
-
|
|
427
|
-
};
|
|
428
|
-
|
|
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
|