Skip to content

pm:cut - how to copy GeoJSON feature properties from originalLayer to new layer(s)? #1556

Closed Answered by Falke-Design
udos asked this question in Questions & Help
Discussion options

You must be logged in to vote

You need to copy the properties from the geojson data on the Leaflet Layer-Object.
https://plnkr.co/edit/Q6qaZM5QxsxV7hCG

line.on('pm:cut', (e)=>{
	console.log(e)

	// copy properties without reference
	const properties = JSON.parse(JSON.stringify(e.originalLayer.feature.properties))
	e.layer.getLayers().forEach((layer)=>{
		// to makre sure that the geojson sturcutre is on the layer object
		layer.toGeoJSON();

		layer.feature.properties = properties;
		layer.bindPopup('<pre>'+JSON.stringify(layer.feature.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');

	})
})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@udos
Comment options

Answer selected by udos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants