forked from MapComplete/MapComplete
		
	Robustify code
This commit is contained in:
		
							parent
							
								
									1dbe167e4e
								
							
						
					
					
						commit
						15a1ab19cd
					
				
					 2 changed files with 19 additions and 20 deletions
				
			
		| 
						 | 
					@ -54,12 +54,14 @@ export default class RenderingMultiPlexerFeatureSource {
 | 
				
			||||||
                            })
 | 
					                            })
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                        // This is a a line
 | 
					                        // This is a a line: add the centroids
 | 
				
			||||||
                        for (const rendering of centroidRenderings) {
 | 
					                        for (const rendering of centroidRenderings) {
 | 
				
			||||||
                            addAsPoint(feat, rendering, GeoOperations.centerpointCoordinates(feat))
 | 
					                            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
 | 
					                            const coordinates = feat.geometry.coordinates
 | 
				
			||||||
                            for (const rendering of startRenderings) {
 | 
					                            for (const rendering of startRenderings) {
 | 
				
			||||||
                                addAsPoint(feat, rendering, coordinates[0])
 | 
					                                addAsPoint(feat, rendering, coordinates[0])
 | 
				
			||||||
| 
						 | 
					@ -68,29 +70,17 @@ export default class RenderingMultiPlexerFeatureSource {
 | 
				
			||||||
                                const coordinate = coordinates[coordinates.length - 1]
 | 
					                                const coordinate = coordinates[coordinates.length - 1]
 | 
				
			||||||
                                addAsPoint(feat, rendering, coordinate)
 | 
					                                addAsPoint(feat, rendering, coordinate)
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            for (let i = 0; i < lineRenderObjects.length; i++) {
 | 
					                           
 | 
				
			||||||
                                withIndex.push({
 | 
					 | 
				
			||||||
                                    ...feat,
 | 
					 | 
				
			||||||
                                    lineRenderingIndex: i
 | 
					 | 
				
			||||||
                                })
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (feat.geometry.type === "MultiLineString") {
 | 
					                        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
 | 
					                            const lineList: [number, number][][] = feat.geometry.coordinates
 | 
				
			||||||
 | 
					                            
 | 
				
			||||||
                            for (let i1 = 0; i1 < lineList.length; i1++) {
 | 
					                            for (let i1 = 0; i1 < lineList.length; i1++) {
 | 
				
			||||||
                                const coordinates = lineList[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++) {
 | 
					                                for (let i = 0; i < lineRenderObjects.length; i++) {
 | 
				
			||||||
                                    const orig = {
 | 
					                                    const orig = {
 | 
				
			||||||
                                        ...feat,
 | 
					                                        ...feat,
 | 
				
			||||||
| 
						 | 
					@ -102,7 +92,18 @@ export default class RenderingMultiPlexerFeatureSource {
 | 
				
			||||||
                                    withIndex.push(orig)
 | 
					                                    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
 | 
				
			||||||
 | 
					                                })
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                     
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -157,7 +157,6 @@ export default class ShowDataLayer {
 | 
				
			||||||
                    const coords = L.GeoJSON.coordsToLatLngs(feat.geometry.coordinates)
 | 
					                    const coords = L.GeoJSON.coordsToLatLngs(feat.geometry.coordinates)
 | 
				
			||||||
                    const tagsSource = this.allElements?.addOrGetElement(feat) ?? new UIEventSource<any>(feat.properties);
 | 
					                    const tagsSource = this.allElements?.addOrGetElement(feat) ?? new UIEventSource<any>(feat.properties);
 | 
				
			||||||
                    let offsettedLine;
 | 
					                    let offsettedLine;
 | 
				
			||||||
                    console.log("Rendering ", feat)
 | 
					 | 
				
			||||||
                    tagsSource
 | 
					                    tagsSource
 | 
				
			||||||
                        .map(tags => this._layerToShow.lineRendering[feat.lineRenderingIndex].GenerateLeafletStyle(tags))
 | 
					                        .map(tags => this._layerToShow.lineRendering[feat.lineRenderingIndex].GenerateLeafletStyle(tags))
 | 
				
			||||||
                        .withEqualityStabilized((a, b) => {
 | 
					                        .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
 | 
					                            return a.offset === b.offset && a.color === b.color && a.weight === b.weight && a.dashArray === b.dashArray
 | 
				
			||||||
                        })
 | 
					                        })
 | 
				
			||||||
                        .addCallbackAndRunD(lineStyle => {
 | 
					                        .addCallbackAndRunD(lineStyle => {
 | 
				
			||||||
                            console.log("Linestyle is ", lineStyle)
 | 
					 | 
				
			||||||
                            if (offsettedLine !== undefined) {
 | 
					                            if (offsettedLine !== undefined) {
 | 
				
			||||||
                                self.geoLayer.removeLayer(offsettedLine)
 | 
					                                self.geoLayer.removeLayer(offsettedLine)
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue