Robustify code

This commit is contained in:
Pieter Vander Vennet 2021-11-09 23:44:20 +01:00
parent 1dbe167e4e
commit 15a1ab19cd
2 changed files with 19 additions and 20 deletions

View file

@ -54,12 +54,14 @@ export default class RenderingMultiPlexerFeatureSource {
})
}
} else {
// This is a a line
// This is a a line: add the centroids
for (const rendering of centroidRenderings) {
addAsPoint(feat, rendering, GeoOperations.centerpointCoordinates(feat))
}
if (feat.geometry.type === "LineString" || feat.geometry.type==="Polygon" || feat.geometry.type === "MultiPolygon") {
if (feat.geometry.type === "LineString") {
// Add start- and endpoints
const coordinates = feat.geometry.coordinates
for (const rendering of startRenderings) {
addAsPoint(feat, rendering, coordinates[0])
@ -68,29 +70,17 @@ export default class RenderingMultiPlexerFeatureSource {
const coordinate = coordinates[coordinates.length - 1]
addAsPoint(feat, rendering, coordinate)
}
for (let i = 0; i < lineRenderObjects.length; i++) {
withIndex.push({
...feat,
lineRenderingIndex: i
})
}
}
if (feat.geometry.type === "MultiLineString") {
// Multilinestrings get a special treatment: we split them into their subparts before rendering
const lineList: [number, number][][] = feat.geometry.coordinates
for (let i1 = 0; i1 < lineList.length; i1++) {
const coordinates = lineList[i1];
for (const rendering of startRenderings) {
const coordinate = coordinates[0]
addAsPoint(feat, rendering, coordinate)
}
for (const rendering of endRenderings) {
const coordinate = coordinates[coordinates.length - 1]
addAsPoint(feat, rendering, coordinate)
}
for (let i = 0; i < lineRenderObjects.length; i++) {
const orig = {
...feat,
@ -102,8 +92,19 @@ export default class RenderingMultiPlexerFeatureSource {
withIndex.push(orig)
}
}
}else{
// AT last, add it 'as is' to what we should render
for (let i = 0; i < lineRenderObjects.length; i++) {
withIndex.push({
...feat,
lineRenderingIndex: i
})
}
}
}
}

View file

@ -157,7 +157,6 @@ export default class ShowDataLayer {
const coords = L.GeoJSON.coordsToLatLngs(feat.geometry.coordinates)
const tagsSource = this.allElements?.addOrGetElement(feat) ?? new UIEventSource<any>(feat.properties);
let offsettedLine;
console.log("Rendering ", feat)
tagsSource
.map(tags => this._layerToShow.lineRendering[feat.lineRenderingIndex].GenerateLeafletStyle(tags))
.withEqualityStabilized((a, b) => {
@ -170,7 +169,6 @@ export default class ShowDataLayer {
return a.offset === b.offset && a.color === b.color && a.weight === b.weight && a.dashArray === b.dashArray
})
.addCallbackAndRunD(lineStyle => {
console.log("Linestyle is ", lineStyle)
if (offsettedLine !== undefined) {
self.geoLayer.removeLayer(offsettedLine)
}