unvt / charites

It is an application to style vector tiles easily

Home Page:https://unvt.github.io/charites/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

">" causes some issue when running "build"

ubukawa opened this issue · comments

Describe the bug
If the "id" of any layer in "layers" is long, ">" 「折り返し形式のブロックスカラー」 is used in the layer list during the import, and it causes problem when we build JSON from YAML.

To Reproduce
Steps to reproduce the behavior:

  1. Prepare a style json with a long layer name.
  2. Import that JSON file into YAML.
  3. Confirm that ">" is used together with "!!inc/file."
  4. Build a newe JSON form imported YAML file.
  5. Then, you will see an error that says "Cannot use 'in' operator to search for 'ref' in !!inc/fil ...."

Expected behavior
Build can be successfully done.

Screenshots
If applicable, add screenshots to help explain your problem.
image

image

Charites Version:

Desktop (please complete the following information):

  • OS: [e.g. Windows] Windows/Docker (unvt/nanban)
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

OK, I think I know why this isn't being parsed correctly.

!!inc/file is a YAML tag? type? statement, and is probably not parsed as such when using a multiline statement such as >- (I found this when looking up multiline statements... 👀 )

As a solution, I think maybe setting lineWidth: -1 for unlimited width when running YAML.dump would work? I don't necessarily like this solution...

Maybe as an alternative we can try removing the replace here:

YAML.dump(style).replace(
/'\!\!inc\/file layers\/.+\.yml'/g,
function (match) {
return match.replace(/'/g, '')
},
),

and replacing it with a non-string type that directly translates to !!inc/file when running YAML.dump?

// ts-ignore is required here because !!inc/file string is not compatible with the Layer object type.
// We use path.posix.join to make sure the path uses / path separators, even when run on Windows.
// @ts-ignore
layers.push(`!!inc/file ${path.posix.join('layers', fileName)}`)

Looking at yaml-include, it doesn't look like we can use that, so we could possibly make a temporary schema just for this:

class IncFileTag {
  constructor(fileName) {
    this.value = path.posix.join('layers', fileName)
  }
}

const incFileYamlType = new yaml.Type('!!inc/file', { kind: 'scalar', resolve: data => data, construct, data => new IncFileTag(data), instanceOf: IncFileTag, represent: tag => tag.value })
const schema = yaml.Schema.create([incFileYamlType])

...
layers.push(new IncFileTag(fileName))
...

yaml.dump(style, { schema: schema })

(I haven't tested it yet... I'll try to get around to trying to fix this in the near future if nobody else wants to.. 🙂 )

Thank you very much for your consideration. Although I cannot immediately understand your script, I keep watching this!

This is the issue, I have written here.
https://unvt.github.io/charites/usage/example2.html#step-2-checking-an-overall-yaml-style-yml-in-this-case

">-" is good if it appears in "attribution" and others, but not in "layers."