Skip to content

Conversation

@wipfli
Copy link
Collaborator

@wipfli wipfli commented Jun 23, 2024

Encodes parts of strings that are in the Devanagari script with a positioned glyph font from https://github.com/wipfli/pgf-encoding.

Usage in style.json

Engish

To show a map localized to English one can do then something like this:

"text-field": [
    "case",
    ["has", "pmap:script"],
    [
        "format",
        [
        "coalesce",
        ["get", "name:en"],
        ["get", "name:de"],
        ["get", "name:fr"]
        ],
        {},
        "\n",
        {},
        ["get", "pmap:pgf:name"],
        {
        "text-font": [
            "case",
            ["==", ["get", "pmap:script"], "Devanagari"],
            ["literal", ["NotoSansDevanagari-Regular-v1"]],
            ["literal", ["Noto Sans Regular"]]
        ]
        }
    ],
    [
        "coalesce",
        ["get", "name:en"],
        ["get", "name"]
    ]
],

Nepali

For Nepali one can on the other hand do something like this:

"text-field": [
    "case",
    ["!=", ["get", "pmap:script"], "Devanagari"],
    [
        "format",
        [
        "coalesce",
        ["get", "pmap:pgf:name:ne"],
        ["get", "pmap:pgf:name:mr"],
        ["get", "pmap:pgf:name:hi"]
        ],
        {
        "text-font": ["literal", ["NotoSansDevanagari-Regular-v1"]]
        },
        "\n",
        {},
        ["get", "pmap:pgf:name"],
        {
        "text-font": [
            "case",
            ["==", ["get", "pmap:script"], "Devanagari"],
            ["literal", ["NotoSansDevanagari-Regular-v1"]],
            ["literal", ["Noto Sans Regular"]]
        ]
        }
    ],
    [
        "format",
        [
        "coalesce",
        ["get", "pmap:pgf:name:ne"],
        ["get", "pmap:pgf:name"]
        ],
        {
        "text-font": ["literal", ["NotoSansDevanagari-Regular-v1"]]
        }
    ]
],

Demo

Planet PMTiles

https://pub-726b01260c98468a9387cc0dfcb7386b.r2.dev/protomaps-planet-pgf-20240627.pmtiles (126 GB)

Nepali

Note: Only the places_locality layer was changed.

https://pub-cf7f11e26ace447db8f7215b61ac0eae.r2.dev/ne.html

English

Note: Only the places_locality layer was changed.

https://pub-cf7f11e26ace447db8f7215b61ac0eae.r2.dev/en.html

Todos

  • Remove all todo comments
  • Handle errors and exceptions
  • Add unit tests
  • Remove main() functions
  • Store fonts and versions in tilejson metadata

@wipfli
Copy link
Collaborator Author

wipfli commented Jun 27, 2024

Thank you for the great feedback @bdon. I think I address all concerns. The naming has been updated and I am currently running a planet build which should be ready for an updated demo in a few hours.

Let me know what else needs to change...

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3 Security Hotspots
66.4% Coverage on New Code (required ≥ 80%)
5.1% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@bdon bdon merged commit e8127dc into protomaps:main Jun 27, 2024
List<String> scripts = fontRegistry.getScripts();

for (String script : scripts) {
result.put("pgf:" + script.toLowerCase() + ":name", fontRegistry.getName(script));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't clear to me that pgf stands for "positioned glyph font", consider adding a comment above this line to explain that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I was also wondering if we have a schema documentation somewhere?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the inline comment in the code here, we should probably add a new "names.md" or localization.md file next to https://github.com/protomaps/docs/blob/main/basemaps/layers.md in the Protomaps docs repo?

Tilezen had this, which we should only lightly crib from.

Natural Earth's table of common languages is useful, too, and add a script column to that?

image

...snip...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wipfli wipfli deleted the pgf2 branch June 27, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants