import { getProp, parseSequence, getColor } from './util' import { polygon } from '@turf/helpers'; import union from '@turf/union'; import proj4 from 'proj4'; export const LANDXML_POINT = 'cg_point'; export function convertCGPoints(xmlObj, projection, opts) { const features = []; const pointsContainerNodes = getProp(xmlObj, "LandXML", "CgPoints"); if (!pointsContainerNodes) return features; pointsContainerNodes.forEach(pc => { const attrs = (pc.$ || {}); const baseProps = { name: attrs.name || "", description: attrs.description || "", }; const pointNodes = getProp(pc, "CgPoint"); if (!Array.isArray(pointNodes)) return; pointNodes.forEach(p => { const name = baseProps.name ? ( baseProps.name + ' - ' + p.$.name ) : p.$.name; const description = baseProps.description ? ( baseProps.description + ' - ' + p.$.desc ) : p.$.desc; const featureProps = { name: name, description: description, landxmlType: LANDXML_POINT, "stroke-width": 0, "color": "transparent", "fill": getColor(`point-${name}`, opts.colorOpts), "fill-opacity": 0.3, }; const pointFeature = convertPoint(p, projection, featureProps, opts); features.push(pointFeature) }); }); return features; } function convertPoint(cgPoint, projection, featureProps) { let pointCoords = parseSequence(cgPoint._).map(v => parseFloat(v)); pointCoords = [pointCoords[1], pointCoords[0], pointCoords[2]]; pointCoords = proj4(projection, 'WGS84', pointCoords); return { type: "Feature", geometry: { type: "Point", coordinates: [...pointCoords, pointCoords[2]], }, properties: { ...featureProps, } }; }