feat(parser): parse LineStyle, PolyStyle and SimpleData - #18
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two gaps that both end the same way: the parser reads the file, reports success, and silently returns nothing for data that is right there in the document.
1. Lines and polygons have no style
getStyles()readIconStyleandLabelStyleand nothing else. Those two describe a point marker. The elements that describe everything not a point were skipped:LineStyle—colorandwidth, the stroke of aLineStringand the outline of aPolygonPolyStyle—color,fillandoutline, the fill of aPolygonSo a document full of routes and areas parsed fine and came back with geometry that could not be drawn: no colour, no width, no fill. The information was in the file the whole time.
Both are now parsed.
Only what the document declares
KML defines defaults for all of these (
width1,colorffffffff,fillandoutline1). The parser does not fill them in. Emitting a default would stop the caller telling "the file said nothing about width" apart from "the file said width is exactly 1", and a renderer that wants the default can apply it itself.<fill>0</fill>Read with
isset(), not a truthiness check:if ($polyStyle->fill)would be false for<fill>0</fill>and the key would vanish — which is precisely the case where the document is saying something non-default and the caller most needs to know. There is a test for it.2.
ExtendedDataignored half the specOnly
<Data>pairs. But KML has a second form, and it is the oneogr2ogrand QGIS emit:Every attribute in such a file was dropped.
getPlacemarks()returnedextendedData => []andtoGeoJson()carried nothing intoproperties. No error, no warning: the data was simply gone.Both forms now land in the same map.
SimpleDatais applied last, so if a document somehow declares the same name both ways the explicit schema value wins. Several<SchemaData>blocks in one<ExtendedData>are all read.Note that
<SimpleData>holds its value as the element's own text, not in a<value>child like<Data>does — which is why the existing loop could never have picked it up even by accident.Tests
tests/StyleDetailsTest.phpandtests/ExtendedDataTest.php, 10 tests. 9 of the 10 fail onmain; the one that passes is the existing<Data>behaviour, which is deliberately unchanged.color+widthcolor+fill+outline<fill>0</fill>survives asfalseLineStyle-only style has nopolyStyle/iconStyle/labelStylekeysIconStyleandLabelStylestill parse exactly as before, alongside the new onesSimpleDatainsideSchemaDataDataandSimpleDatamixed in oneExtendedDataSimpleDataspread across severalSchemaDatablockspropertiesSuite goes 39 to 49. Pint and PHPStan clean.
Behaviour change
getStyles()entries can now carrylineStyleandpolyStylekeys, andextendedDatacan now be non-empty where it used to be empty. Additive: nothing that was returned before changed shape. Worth a changelog line so people know the data is there.Not in scope
<Folder>nesting,NetworkLink,GroundOverlay,TimeStamp/TimeSpanandgx:Trackare still unsupported. The README does not yet state which elements are supported at all, which is the next thing worth fixing.