hfu / noteworthy

noteworthy things in markdown
Creative Commons Zero v1.0 Universal
10 stars 6 forks source link

style.json を生成する DSL を作ればいいんじゃないか。 #60

Open hfu opened 6 years ago

hfu commented 6 years ago

考え方

打鍵数を最小化し、再利用率を最大化したい。

ラフスケッチ

例えば、https://github.com/hfu/som1801-bright/blob/master/style.json を生成する元としてこれを作る。

{
  "hash": "#4.95/5.16/46.15",
  "openmaptiles": {
    "template": "https://hfujimura.gitlab.io/som1801/{z}/{x}/{y}.mvt",
    "attribution": "© OpenMapTiles © OpenStreetMap contributors",
    "maxzoom": 14
  },
  "layers": "bright"
}

この JSON から、気の利いたデフォルトを使って style.json を組み上げていけば良い。ファイル名重要だね、そうだね、例えば sty.json としようか。sty.json から style.json が make されるものと考えよう。

挙動

  1. tile.json は分離しないスタイルの style.json を生成する。(ArcGIS API for JavaScript は tile.json を理解しない。)
  2. ルート直下に hash があったら、Leaflet / Mapbox GL JS のハッシュだと思って zoom, latitude, longitude と解釈する。
  3. ルート直下に layers があったら、そこには「作り置きの layers 定義の名前」が入っているものとして、適宜解決し、代入する。
  4. ルート直下に他のものがあったら、バイナリベクトルタイルのテンプレートを格納しているものと思って適宜処理する。
hfu commented 6 years ago

※ちなみに、昨今の状況に合わせ、バイナリベクトルタイルの拡張子は、今後生成するものは pbf に統一しようとしているところ。

hfu commented 6 years ago

※ArcGIS API for JavaScript はstyle.json内のcenter, zoomを解釈しないことに対してどのように一貫性をとりにいくかも課題。むしろ、外してしまった方がスッキリするかもしれない。style.json には interoperable なことしか記述しないという考え方になる。他方で、center や zoom がないと収拾がつかないアプリケーションもあるかもしれない。翻って、center や zoom を用意することが一定の負担になっているのも事実。正しく管理されづらい数値の温床になる。

hfu commented 6 years ago

もっと node っぽくするほうがいいのだろう。多分、こんな感じ。

const bright = require('./bright.js')
const thematic = require('./thematic.js')
const sources = {
  openmaptiles: {
    template: 'https://hfujimura.gitlab.io/som1801/{z}/{x}/{y}.mvt',
    attribution: '© OpenMapTiles © OpenStreetMap contributors',
    maxzoom: 14
  }, 
  some: {
    template: '...',
    attribution: '...',
    maxzoom: 14
  }
}

console.log(JSON.stringify(style({
  hash: "#4.95/5.16/46.15",
  sources: sources,
  layers: bright.concat(thematic)
}), null, 2))
hfu commented 6 years ago

https://github.com/hfu/style/blob/master/index.js たぶん、こんな風に作っていくのだろう。

おそらく、オープン環境ではこれを作り込む機会がないので、これで実質上本件はクローズとする。

hfu commented 5 years ago

これ、今は hjson でやっている。 https://github.com/hfu/macrostyle