Handle LandXML CgPoints

This commit is contained in:
wpetit 2021-01-22 15:56:02 +01:00
parent 4a4a26c2bd
commit 988ec50368
8 changed files with 122 additions and 18 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -123,7 +123,7 @@
} }
}, },
onEachFeature: (f, l) => { onEachFeature: (f, l) => {
l.bringToBack(); if(f.geometry.type !== 'Point') l.bringToBack();
} }
}).on('click', (e) => { }).on('click', (e) => {
// Check for selected // Check for selected
@ -138,19 +138,56 @@
console.log('Selected feature:', feature); console.log('Selected feature:', feature);
// Bring selected to front if(feature.geometry.type !== 'Point') {
//selectedFeature.bringToFront()
// Style selected // Style selected
selectedFeature.setStyle({ selectedFeature.setStyle({
'fillColor': 'blue' 'fillColor': 'blue'
}) })
}
selectedFeature.bindPopup(featurePropertiesToHTML(feature)).openPopup();
selectedFeature.bindPopup(`<b>${feature.properties.name}</b><br>${feature.properties.description}`).openPopup();
}).addTo(map); }).addTo(map);
const bounds = geojsonLayer.getBounds(); const bounds = geojsonLayer.getBounds();
map.fitBounds(bounds); map.fitBounds(bounds);
} }
function featurePropertiesToHTML(feature) {
let html = `<b>${feature.properties.name}</b><br /><br />`;
if (feature.geometry.type === "Point") {
html += `
<ul>
<li><b>Latitude</b> ${feature.geometry.coordinates[1]}°</li>
<li><b>Longitude</b> ${feature.geometry.coordinates[0]}°</li>
<li><b>Altitude</b> ${feature.geometry.coordinates[2]}m</li>
</ul>
<br />
`;
}
html += `
<b>Propriétés</b><br/><br/>
<table>
<thead>
<tr>
<th>Clé</th>
<th>Valeur</th>
</tr>
<thead>
<tbody>
`;
Object.keys(feature.properties).sort().forEach(key => {
html += `
<tr>
<td>${key}</td>
<td>${feature.properties[key]}</td>
</tr>
`;
});
html += `
</tbody>
<table/>
`;
return html;
}
}()); }());

64
lib/cg-point.js Normal file
View File

@ -0,0 +1,64 @@
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,
}
};
}

View File

@ -1,8 +1,8 @@
/// #if target == 'native' /// #if target == 'native'
import xml2js from 'react-native-xml2js'; import xml2js from 'react-native-xml2js';
/// #else /// #else
import xml2js from 'xml2js'; import xml2js from 'xml2js';
/// #endif /// #endif
import { featureCollection } from '@turf/helpers'; import { featureCollection } from '@turf/helpers';
@ -14,16 +14,19 @@ import { getProp } from './util';
import { convertSurfaces } from './surface'; import { convertSurfaces } from './surface';
import { convertParcels } from './parcel'; import { convertParcels } from './parcel';
import { convertPipeNetworks } from './pipe-network'; import { convertPipeNetworks } from './pipe-network';
import { convertCGPoints } from './cg-point';
export const PROJECTION_AUTO_DETECT = 'auto_detect'; export const PROJECTION_AUTO_DETECT = 'auto_detect';
export const CONVERT_SURFACES = 'surfaces'; export const CONVERT_SURFACES = 'surfaces';
export const CONVERT_PARCELS = 'parcels'; export const CONVERT_PARCELS = 'parcels';
export const CONVERT_PIPE_NETWORKS = 'pipe_networks'; export const CONVERT_PIPE_NETWORKS = 'pipe_networks';
export const CONVERT_CG_POINTS = 'cg_points';
const converters = { const converters = {
[CONVERT_PARCELS]: convertParcels, [CONVERT_PARCELS]: convertParcels,
[CONVERT_SURFACES]: convertSurfaces, [CONVERT_SURFACES]: convertSurfaces,
[CONVERT_PIPE_NETWORKS]: convertPipeNetworks, [CONVERT_PIPE_NETWORKS]: convertPipeNetworks,
[CONVERT_CG_POINTS]: convertCGPoints,
} }
// Based on alexgleith's preliminary work // Based on alexgleith's preliminary work
@ -32,7 +35,7 @@ export class Converter {
defaultOptions = { defaultOptions = {
projection: PROJECTION_AUTO_DETECT, projection: PROJECTION_AUTO_DETECT,
enabledConverters: [ CONVERT_SURFACES, CONVERT_PARCELS, CONVERT_PIPE_NETWORKS ], enabledConverters: [ CONVERT_SURFACES, CONVERT_PARCELS, CONVERT_PIPE_NETWORKS, CONVERT_CG_POINTS ],
parser: { parser: {
normalize: true normalize: true
}, },