@geolonia/maps-core 0.6.0 → 0.7.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/README.md +23 -0
- package/dist/npm/index.d.ts +15 -2
- package/dist/npm/index.js +63 -39
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -183,6 +183,29 @@ new GeoloniaMap({ container: '#map', errorMessage: 'Sorry, the map is unavailabl
|
|
|
183
183
|
new GeoloniaMap({ container: '#map', errorMessage: false });
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
+
#### `transformRequest`
|
|
187
|
+
|
|
188
|
+
Works like MapLibre's `transformRequest`, and is also called for the requests that maps-core rewrites itself: Geolonia sources (`api.geolonia.com` and the Geolonia tile hosts) and Geolonia sprites. For those, the function receives the URL after maps-core has added `key` and `sessionId`, so the parameters are kept as long as you build on the URL you are given.
|
|
189
|
+
|
|
190
|
+
- Return a `RequestParameters` object to use it as is.
|
|
191
|
+
- Return `undefined` to keep the request maps-core built.
|
|
192
|
+
- A `Promise` may be returned. If it resolves to `undefined`, the request maps-core built is used.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
new GeoloniaMap({
|
|
196
|
+
container: '#map',
|
|
197
|
+
transformRequest: (url, resourceType) => {
|
|
198
|
+
// Load another tileset from the Geolonia tile server
|
|
199
|
+
if (resourceType === 'Source' && url.includes('tileserver.geolonia.com/oneself/')) {
|
|
200
|
+
return { url: url.replace('/oneself/', '/my-tileset/') };
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Replacing the function later with `map.setTransformRequest()` also removes the maps-core rewriting, including `key` and `sessionId`.
|
|
208
|
+
|
|
186
209
|
### `GeoloniaMarker`
|
|
187
210
|
|
|
188
211
|
Extends `maplibregl.Marker` with Geolonia's default marker style.
|
package/dist/npm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as maplibregl from 'maplibre-gl';
|
|
2
|
-
import { IControl, ControlPosition, Map, MapOptions, ExpiryData, StyleSpecification, StyleSwapOptions, StyleOptions, GetResourceResponse, MarkerOptions } from 'maplibre-gl';
|
|
2
|
+
import { IControl, ControlPosition, Map, MapOptions, RequestTransformFunction, ExpiryData, StyleSpecification, StyleSwapOptions, StyleOptions, GetResourceResponse, MarkerOptions } from 'maplibre-gl';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Shadow DOM を用いたカスタム帰属表示コントロールの実装です。
|
|
@@ -162,7 +162,8 @@ type GeoloniaMapOptions = MapOptions & {
|
|
|
162
162
|
apiKey?: string;
|
|
163
163
|
/**
|
|
164
164
|
* API のステージ(`'dev'` / `'v1'` など)。API エンドポイントの選択に使う。
|
|
165
|
-
*
|
|
165
|
+
* 省略時は共有キーリングの現在のステージを使う。別の地図が `stage` を指定してキーリングを変更済みの場合は、その値になる。
|
|
166
|
+
* @defaultValue `'v1'`(キーリングの初期値)
|
|
166
167
|
*/
|
|
167
168
|
stage?: string;
|
|
168
169
|
/**
|
|
@@ -171,6 +172,18 @@ type GeoloniaMapOptions = MapOptions & {
|
|
|
171
172
|
* @defaultValue `'geolonia/basic-v2'`
|
|
172
173
|
*/
|
|
173
174
|
style?: string;
|
|
175
|
+
/**
|
|
176
|
+
* リクエストを送る直前に URL やヘッダーを書き換える関数。MapLibre の `transformRequest` と同じ形。
|
|
177
|
+
*
|
|
178
|
+
* Geolonia のソース(`api.geolonia.com` と Geolonia のタイルホスト)とスプライトのリクエストでは、
|
|
179
|
+
* maps-core が `key` や `sessionId` を付けた後の URL が渡される。
|
|
180
|
+
* `undefined` を返すと maps-core の変換結果がそのまま使われる。
|
|
181
|
+
* Promise を返してもよい。解決値が `undefined` のときも maps-core の変換結果が使われる。
|
|
182
|
+
*
|
|
183
|
+
* `map.setTransformRequest()` で差し替えると maps-core の変換も外れる。後から変えるときは、
|
|
184
|
+
* maps-core が付ける `key` や `sessionId` を自分で付ける必要がある。
|
|
185
|
+
*/
|
|
186
|
+
transformRequest?: RequestTransformFunction | null;
|
|
174
187
|
/**
|
|
175
188
|
* ラベルの言語。`'ja'` / `'en'` / `'auto'`(ブラウザ言語に従う)。
|
|
176
189
|
* `'auto'` または未指定のときは `getLang()` の結果(`'ja'` または `'en'`)になる。
|
package/dist/npm/index.js
CHANGED
|
@@ -1684,6 +1684,61 @@ function normalizeConstructorArg(arg) {
|
|
|
1684
1684
|
return arg;
|
|
1685
1685
|
}
|
|
1686
1686
|
|
|
1687
|
+
// src/lib/transform-request.ts
|
|
1688
|
+
function transformGeoloniaRequest(url, resourceType, { apiKey, stage, sessionId: sessionId2, sourcesUrl }) {
|
|
1689
|
+
if (resourceType === "Source" && url.startsWith("https://api.geolonia.com")) {
|
|
1690
|
+
return { url: sourcesUrl, request: { url: sourcesUrl } };
|
|
1691
|
+
}
|
|
1692
|
+
let transformedUrl = url;
|
|
1693
|
+
if (url.startsWith("geolonia://")) {
|
|
1694
|
+
const tilesMatch = url.match(
|
|
1695
|
+
/^geolonia:\/\/tiles\/(?<username>.+)\/(?<customtileId>.+)/
|
|
1696
|
+
);
|
|
1697
|
+
if (tilesMatch?.groups) {
|
|
1698
|
+
transformedUrl = `https://tileserver.geolonia.com/customtiles/${tilesMatch.groups.customtileId}/tiles.json`;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
const transformedUrlObj = new URL(transformedUrl);
|
|
1702
|
+
const geoloniaTilesHost = isGeoloniaTilesHost(transformedUrlObj);
|
|
1703
|
+
if (resourceType === "Source" && geoloniaTilesHost) {
|
|
1704
|
+
if (stage === "dev" && transformedUrlObj.hostname === "tileserver.geolonia.com") {
|
|
1705
|
+
transformedUrlObj.hostname = "tileserver-dev.geolonia.com";
|
|
1706
|
+
}
|
|
1707
|
+
transformedUrlObj.searchParams.set("sessionId", sessionId2);
|
|
1708
|
+
transformedUrlObj.searchParams.set("key", apiKey);
|
|
1709
|
+
const transformed = transformedUrlObj.toString();
|
|
1710
|
+
return { url: transformed, request: { url: transformed } };
|
|
1711
|
+
}
|
|
1712
|
+
if ((resourceType === "SpriteJSON" || resourceType === "SpriteImage") && transformedUrl.match(/^https:\/\/api\.geolonia\.com\/(dev|v1)\/sprites\//)) {
|
|
1713
|
+
const pathParts = transformedUrlObj.pathname.split("/");
|
|
1714
|
+
pathParts[1] = stage;
|
|
1715
|
+
transformedUrlObj.pathname = pathParts.join("/");
|
|
1716
|
+
transformedUrlObj.searchParams.set("key", apiKey);
|
|
1717
|
+
const transformed = transformedUrlObj.toString();
|
|
1718
|
+
return { url: transformed, request: { url: transformed } };
|
|
1719
|
+
}
|
|
1720
|
+
return { url: transformedUrl };
|
|
1721
|
+
}
|
|
1722
|
+
function isThenable(value) {
|
|
1723
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
1724
|
+
}
|
|
1725
|
+
function createTransformRequest(context) {
|
|
1726
|
+
const { userTransformRequest } = context;
|
|
1727
|
+
return (url, resourceType) => {
|
|
1728
|
+
const core = transformGeoloniaRequest(url, resourceType, context);
|
|
1729
|
+
if (typeof userTransformRequest !== "function") {
|
|
1730
|
+
return core.request;
|
|
1731
|
+
}
|
|
1732
|
+
const userResult = userTransformRequest(core.url, resourceType);
|
|
1733
|
+
if (isThenable(userResult)) {
|
|
1734
|
+
return Promise.resolve(userResult).then(
|
|
1735
|
+
(resolved) => resolved ?? core.request ?? { url: core.url }
|
|
1736
|
+
);
|
|
1737
|
+
}
|
|
1738
|
+
return userResult ?? core.request;
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1687
1742
|
// src/lib/geolonia-map.ts
|
|
1688
1743
|
var pmtilesRegistered = false;
|
|
1689
1744
|
function ensurePMTiles() {
|
|
@@ -1756,44 +1811,13 @@ var GeoloniaMap = class extends maplibregl5.Map {
|
|
|
1756
1811
|
const sourcesUrl = new URL(`${apiUrl}/sources`);
|
|
1757
1812
|
sourcesUrl.searchParams.set("key", apiKey);
|
|
1758
1813
|
sourcesUrl.searchParams.set("sessionId", sessionId2);
|
|
1759
|
-
const
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
const tilesMatch = url.match(
|
|
1767
|
-
/^geolonia:\/\/tiles\/(?<username>.+)\/(?<customtileId>.+)/
|
|
1768
|
-
);
|
|
1769
|
-
if (tilesMatch?.groups) {
|
|
1770
|
-
transformedUrl = `https://tileserver.geolonia.com/customtiles/${tilesMatch.groups.customtileId}/tiles.json`;
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
const transformedUrlObj = new URL(transformedUrl);
|
|
1774
|
-
const geoloniaTilesHost = isGeoloniaTilesHost(transformedUrlObj);
|
|
1775
|
-
if (resourceType === "Source" && geoloniaTilesHost) {
|
|
1776
|
-
if (stage === "dev" && transformedUrlObj.hostname === "tileserver.geolonia.com") {
|
|
1777
|
-
transformedUrlObj.hostname = "tileserver-dev.geolonia.com";
|
|
1778
|
-
}
|
|
1779
|
-
transformedUrlObj.searchParams.set("sessionId", sessionId2);
|
|
1780
|
-
transformedUrlObj.searchParams.set("key", apiKey);
|
|
1781
|
-
return { url: transformedUrlObj.toString() };
|
|
1782
|
-
}
|
|
1783
|
-
if ((resourceType === "SpriteJSON" || resourceType === "SpriteImage") && transformedUrl.match(
|
|
1784
|
-
/^https:\/\/api\.geolonia\.com\/(dev|v1)\/sprites\//
|
|
1785
|
-
)) {
|
|
1786
|
-
const pathParts = transformedUrlObj.pathname.split("/");
|
|
1787
|
-
pathParts[1] = stage;
|
|
1788
|
-
transformedUrlObj.pathname = pathParts.join("/");
|
|
1789
|
-
transformedUrlObj.searchParams.set("key", apiKey);
|
|
1790
|
-
return { url: transformedUrlObj.toString() };
|
|
1791
|
-
}
|
|
1792
|
-
if (typeof userTransformRequest === "function") {
|
|
1793
|
-
return userTransformRequest(transformedUrl, resourceType);
|
|
1794
|
-
}
|
|
1795
|
-
return void 0;
|
|
1796
|
-
};
|
|
1814
|
+
const transformRequest = createTransformRequest({
|
|
1815
|
+
apiKey,
|
|
1816
|
+
stage,
|
|
1817
|
+
sessionId: sessionId2,
|
|
1818
|
+
sourcesUrl: sourcesUrl.toString(),
|
|
1819
|
+
userTransformRequest: options.transformRequest
|
|
1820
|
+
});
|
|
1797
1821
|
let loading;
|
|
1798
1822
|
const showLoader = options.loader !== false;
|
|
1799
1823
|
if (showLoader) {
|
|
@@ -2055,7 +2079,7 @@ var GeoloniaMap = class extends maplibregl5.Map {
|
|
|
2055
2079
|
};
|
|
2056
2080
|
|
|
2057
2081
|
// src/version.ts
|
|
2058
|
-
var VERSION = "0.
|
|
2082
|
+
var VERSION = "0.7.0";
|
|
2059
2083
|
export {
|
|
2060
2084
|
attribution_default as CustomAttributionControl,
|
|
2061
2085
|
DEFAULT_STAGE,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/maps-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "dist/npm/index.js",
|
|
6
6
|
"types": "dist/npm/index.d.ts",
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
"maplibre-gl": "^6.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@biomejs/biome": "^2.
|
|
31
|
-
"@playwright/test": "^1.
|
|
30
|
+
"@biomejs/biome": "^2.5.14",
|
|
31
|
+
"@playwright/test": "^1.63.0",
|
|
32
32
|
"@types/sanitize-html": "^2.16.1",
|
|
33
33
|
"@types/tinycolor2": "^1.4.6",
|
|
34
|
-
"@vitest/coverage-v8": "^5.0.
|
|
35
|
-
"esbuild": "^0.28.
|
|
36
|
-
"jsdom": "^
|
|
37
|
-
"maplibre-gl": "6.
|
|
34
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
35
|
+
"esbuild": "^0.28.2",
|
|
36
|
+
"jsdom": "^30.1.1",
|
|
37
|
+
"maplibre-gl": "6.11.2",
|
|
38
38
|
"tsup": "^8",
|
|
39
39
|
"typedoc": "^0.28.20",
|
|
40
|
-
"typedoc-plugin-markdown": "^4.
|
|
40
|
+
"typedoc-plugin-markdown": "^4.13.1",
|
|
41
41
|
"typescript": "^5.8",
|
|
42
|
-
"vite": "^8.1
|
|
42
|
+
"vite": "^8.3.1",
|
|
43
43
|
"vitest": "^5.0.2"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|