fixes KML/Z import

This commit is contained in:
Christian Beutel
2025-03-22 13:10:40 +01:00
parent ba212a6400
commit c03e5add5d
2 changed files with 30 additions and 14 deletions

View File

@@ -674,8 +674,8 @@ const removeSpace = /\s*/g;
const trimSpace = /^\s*|\s*$/g; const trimSpace = /^\s*|\s*$/g;
const splitSpace = /\s+/; const splitSpace = /\s+/;
/** /**
* Get one coordinate from a coordinate array, if any * Get one coordinate from a coordinate array, if any
*/ */
function coord1(value) { function coord1(value) {
return value. return value.
replace(removeSpace, ""). replace(removeSpace, "").
@@ -701,12 +701,25 @@ function gxCoords(node) {
if (elems.length === 0) { if (elems.length === 0) {
elems = $ns(node, "coord", "*"); elems = $ns(node, "coord", "*");
} }
const coordinates = elems.map(elem => { let coordinates = elems.map(elem => {
return nodeVal(elem).split(" ").map(parseFloat); return nodeVal(elem).split(" ").map(parseFloat);
}); });
if (coordinates.length === 0) { if (coordinates.length === 0) {
return null; return null;
} }
let times = $(node, "when").map(elem => nodeVal(elem));
const invalidCoordinateIndices = []
coordinates.forEach((c, i) => {
if (c.length < 2) {
invalidCoordinateIndices.push(i)
} else {
c.push(times[i])
}
})
coordinates = coordinates.filter((_, i) => !invalidCoordinateIndices.includes(i))
return { return {
geometry: coordinates.length > 2 ? geometry: coordinates.length > 2 ?
{ {
@@ -719,7 +732,7 @@ function gxCoords(node) {
coordinates: coordinates[0] coordinates: coordinates[0]
}, },
times: $(node, "when").map(elem => nodeVal(elem)) times: times
}; };
} }
@@ -848,15 +861,18 @@ function getPlacemark(node, styleMap, schema, options) {
"open", "open",
"phoneNumber", "phoneNumber",
"description"]), "description"]),
getMaybeHTMLDescription(node), extractCascadedStyle(node, styleMap), extractStyle(node), extractExtendedData(node, schema), extractTimeSpan(node), extractTimeStamp(node), coordTimes.length ? getMaybeHTMLDescription(node),
{ extractCascadedStyle(node, styleMap),
coordinateProperties: { extractStyle(node),
times: coordTimes.length === 1 ? coordTimes[0] : coordTimes extractExtendedData(node, schema),
} extractTimeSpan(node),
} : extractTimeStamp(node),
coordTimes.length ?
{
{}) coordinateProperties: {
times: coordTimes.length === 1 ? coordTimes[0] : coordTimes
}
} : {})
}; };
if (((_feature$properties = feature.properties) === null || _feature$properties === void 0 ? void 0 : _feature$properties.visibility) !== undefined) { if (((_feature$properties = feature.properties) === null || _feature$properties === void 0 ? void 0 : _feature$properties.visibility) !== undefined) {

View File

@@ -944,7 +944,7 @@
type="file" type="file"
name="gpx" name="gpx"
id="fileInput" id="fileInput"
accept=".gpx,.GPX,.tcx,.TCX,.kml,.KML,.fit,.FIT" accept=".gpx,.GPX,.tcx,.TCX,.kml,.KML,.kmz,.KMZ,.fit,.FIT"
style="display: none;" style="display: none;"
onchange={handleFileSelection} onchange={handleFileSelection}
/> />