@unvt/charites 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/README.md +1 -1
- package/.eslintrc.js +1 -1
- package/.github/PULL_REQUEST_TEMPLATE.md +1 -1
- package/.github/release.yml +14 -0
- package/.github/workflows/build-docs.yml +4 -4
- package/.github/workflows/build.yml +33 -7
- package/LICENSE +1 -1
- package/dist/cli/build.js +4 -4
- package/dist/cli/convert.js +2 -2
- package/dist/cli/init.js +3 -3
- package/dist/cli/serve.js +8 -4
- package/dist/commands/build.js +7 -12
- package/dist/commands/convert.js +2 -12
- package/dist/commands/init.js +1 -1
- package/dist/commands/serve.js +81 -16
- package/dist/lib/build-sprite.js +6 -8
- package/dist/lib/error.js +2 -1
- package/dist/lib/tileinfo-importer/index.js +1 -0
- package/dist/lib/yaml-writer.js +25 -13
- package/dist/types/index.js +6 -2
- package/docs/Pipfile.lock +136 -193
- package/docs/source/conf.py +3 -3
- package/docs/source/index.rst +2 -2
- package/docs/source/install/img/windows-guide-01.png +0 -0
- package/docs/source/install/index.rst +1 -0
- package/docs/source/install/install.rst +1 -0
- package/docs/source/install/install_on_nanban.rst +1 -1
- package/docs/source/install/installation_guide_for_windows.rst +52 -0
- package/docs/source/install/recommended_environment.rst +2 -2
- package/docs/source/usage/commandline_interface.rst +23 -10
- package/docs/source/usage/example2.rst +166 -0
- package/docs/source/usage/examples.rst +2 -2
- package/docs/source/usage/img/example02-001.png +0 -0
- package/docs/source/usage/img/example02-002.png +0 -0
- package/docs/source/usage/img/example02-003.png +0 -0
- package/docs/source/usage/img/example02-004.png +0 -0
- package/docs/source/usage/img/example02-005.png +0 -0
- package/docs/source/usage/img/example02-006.png +0 -0
- package/docs/source/usage/img/example02-007.png +0 -0
- package/docs/source/usage/img/example02-008.png +0 -0
- package/docs/source/usage/img/example02-009.png +0 -0
- package/docs/source/usage/img/example02-010.png +0 -0
- package/docs/source/usage/img/example02-011.png +0 -0
- package/docs/source/usage/img/example02-012.png +0 -0
- package/docs/source/usage/img/example02-013.png +0 -0
- package/docs/source/usage/img/example02-014.png +0 -0
- package/docs/source/usage/img/example02-015.png +0 -0
- package/docs/source/usage/img/example02-016.png +0 -0
- package/docs/source/usage/img/example02-017.png +0 -0
- package/docs/source/usage/img/example02-018.png +0 -0
- package/docs/source/usage/index.rst +1 -0
- package/package.json +34 -28
- package/playwright.config.ts +29 -0
- package/provider/default/app.js +26 -46
- package/provider/default/index.html +4 -3
- package/provider/default/shared.js +76 -0
- package/provider/geolonia/app.js +25 -32
- package/provider/geolonia/index.html +4 -1
- package/provider/mapbox/app.js +33 -53
- package/provider/mapbox/index.html +2 -1
- package/src/cli/init.ts +1 -1
- package/src/cli/serve.ts +10 -3
- package/src/commands/build.ts +2 -6
- package/src/commands/convert.ts +2 -10
- package/src/commands/init.ts +1 -1
- package/src/commands/serve.ts +107 -15
- package/src/lib/build-sprite.ts +2 -6
- package/src/lib/get-sprite-slug.ts +1 -1
- package/src/lib/tileinfo-importer/base-importer.ts +1 -1
- package/src/lib/tileinfo-importer/metadata-importer.ts +1 -1
- package/src/lib/tileinfo-importer/tilejson-importer.ts +1 -1
- package/src/lib/validate-style.ts +1 -1
- package/src/lib/yaml-parser.ts +1 -1
- package/src/lib/yaml-writer.ts +28 -15
- package/test/build.spec.ts +22 -12
- package/test/command.build.spec.ts +39 -31
- package/test/command.serve.spec.ts +103 -0
- package/test/convert.spec.ts +24 -4
- package/test/data/convert.json +7 -0
- package/test/data/style.json +4 -3
- package/test/init.spec.ts +7 -5
- package/test/playwright/provider/default/e2e.spec.ts +13 -0
- package/test/playwright/provider/geolonia/e2e.spec.ts +13 -0
- package/test/playwright/provider/mapbox/e2e.spec.ts +13 -0
- package/test/util/charitesCmd.ts +3 -1
- package/test/util/execPromise.ts +51 -1
- package/test/util/index.ts +3 -0
- package/test/validate-style.spec.ts +1 -1
- package/provider/geolonia/app.css +0 -17
- package/provider/mapbox/app.css +0 -17
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Commandline Interface
|
|
2
2
|
======================
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Help
|
|
5
5
|
----
|
|
6
6
|
|
|
7
7
|
.. code-block:: bash
|
|
@@ -14,13 +14,22 @@ help
|
|
|
14
14
|
-h, --help display help for command
|
|
15
15
|
|
|
16
16
|
Commands:
|
|
17
|
-
init [options] <file> initialize a style
|
|
17
|
+
init [options] <file> initialize a style YAML
|
|
18
18
|
convert <source> [destination] convert the style JSON to YAML
|
|
19
19
|
build [options] <source> [destination] build a style JSON from the YAML
|
|
20
20
|
serve [options] <source> serve your map locally
|
|
21
21
|
help [command] display help for command
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
Checking version
|
|
25
|
+
-------------------
|
|
26
|
+
|
|
27
|
+
.. code-block:: bash
|
|
28
|
+
|
|
29
|
+
$ charites --version
|
|
30
|
+
0.3.0
|
|
31
|
+
|
|
32
|
+
|
|
24
33
|
Inititalize `style.yml`
|
|
25
34
|
-----------------------
|
|
26
35
|
|
|
@@ -29,7 +38,7 @@ Inititalize `style.yml`
|
|
|
29
38
|
$ charites init -h
|
|
30
39
|
Usage: charites init [options] <file>
|
|
31
40
|
|
|
32
|
-
initialize a style
|
|
41
|
+
initialize a style YAML
|
|
33
42
|
|
|
34
43
|
Options:
|
|
35
44
|
-t, --tilejson-urls <tilejson_urls> an URL for TileJSON. It will create empty layers from vector_layers property of TileJSON. Please use
|
|
@@ -85,18 +94,22 @@ Realtime editor on browser
|
|
|
85
94
|
serve your map locally
|
|
86
95
|
|
|
87
96
|
Options:
|
|
88
|
-
--provider [provider]
|
|
89
|
-
--mapbox-access-token [mapboxAccessToken]
|
|
90
|
-
--
|
|
91
|
-
|
|
97
|
+
--provider [provider] your map service. e.g. `mapbox`, `geolonia`
|
|
98
|
+
--mapbox-access-token [mapboxAccessToken] Access Token for the Mapbox
|
|
99
|
+
-i, --sprite-input [<icon input directory>] directory path of icon source to build icons. The default <icon
|
|
100
|
+
source> is `icons/`
|
|
101
|
+
--port [port] Specify custom port
|
|
102
|
+
-h, --help display help for command
|
|
92
103
|
|
|
93
104
|
Charites has three options for `serve` command.
|
|
94
105
|
|
|
95
|
-
-
|
|
106
|
+
- ``--provider`` - `mapbox`, `geolonia`, or `default`. When not specified, default or the value in the configuration file will be used.
|
|
96
107
|
|
|
97
108
|
- `mapbox` - The format linter runs against the Mapbox GL JS v2.x compatible specification.
|
|
98
109
|
- `geolonia` and `default` - the format linter runs against the MapLibre GL JS compatible specification.
|
|
99
110
|
|
|
100
|
-
-
|
|
111
|
+
- ``--mapbox-access-token`` - Set your access-token when styling for Mapbox.
|
|
112
|
+
|
|
113
|
+
- ``--sprite-input`` - If you are building icon spritesheets with Charites, you can specify the directory of SVG files to compile here. See the ``build`` command for more information.
|
|
101
114
|
|
|
102
|
-
-
|
|
115
|
+
- ``--port`` - Set http server's port number. When not specified, the default is 8080.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Example 2: Import existing style.json and edit it with charites
|
|
2
|
+
===================================================================
|
|
3
|
+
This is an example of using charites for importing an existing style.json and editing it as yaml files, and exporting them back to a json style.
|
|
4
|
+
|
|
5
|
+
Condition
|
|
6
|
+
------------------------
|
|
7
|
+
- OS: Windows 10
|
|
8
|
+
- Charites version: 0.3.0
|
|
9
|
+
- Running on WindowsPowershell
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Steps
|
|
13
|
+
-----
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Step 1. Import style json into a series of YAML files
|
|
17
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
18
|
+
|
|
19
|
+
If your style json is in the Internet, it may need to downloat it from the Internet before you convert because charites cannot directly convert json a file in the Internet. Use curl.exe (in WindowsPowershell) or curl (in bash environment).
|
|
20
|
+
|
|
21
|
+
.. code-block::
|
|
22
|
+
|
|
23
|
+
curl.exe -O https://ubukawa.github.io/cmv-test/style1.json
|
|
24
|
+
charites convert style1.json editing/style.yml
|
|
25
|
+
|
|
26
|
+
Then, you will see a series of yaml files are converted from the source json. You will obtain an overall YAML that contains a list of style layers with the style yamls in the layer directory.
|
|
27
|
+
In this case, we will have "style.yml" in "editing" directory together with a lot of yaml files for layers in "layers" directory.
|
|
28
|
+
|
|
29
|
+
.. image:: ./img/example02-001.png
|
|
30
|
+
:scale: 75%
|
|
31
|
+
:align: center
|
|
32
|
+
|
|
33
|
+
.. image:: ./img/example02-002.png
|
|
34
|
+
:scale: 75%
|
|
35
|
+
:align: center
|
|
36
|
+
|
|
37
|
+
(Tips) It is good to know that if your source json has some folder structure in its layer ids, that structure would be maintained when you import.
|
|
38
|
+
|
|
39
|
+
.. image:: ./img/example02-005.png
|
|
40
|
+
:scale: 75%
|
|
41
|
+
:align: center
|
|
42
|
+
|
|
43
|
+
.. image:: ./img/example02-003.png
|
|
44
|
+
:scale: 75%
|
|
45
|
+
:align: center
|
|
46
|
+
|
|
47
|
+
.. image:: ./img/example02-004.png
|
|
48
|
+
:scale: 75%
|
|
49
|
+
:align: center
|
|
50
|
+
|
|
51
|
+
Step 2. Checking an overall yaml (style.yml in this case)
|
|
52
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
53
|
+
Check the style.yml by opening it with Notepad or any text editor. You will see it like this:
|
|
54
|
+
|
|
55
|
+
.. image:: ./img/example02-006.png
|
|
56
|
+
:scale: 75%
|
|
57
|
+
:align: center
|
|
58
|
+
|
|
59
|
+
Although it is not often seen, we need to check one thing. Sometimes, if id for each layer is too long, YAML automatically uses ">-" and break the line to improve human's readability. ">-" would pretend an actual line break in YAML, however, it will cause some problem for Charites, so please fix line brakes with ">-" in the layers if you find them.
|
|
60
|
+
This is often seen in style files from Esri vector tile because it has detailed folder structure sometimes.
|
|
61
|
+
|
|
62
|
+
.. image:: ./img/example02-007.png
|
|
63
|
+
:scale: 75%
|
|
64
|
+
:align: center
|
|
65
|
+
|
|
66
|
+
.. image:: ./img/example02-008.png
|
|
67
|
+
:scale: 75%
|
|
68
|
+
:align: center
|
|
69
|
+
|
|
70
|
+
You can extract layers and use "replace" tool to remove ">-" and unnecessary line changes.
|
|
71
|
+
|
|
72
|
+
.. image:: ./img/example02-009.png
|
|
73
|
+
:scale: 75%
|
|
74
|
+
:align: center
|
|
75
|
+
|
|
76
|
+
.. image:: ./img/example02-010.png
|
|
77
|
+
:scale: 75%
|
|
78
|
+
:align: center
|
|
79
|
+
|
|
80
|
+
If you obtain the list of layers without ">-", you are ready to go to the next step.
|
|
81
|
+
|
|
82
|
+
.. image:: ./img/example02-011.png
|
|
83
|
+
:scale: 75%
|
|
84
|
+
:align: center
|
|
85
|
+
|
|
86
|
+
.. note::
|
|
87
|
+
|
|
88
|
+
You may also need to check paths in "sprite", "glyphs" and "sources." They would be written as relative paths, so you may need to adjust these paths so that charites in your local PC can access to them. In addition, if you are importing styles from ArcGIS server, reference to the source should be modifyed (use "tiles" instead of "url"). The "tiles" URL will be provided by adding "/tile/{z}/{y}/{x}.pbf" in the end of Esri vector tile server URL.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
Step 3. Serve YAML files for live preview
|
|
92
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
93
|
+
|
|
94
|
+
Run the "charites serve" command to serve your YAML files in the localhost. By default, its port is 8080.
|
|
95
|
+
|
|
96
|
+
.. code-block::
|
|
97
|
+
|
|
98
|
+
charites serve editing/style.yml
|
|
99
|
+
|
|
100
|
+
A window would automatically appears in the windows environment, but if not please open "http://localhost:8080" to access your live view. You can stop the live preview by pressing ctrl + c.
|
|
101
|
+
|
|
102
|
+
.. image:: ./img/example02-012.png
|
|
103
|
+
:scale: 75%
|
|
104
|
+
:align: center
|
|
105
|
+
|
|
106
|
+
Step 4. Editing YAML files to change style
|
|
107
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
108
|
+
You can change/edit the map style by editing YAML files. If you edit and save your update, charites automatically finds your updates to reflect them into the live view.
|
|
109
|
+
|
|
110
|
+
.. image:: ./img/example02-016.png
|
|
111
|
+
:scale: 75%
|
|
112
|
+
:align: center
|
|
113
|
+
|
|
114
|
+
Here are some tips for efficient style editing.
|
|
115
|
+
|
|
116
|
+
(Tips 1) Legend control
|
|
117
|
+
########################
|
|
118
|
+
There is a legend control in the lower left of the screen. You can turn on/off any layers so that your edit would be easy. It will also help you to identify layers that should be edited.
|
|
119
|
+
You can enlarge the window by clicking the button, and reduce its size by clicking "x" in the window. You can also choose to list only rendered layers or not in the window.
|
|
120
|
+
|
|
121
|
+
.. image:: ./img/example02-013.png
|
|
122
|
+
:scale: 75%
|
|
123
|
+
:align: center
|
|
124
|
+
|
|
125
|
+
(Tips 2) Showing tile boundary
|
|
126
|
+
###############################
|
|
127
|
+
It would be alos helpful to show the tile boundary. There are checkbox in the upper left, and you can turn on/off. You will see tile border and its xyx in z/x/y order together with tile size. This would be useful when you also think about optimization of your vector tile.
|
|
128
|
+
|
|
129
|
+
.. image:: ./img/example02-014.png
|
|
130
|
+
:scale: 75%
|
|
131
|
+
:align: center
|
|
132
|
+
|
|
133
|
+
(Tips 3) Showing collision boxes
|
|
134
|
+
#################################
|
|
135
|
+
It would be alos helpful to show the collision boxes. If a box is red, it indicates a collision with others. When you adjust label location/size, this is good.
|
|
136
|
+
|
|
137
|
+
.. image:: ./img/example02-015.png
|
|
138
|
+
:scale: 75%
|
|
139
|
+
:align: center
|
|
140
|
+
|
|
141
|
+
(Tips 4) Use of "#" (comment tag) to specify error
|
|
142
|
+
###################################################
|
|
143
|
+
If there is a layer contains some error, the web map may not appears. In such a case, use a YAML comment tag "#" to comment out a layer (or layers) to specify the layer contains an error. The comment tag is also useful to tentatively change colors, etc.
|
|
144
|
+
|
|
145
|
+
(Tips 5) Use of inclusion of other YAML file for efficinet edit
|
|
146
|
+
################################################################
|
|
147
|
+
If you repeatedly use the same expression (color, font, etc) for several layers, it is conveninet to use a reference to a common expression. You can do it by using inclusion of an independent YAML file with "!!inc/file hogehoge.yml". This is particular important if you manage your style with YAML files.
|
|
148
|
+
|
|
149
|
+
.. image:: ./img/example02-017.png
|
|
150
|
+
:scale: 75%
|
|
151
|
+
:align: center
|
|
152
|
+
|
|
153
|
+
.. image:: ./img/example02-018.png
|
|
154
|
+
:scale: 75%
|
|
155
|
+
:align: center
|
|
156
|
+
|
|
157
|
+
Step 5. Exporting style json from YAML files
|
|
158
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
159
|
+
Once you have edited your style with YAML files, you can now export it back to json by running the following command.
|
|
160
|
+
|
|
161
|
+
.. code-block::
|
|
162
|
+
|
|
163
|
+
charites build editing/style.yml out.json
|
|
164
|
+
|
|
165
|
+
Congratulations. You will obtain the updated style json, and all done.
|
|
166
|
+
|
|
@@ -29,14 +29,14 @@ Build `style.json` from `style.yml`:
|
|
|
29
29
|
|
|
30
30
|
charites build style.yml style.json
|
|
31
31
|
|
|
32
|
-
Add
|
|
32
|
+
Add ``-c`` or ``--compact-output`` to minify the JSON
|
|
33
33
|
|
|
34
34
|
.. code-block:: bash
|
|
35
35
|
|
|
36
36
|
charites build style.yml style.json -c
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
Add
|
|
39
|
+
Add ``--sprite-input`` and ``--sprite-output`` to build svg files for map icons.
|
|
40
40
|
|
|
41
41
|
.. code-block:: bash
|
|
42
42
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unvt/charites",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"bin": {
|
|
6
6
|
"charites": "dist/cli.js"
|
|
@@ -9,45 +9,51 @@
|
|
|
9
9
|
"build": "tsc -p .",
|
|
10
10
|
"watch": "tsc -w",
|
|
11
11
|
"lint": "eslint --fix .",
|
|
12
|
-
"test": "npm run build && mocha -r ts-node/register test/*.ts",
|
|
12
|
+
"test": "npm run build && mocha --timeout 5000 -r ts-node/register test/*.ts",
|
|
13
13
|
"test:watch": "npm test -- --watch --watch-files src/**/*.ts --watch-files test/**/*.ts",
|
|
14
|
+
"test:e2e": "npx playwright test",
|
|
14
15
|
"command": "./node_modules/.bin/ts-node ./src/cli.ts"
|
|
15
16
|
},
|
|
16
17
|
"author": "",
|
|
17
18
|
"license": "MIT",
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@mapbox/mapbox-gl-style-spec": "^13.
|
|
20
|
-
"@maplibre/maplibre-gl-style-spec": "^
|
|
21
|
-
"@unvt/sprite-one": "^0.0.6",
|
|
20
|
+
"@mapbox/mapbox-gl-style-spec": "^13.27.0",
|
|
21
|
+
"@maplibre/maplibre-gl-style-spec": "^17.0.2",
|
|
22
22
|
"@types/jsonminify": "^0.4.1",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
23
|
+
"@unvt/sprite-one": "^0.0.9",
|
|
24
|
+
"axios": "^1.2.2",
|
|
25
|
+
"commander": "^9.4.1",
|
|
26
|
+
"glob": "^8.0.3",
|
|
26
27
|
"js-yaml": "^4.0.0",
|
|
27
|
-
"jsonminify": "^0.4.
|
|
28
|
-
"node-watch": "^0.7.
|
|
28
|
+
"jsonminify": "^0.4.2",
|
|
29
|
+
"node-watch": "^0.7.3",
|
|
29
30
|
"open": "^8.2.1",
|
|
30
|
-
"ws": "^8.
|
|
31
|
+
"ws": "^8.11.0",
|
|
31
32
|
"yaml-include": "^1.2.1"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
+
"@playwright/test": "^1.29.1",
|
|
36
|
+
"@types/chai": "^4.3.4",
|
|
37
|
+
"@types/chai-as-promised": "^7.1.5",
|
|
35
38
|
"@types/fs-extra": "^9.0.13",
|
|
36
|
-
"@types/js-yaml": "^4.0.
|
|
37
|
-
"@types/
|
|
38
|
-
"@types/
|
|
39
|
-
"@types/
|
|
40
|
-
"@
|
|
41
|
-
"@typescript-eslint/
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"eslint
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
39
|
+
"@types/js-yaml": "^4.0.5",
|
|
40
|
+
"@types/mapbox__point-geometry": "^0.1.2",
|
|
41
|
+
"@types/mocha": "^10.0.1",
|
|
42
|
+
"@types/node": "^18.11.18",
|
|
43
|
+
"@types/ws": "^8.5.4",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
|
45
|
+
"@typescript-eslint/parser": "^5.47.1",
|
|
46
|
+
"chai": "^4.3.7",
|
|
47
|
+
"chai-as-promised": "^7.1.1",
|
|
48
|
+
"eslint": "^8.31.0",
|
|
49
|
+
"eslint-config-prettier": "^8.5.0",
|
|
50
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
51
|
+
"fs-extra": "^11.1.0",
|
|
52
|
+
"kill-port-process": "^3.1.0",
|
|
53
|
+
"mocha": "^10.2.0",
|
|
54
|
+
"node-abort-controller": "^3.0.1",
|
|
55
|
+
"prettier": "^2.8.1",
|
|
56
|
+
"ts-node": "^10.9.1",
|
|
57
|
+
"typescript": "^4.9.4"
|
|
52
58
|
}
|
|
53
59
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// playwright.config.ts
|
|
2
|
+
import type { PlaywrightTestConfig } from '@playwright/test'
|
|
3
|
+
|
|
4
|
+
const config: PlaywrightTestConfig = {
|
|
5
|
+
testDir: 'test/playwright',
|
|
6
|
+
use: {
|
|
7
|
+
browserName: 'chromium',
|
|
8
|
+
headless: true,
|
|
9
|
+
},
|
|
10
|
+
workers: 3,
|
|
11
|
+
webServer: [
|
|
12
|
+
{
|
|
13
|
+
command: 'dist/cli.js serve test/data/style.yml --port 8080',
|
|
14
|
+
port: 8080,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
command:
|
|
18
|
+
'dist/cli.js serve test/data/style.yml --provider geolonia --port 8088',
|
|
19
|
+
port: 8088,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
command:
|
|
23
|
+
'dist/cli.js serve test/data/style.yml --provider mapbox --port 8888 --mapbox-access-token ' +
|
|
24
|
+
process.env.MAPBOX_ACCESS_TOKEN,
|
|
25
|
+
port: 8888,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
}
|
|
29
|
+
export default config
|
package/provider/default/app.js
CHANGED
|
@@ -1,50 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
;(async () => {
|
|
2
|
+
const { style, center, zoom } = await window._charites.parseMapStyle()
|
|
3
|
+
const options = {
|
|
4
|
+
container: 'map',
|
|
5
|
+
hash: true,
|
|
6
|
+
style,
|
|
7
|
+
}
|
|
8
|
+
if (center) options.center = center
|
|
9
|
+
if (zoom) options.zoom = zoom
|
|
10
|
+
const map = new maplibregl.Map(options)
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
window._charites.initializeWebSocket(map)
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
map.setStyle(JSON.parse(message.data))
|
|
11
|
-
})
|
|
14
|
+
map.addControl(new maplibregl.NavigationControl(), 'top-right')
|
|
12
15
|
|
|
13
|
-
map.addControl(
|
|
16
|
+
map.addControl(
|
|
17
|
+
new MaplibreLegendControl(
|
|
18
|
+
{},
|
|
19
|
+
{
|
|
20
|
+
showDefault: true,
|
|
21
|
+
showCheckbox: true,
|
|
22
|
+
onlyRendered: true,
|
|
23
|
+
reverseOrder: true,
|
|
24
|
+
},
|
|
25
|
+
),
|
|
26
|
+
'bottom-left',
|
|
27
|
+
)
|
|
14
28
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{},
|
|
18
|
-
{
|
|
19
|
-
showDefault: true,
|
|
20
|
-
showCheckbox: true,
|
|
21
|
-
onlyRendered: true,
|
|
22
|
-
reverseOrder: true,
|
|
23
|
-
},
|
|
24
|
-
),
|
|
25
|
-
'bottom-left',
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
const showTileBoundaries = document.getElementById('showTileBoundaries')
|
|
29
|
-
const setShowTileBoundaries = function () {
|
|
30
|
-
const checked = showTileBoundaries.checked
|
|
31
|
-
map.showTileBoundaries = checked
|
|
32
|
-
}
|
|
33
|
-
setShowTileBoundaries()
|
|
34
|
-
showTileBoundaries.addEventListener('click', setShowTileBoundaries)
|
|
35
|
-
|
|
36
|
-
const showCollisionBoxes = document.getElementById('showCollisionBoxes')
|
|
37
|
-
const setShowCollisionBoxes = function () {
|
|
38
|
-
const checked = showCollisionBoxes.checked
|
|
39
|
-
map.showCollisionBoxes = checked
|
|
40
|
-
}
|
|
41
|
-
setShowCollisionBoxes()
|
|
42
|
-
showCollisionBoxes.addEventListener('click', setShowCollisionBoxes)
|
|
43
|
-
|
|
44
|
-
const showPadding = document.getElementById('showPadding')
|
|
45
|
-
const setShowPadding = function () {
|
|
46
|
-
const checked = showPadding.checked
|
|
47
|
-
map.showPadding = checked
|
|
48
|
-
}
|
|
49
|
-
setShowPadding()
|
|
50
|
-
showPadding.addEventListener('click', setShowPadding)
|
|
29
|
+
window._charites.setupDebugCheckboxes(map)
|
|
30
|
+
})()
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
2
|
+
<html id="charites-default">
|
|
3
3
|
<head>
|
|
4
4
|
<link rel="stylesheet" href="/app.css" />
|
|
5
|
-
<link href='https://unpkg.com/maplibre-gl@
|
|
5
|
+
<link href='https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css' rel='stylesheet' />
|
|
6
6
|
<link href='https://watergis.github.io/maplibre-gl-legend/maplibre-gl-legend.css' rel='stylesheet' />
|
|
7
7
|
<title>Charites Live Preview</title>
|
|
8
|
-
<script src='https://unpkg.com/maplibre-gl@
|
|
8
|
+
<script src='https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js'></script>
|
|
9
9
|
<script src="https://watergis.github.io/maplibre-gl-legend/maplibre-gl-legend.js"></script>
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
<label><input type="checkbox" id="showPadding">show Padding</label>
|
|
18
18
|
</div>
|
|
19
19
|
<div id="map"></div>
|
|
20
|
+
<script type="text/javascript" src="/shared.js"></script>
|
|
20
21
|
<script type="text/javascript" src="/app.js"></script>
|
|
21
22
|
</body>
|
|
22
23
|
</html>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
;(async () => {
|
|
2
|
+
window._charites = {
|
|
3
|
+
initializeWebSocket: function (map) {
|
|
4
|
+
const socket = new WebSocket(`ws://${window.location.host}`)
|
|
5
|
+
|
|
6
|
+
socket.addEventListener('message', (message) => {
|
|
7
|
+
const data = JSON.parse(message.data)
|
|
8
|
+
if (data.event === 'styleUpdate') {
|
|
9
|
+
map.setStyle(`http://${window.location.host}/style.json`)
|
|
10
|
+
} else if (data.event === 'spriteUpdate') {
|
|
11
|
+
map.setStyle(`http://${window.location.host}/style.json`, {
|
|
12
|
+
diff: false,
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
},
|
|
17
|
+
parseMapStyle: async function () {
|
|
18
|
+
const mapStyleUrl = `http://${window.location.host}/style.json`
|
|
19
|
+
const mapStyleRes = await fetch(mapStyleUrl)
|
|
20
|
+
const mapStyleJson = await mapStyleRes.json()
|
|
21
|
+
|
|
22
|
+
// detect center & zoom from map style json
|
|
23
|
+
let center = mapStyleJson.hasOwnProperty('center')
|
|
24
|
+
? mapStyleJson.center
|
|
25
|
+
: undefined
|
|
26
|
+
let zoom = mapStyleJson.hasOwnProperty('zoom')
|
|
27
|
+
? mapStyleJson.zoom
|
|
28
|
+
: undefined
|
|
29
|
+
|
|
30
|
+
// detect center & zoom from tile json
|
|
31
|
+
if (center === undefined || zoom === undefined) {
|
|
32
|
+
for (const sourceName in mapStyleJson.sources) {
|
|
33
|
+
if (
|
|
34
|
+
mapStyleJson.sources[sourceName].type === 'vector' &&
|
|
35
|
+
mapStyleJson.sources[sourceName].hasOwnProperty('url')
|
|
36
|
+
) {
|
|
37
|
+
const mapTileUrl = mapStyleJson.sources[sourceName].url
|
|
38
|
+
const mapTileRes = await fetch(mapTileUrl)
|
|
39
|
+
const mapTileJson = await mapTileRes.json()
|
|
40
|
+
if (center === undefined) {
|
|
41
|
+
const bounds = mapTileJson.bounds
|
|
42
|
+
center = mapTileJson.center
|
|
43
|
+
? mapTileJson.center
|
|
44
|
+
: [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2]
|
|
45
|
+
}
|
|
46
|
+
if (zoom === undefined) {
|
|
47
|
+
zoom = (mapTileJson.minzoom + mapTileJson.maxzoom) / 2
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
style: mapStyleUrl,
|
|
55
|
+
center,
|
|
56
|
+
zoom,
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
setupDebugCheckboxes: function (map) {
|
|
60
|
+
const properties = [
|
|
61
|
+
'showTileBoundaries',
|
|
62
|
+
'showCollisionBoxes',
|
|
63
|
+
'showPadding',
|
|
64
|
+
]
|
|
65
|
+
for (const property of properties) {
|
|
66
|
+
const control = document.getElementById(property)
|
|
67
|
+
const clickHandler = function () {
|
|
68
|
+
const checked = control.checked
|
|
69
|
+
map[property] = checked
|
|
70
|
+
}
|
|
71
|
+
clickHandler()
|
|
72
|
+
control.addEventListener('click', clickHandler)
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
})()
|
package/provider/geolonia/app.js
CHANGED
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
;(async () => {
|
|
2
|
+
const { style, center, zoom } = await window._charites.parseMapStyle()
|
|
3
|
+
const options = {
|
|
4
|
+
container: 'map',
|
|
5
|
+
hash: true,
|
|
6
|
+
style,
|
|
7
|
+
}
|
|
8
|
+
if (center) options.center = center
|
|
9
|
+
if (zoom) options.zoom = zoom
|
|
10
|
+
const map = new geolonia.Map(options)
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
window._charites.initializeWebSocket(map)
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
14
|
+
map.addControl(
|
|
15
|
+
new MaplibreLegendControl(
|
|
16
|
+
{},
|
|
17
|
+
{
|
|
18
|
+
showDefault: true,
|
|
19
|
+
showCheckbox: true,
|
|
20
|
+
onlyRendered: true,
|
|
21
|
+
reverseOrder: true,
|
|
22
|
+
},
|
|
23
|
+
),
|
|
24
|
+
'bottom-left',
|
|
25
|
+
)
|
|
12
26
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const checked = showTileBoundaries.checked
|
|
16
|
-
map.showTileBoundaries = checked
|
|
17
|
-
}
|
|
18
|
-
setShowTileBoundaries()
|
|
19
|
-
showTileBoundaries.addEventListener('click', setShowTileBoundaries)
|
|
20
|
-
|
|
21
|
-
const showCollisionBoxes = document.getElementById('showCollisionBoxes')
|
|
22
|
-
const setShowCollisionBoxes = function () {
|
|
23
|
-
const checked = showCollisionBoxes.checked
|
|
24
|
-
map.showCollisionBoxes = checked
|
|
25
|
-
}
|
|
26
|
-
setShowCollisionBoxes()
|
|
27
|
-
showCollisionBoxes.addEventListener('click', setShowCollisionBoxes)
|
|
28
|
-
|
|
29
|
-
const showPadding = document.getElementById('showPadding')
|
|
30
|
-
const setShowPadding = function () {
|
|
31
|
-
const checked = showPadding.checked
|
|
32
|
-
map.showPadding = checked
|
|
33
|
-
}
|
|
34
|
-
setShowPadding()
|
|
35
|
-
showPadding.addEventListener('click', setShowPadding)
|
|
27
|
+
window._charites.setupDebugCheckboxes(map)
|
|
28
|
+
})()
|