Skip to content

Commit b802a6f

Browse files
committed
docs: translate README into ja
- Translates `README.md` and `example/README.md` into Japanese.
1 parent 90c8926 commit b802a6f

File tree

4 files changed

+123
-3
lines changed

4 files changed

+123
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
English / [日本語](./README_ja.md)
2+
13
# Mapbox Collision Boxes
24

35
A utility library for [Mapbox GL JS (`mapbox-gl`)](https://docs.mapbox.com/mapbox-gl-js/guides/), that calculates collision boxes of symbols on a Mapbox map in the screen coordinate.
@@ -45,13 +47,13 @@ You can find a complete project in the [`example`](./example) folder.
4547

4648
I have been developing an app that shows custom symbols on a map using [symbol layers](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#symbol) of `mapbox-gl`.
4749
When symbols overlap on the screen, `mapbox-gl` shows only the first one and hides other overlapping ones.
48-
As far as I know, there is no `mapbox-gl` API to get symbols hidden by a specific symbol on the screen\*.
50+
As far as I know, there is no `mapbox-gl` API to get symbols hidden by a specific symbol on the screen.
4951
This is not convenient for my app because it wants to list all the symbols including hidden ones at a clicked point.
5052
Although there is an [option](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#layout-symbol-icon-allow-overlap) that makes `mapbox-gl` skip collision detection and show every single symbol on the screen, this will make the map too busy if there are many overlapping symbols.
5153

5254
So I decided to **develop a library that can aggregate symbols overlapping with a specific symbol on a Mapbox map**.
5355

54-
Please refer to my [blog post](https://codemonger.io/blog/0009-mapbox-collision-boxes/) for more details.
56+
Please refer to [my blog post](https://codemonger.io/blog/0009-mapbox-collision-boxes/) for more details.
5557

5658
## API Documentation
5759

@@ -61,7 +63,7 @@ Please refer to [`api-docs/markdown/index.md`](./api-docs/markdown/index.md).
6163

6264
### Viewport padding
6365

64-
Collision boxes collected by `collectCollisionBoxesAndFeatures` include constant offsets.
66+
Collision boxes collected by [`collectCollisionBoxesAndFeatures`](./api-docs/markdown/mapbox-collision-boxes.collectcollisionboxesandfeatures.md) include constant offsets.
6567
They have the actual screen position + `100`\* along both the x- and y-axes.
6668
Since the offsets do not matter to hit tests among collision boxes, this library leaves them to avoid unnecessary calculation.
6769
If you want to project collision boxes to the actuall screen, you have to subtract `100` from their x- and y-axis values.

README_ja.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[English](./README.md) / 日本語
2+
3+
# Mapbox Collision Boxes
4+
5+
Mapboxマップ上の衝突ボックスを画面座標系で計算する、[Mapbox GL JS (`mapbox-gl`)](https://docs.mapbox.com/mapbox-gl-js/guides/)用のユーティリティライブラリです。
6+
7+
## はじめる
8+
9+
### 事前準備
10+
11+
このライブラリは`mapbox-gl`バージョン2以降と一緒に使用する想定です。
12+
13+
### インストール方法
14+
15+
このレポジトリを依存関係に追加してください。
16+
17+
```sh
18+
npm install https://github.com/codemonger-io/mapbox-collision-boxes#v0.1.0
19+
```
20+
21+
### 使い方
22+
23+
以下のスニペットはクリックしたシンボルに画面上で隠されているFeatureを集めてくる例です。
24+
25+
```ts
26+
import mapboxgl from 'mapbox-gl';
27+
import { boxesIntersect, collectCollisionBoxesAndFeatures } from 'mapbox-collision-boxes';
28+
29+
const map = new mapboxgl.Map(
30+
// ... マップの初期化
31+
);
32+
// ... その他の設定
33+
const layerId = 'cats-and-dogs'; // カスタムレイヤーを追加した想定
34+
const map.on('click', layerId, async event => {
35+
const clickedFeatureId = event.features[0].id;
36+
const collisionBoxes = await collectCollisionBoxesAndFeatures(map, layerId);
37+
const clickedBox = collisionBoxes.find(box => box.feature.id === clickedFeatureId);
38+
const hiddenBoxes = collisionBoxes.filter(box => box !== clickedBox && boxesIntersect(box.box, clickedBox.box));
39+
const hiddenFeatures = hiddenBoxes.map(box => box.feature);
40+
// ... Featureの処理
41+
});
42+
```
43+
44+
[`example`](./example)フォルダに完成したプロジェクトがあります。
45+
46+
## 動機
47+
48+
私はマップ上に`mapbox-gl`[Symbol Layer](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#symbol)を使ってカスタムシンボルを表示するアプリを開発中です。
49+
画面上でシンボルが被ると、`mapbox-gl`は最初のものだけ表示し、他の重なるものは隠してしまいます。
50+
私の知る限り、`mapbox-gl`には画面上で特定のシンボルによって隠されているシンボルを取得するAPIはありません。
51+
開発中のアプリでは非表示のものも含めてクリックされたポイントにあるすべてのシンボルをリストしたいので、これでは不都合です。
52+
`mapbox-gl`に衝突検出をスキップさせてすべてのシンボルを画面に表示させる[オプション](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#layout-symbol-icon-allow-overlap)はありますが、重なるシンボルがたくさんある場合は画面がごちゃごちゃし過ぎてしまいます。
53+
54+
ということで**Mapboxマップ上で特定のシンボルと重なるシンボルを集めることのできるライブラリを開発**することにしました。
55+
56+
詳しくは[私のブログ投稿](https://codemonger.io/blog/0009-mapbox-collision-boxes/)をご覧ください。
57+
58+
## APIドキュメント
59+
60+
[`api-docs/markdown/index.md`](./api-docs/markdown/index.md)をご覧ください。
61+
62+
## Tips
63+
64+
### ビューポートオフセット
65+
66+
[`collectCollisionBoxesAndFeatures`](./api-docs/markdown/mapbox-collision-boxes.collectcollisionboxesandfeatures.md)が集める衝突ボックスは固定のオフセットを含んでいます。
67+
xとyの両軸について実際の画面位置 + `100`\*になっています。
68+
オフセットは衝突ボックス同士の衝突判定には影響しないため、このライブラリでは不必要な計算を避けるためにそのままにしてあります。
69+
衝突ボックスを実際の画面に投影したい場合は、xとy軸の値から`100`を引かなければなりません。
70+
71+
\* この定数は`viewportPadding`として https://github.com/mapbox/mapbox-gl-js/blob/e29e113ff5e1f4c073f84b8cbe546006d2fb604f/src/symbol/collision_index.js#L50 に定義されていますが、`mapbox-gl`はエクスポートしていません。

example/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
English / [日本語](./README_ja.md)
2+
13
# Example for Mapbox Collision Boxes
24

35
A simple [Vue 3](https://vuejs.org) app to demonstrate `mapbox-collision-boxes`.

example/README_ja.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[English](./README.md) / 日本語
2+
3+
# Mapbox Collision Boxesのサンプル
4+
5+
`mapbox-collision-boxes`のデモをする簡単な[Vue 3](https://vuejs.org)アプリです。
6+
このプロジェクトは`npm init vue@latest`で生成しました。
7+
8+
このアプリは東京駅周辺の[Mapbox](https://www.mapbox.com)マップを表示し、ランダムに猫と犬のシンボルを撒き散らします。
9+
猫か犬のシンボルをクリックしどのシンボルが隠されているかを見ることができます。
10+
![スクリーンショット](./screenshots.png)
11+
12+
## はじめる
13+
14+
### 事前準備
15+
16+
[Node.js](https://nodejs.org/en/)をインストールする必要があります。
17+
このライブラリはバージョン16で開発しましたが、バージョン12以降なら問題ないはずです。
18+
19+
[Mapbox GL JS](https://docs.mapbox.com/mapbox-gl-js/guides/)はマップデータをダウンロードするために[アクセストークン](https://docs.mapbox.com/help/getting-started/access-tokens/)を要求します。
20+
アクセストークンはこのレポジトリに含まれていませんので、自身で作成しなければなりません。
21+
[「Mapboxアクセストークンを設定する」](#Mapboxアクセストークンを設定する)をご確認ください。
22+
23+
### Mapboxアクセストークンを設定する
24+
25+
`mapbox-config.ts`ファイルを`src`フォルダに作成し、以下の内容を書き込んでください。
26+
```ts
27+
export const MAPBOX_ACCESS_TOKEN = '<Your Mapbox Access Token Here>';
28+
```
29+
30+
`<Your Mapbox Access Token Here>`をあなたのMapboxアクセストークンで置き換えてください。
31+
`src/mapbox-config.ts`はこのレポジトリにプッシュされません。
32+
33+
### 依存関係を解決する
34+
35+
```sh
36+
npm install
37+
```
38+
39+
### 開発サーバーでサンプルを動かす
40+
41+
```sh
42+
npm run dev
43+
```
44+
45+
開発サーバーは http://localhost:5173 でホストされます。

0 commit comments

Comments
 (0)