Handle LandXML CgPoints
This commit is contained in:
parent
4a4a26c2bd
commit
988ec50368
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
|
@ -123,7 +123,7 @@
|
|||
}
|
||||
},
|
||||
onEachFeature: (f, l) => {
|
||||
l.bringToBack();
|
||||
if(f.geometry.type !== 'Point') l.bringToBack();
|
||||
}
|
||||
}).on('click', (e) => {
|
||||
// Check for selected
|
||||
|
@ -138,19 +138,56 @@
|
|||
|
||||
console.log('Selected feature:', feature);
|
||||
|
||||
// Bring selected to front
|
||||
//selectedFeature.bringToFront()
|
||||
// Style selected
|
||||
selectedFeature.setStyle({
|
||||
'fillColor': 'blue'
|
||||
})
|
||||
if(feature.geometry.type !== 'Point') {
|
||||
// Style selected
|
||||
selectedFeature.setStyle({
|
||||
'fillColor': 'blue'
|
||||
})
|
||||
}
|
||||
|
||||
selectedFeature.bindPopup(featurePropertiesToHTML(feature)).openPopup();
|
||||
|
||||
selectedFeature.bindPopup(`<b>${feature.properties.name}</b><br>${feature.properties.description}`).openPopup();
|
||||
}).addTo(map);
|
||||
const bounds = geojsonLayer.getBounds();
|
||||
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;
|
||||
}
|
||||
|
||||
}());
|
|
@ -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,
|
||||
}
|
||||
};
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
/// #if target == 'native'
|
||||
import xml2js from 'react-native-xml2js';
|
||||
import xml2js from 'react-native-xml2js';
|
||||
/// #else
|
||||
import xml2js from 'xml2js';
|
||||
import xml2js from 'xml2js';
|
||||
/// #endif
|
||||
|
||||
import { featureCollection } from '@turf/helpers';
|
||||
|
@ -14,16 +14,19 @@ import { getProp } from './util';
|
|||
import { convertSurfaces } from './surface';
|
||||
import { convertParcels } from './parcel';
|
||||
import { convertPipeNetworks } from './pipe-network';
|
||||
import { convertCGPoints } from './cg-point';
|
||||
|
||||
export const PROJECTION_AUTO_DETECT = 'auto_detect';
|
||||
export const CONVERT_SURFACES = 'surfaces';
|
||||
export const CONVERT_PARCELS = 'parcels';
|
||||
export const CONVERT_PIPE_NETWORKS = 'pipe_networks';
|
||||
export const CONVERT_CG_POINTS = 'cg_points';
|
||||
|
||||
const converters = {
|
||||
[CONVERT_PARCELS]: convertParcels,
|
||||
[CONVERT_SURFACES]: convertSurfaces,
|
||||
[CONVERT_PIPE_NETWORKS]: convertPipeNetworks,
|
||||
[CONVERT_CG_POINTS]: convertCGPoints,
|
||||
}
|
||||
|
||||
// Based on alexgleith's preliminary work
|
||||
|
@ -32,7 +35,7 @@ export class Converter {
|
|||
|
||||
defaultOptions = {
|
||||
projection: PROJECTION_AUTO_DETECT,
|
||||
enabledConverters: [ CONVERT_SURFACES, CONVERT_PARCELS, CONVERT_PIPE_NETWORKS ],
|
||||
enabledConverters: [ CONVERT_SURFACES, CONVERT_PARCELS, CONVERT_PIPE_NETWORKS, CONVERT_CG_POINTS ],
|
||||
parser: {
|
||||
normalize: true
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue