DEV Community

Hidenori FUJIMURA
Hidenori FUJIMURA

Posted on

style.json from Apple Pkl #2

Started to generate style.json...

1.pkl

// my first attempt to generate style.json from a pkl file.

version = 8
center { -122.42 37.80 }
zoom = 10.42
sources = import("sources.pkl")
sprite = "https://tile.openstreetmap.jp/styles/maptiler-toner-en/sprite"
glyphs = "https://tile.openstreetmap.jp/fonts/{fontstack}/{range}.pbf"
layers = new Listing {
    import("background.pkl")
}
Enter fullscreen mode Exit fullscreen mode

sources.pkl

module sources

openmaptiles {
    type = "vector"
    url = "https://tile.openstreetmap.jp/data/planet.json"
}
Enter fullscreen mode Exit fullscreen mode

background.pkl

module background

id = "background"
paint { background_color = "#fff" }
Enter fullscreen mode Exit fullscreen mode

Makefile

use_color: 
    pkl eval -f json use_color.pkl
1: 
    pkl eval -f json 1.pkl
Enter fullscreen mode Exit fullscreen mode

Result

% make 1
pkl eval -f json 1.pkl
{
  "version": 8,
  "center": [
    -122.42,
    37.8
  ],
  "zoom": 10.42,
  "sources": {
    "openmaptiles": {
      "type": "vector",
      "url": "https://tile.openstreetmap.jp/data/planet.json"
    }
  },
  "sprite": "https://tile.openstreetmap.jp/styles/maptiler-toner-en/sprite",
  "glyphs": "https://tile.openstreetmap.jp/fonts/{fontstack}/{range}.pbf",
  "layers": [
    {
      "id": "background",
      "paint": {
        "background_color": "#fff"
      }
    },
    {
      "id": "cde"
    }
  ]
}
hfu@smart pkl-test % make 1
pkl eval -f json 1.pkl
{
hfu@smart pkl-test % make 1
pkl eval -f json 1.pkl
{
  "version": 8,
  "center": [
    -122.42,
    37.8
  ],
  "zoom": 10.42,
  "sources": {
    "openmaptiles": {
      "type": "vector",
      "url": "https://tile.openstreetmap.jp/data/planet.json"
    }
  },
  "sprite": "https://tile.openstreetmap.jp/styles/maptiler-toner-en/sprite",
  "glyphs": "https://tile.openstreetmap.jp/fonts/{fontstack}/{range}.pbf",
  "layers": [
    {
      "id": "background",
      "paint": {
        "background_color": "#fff"
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Repository

https://github.com/hfu/pkl-test

Top comments (0)