@geolonia/maps-core 0.4.2 → 0.4.3
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/dist/npm/index.cjs +370 -12
- package/dist/npm/index.d.cts +680 -43
- package/dist/npm/index.d.ts +680 -43
- package/dist/npm/index.js +370 -12
- package/package.json +8 -2
package/dist/npm/index.cjs
CHANGED
|
@@ -272,6 +272,11 @@ var ATTRIBUTION_CSS = `
|
|
|
272
272
|
}
|
|
273
273
|
`;
|
|
274
274
|
var CustomAttributionControl = class {
|
|
275
|
+
/**
|
|
276
|
+
* コントロールを生成します。
|
|
277
|
+
*
|
|
278
|
+
* @param options 帰属表示の挙動を指定するオプションです。省略した場合は空のオブジェクトが使われます。
|
|
279
|
+
*/
|
|
275
280
|
constructor(options = {}) {
|
|
276
281
|
this.options = options;
|
|
277
282
|
bindAll(
|
|
@@ -284,9 +289,24 @@ var CustomAttributionControl = class {
|
|
|
284
289
|
this
|
|
285
290
|
);
|
|
286
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* このコントロールの既定の表示位置を返します。
|
|
294
|
+
*
|
|
295
|
+
* @returns 既定の表示位置である `"bottom-right"` を返します。
|
|
296
|
+
*/
|
|
287
297
|
getDefaultPosition() {
|
|
288
298
|
return "bottom-right";
|
|
289
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* コントロールが地図に追加されるときに呼び出されます。
|
|
302
|
+
*
|
|
303
|
+
* Shadow DOM を持つコンテナ要素を生成し、その内部に帰属表示用の要素と CSS を組み立てます。
|
|
304
|
+
* あわせて帰属表示の内容を初期化し、地図の各種イベント(`styledata`、`sourcedata`、`terrain`、
|
|
305
|
+
* `resize`、`drag`)や印刷メディアクエリの変化を監視するリスナーを登録します。
|
|
306
|
+
*
|
|
307
|
+
* @param map このコントロールを追加する対象の地図です。
|
|
308
|
+
* @returns 地図に挿入するコントロールのルート要素を返します。
|
|
309
|
+
*/
|
|
290
310
|
onAdd(map) {
|
|
291
311
|
this._map = map;
|
|
292
312
|
this._compact = this.options.compact;
|
|
@@ -329,6 +349,12 @@ var CustomAttributionControl = class {
|
|
|
329
349
|
this.printQuery.addEventListener("change", this.onMediaPrintChange);
|
|
330
350
|
return this._container;
|
|
331
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* コントロールが地図から取り除かれるときに呼び出されます。
|
|
354
|
+
*
|
|
355
|
+
* 生成したコンテナ要素を DOM から削除し、`onAdd` で登録した地図のイベントリスナーと
|
|
356
|
+
* 印刷メディアクエリのリスナーを解除したうえで、内部で保持している状態を破棄します。
|
|
357
|
+
*/
|
|
332
358
|
onRemove() {
|
|
333
359
|
if (this._container) {
|
|
334
360
|
DOM.remove(this._container);
|
|
@@ -450,6 +476,14 @@ var attribution_default = CustomAttributionControl;
|
|
|
450
476
|
|
|
451
477
|
// src/lib/controls/geolonia-logo.ts
|
|
452
478
|
var GeoloniaControl = class {
|
|
479
|
+
/**
|
|
480
|
+
* コントロールの DOM 要素を生成して返します。
|
|
481
|
+
*
|
|
482
|
+
* `IControl` の実装として、`Map.addControl` で地図に追加された際に MapLibre から呼び出されます。
|
|
483
|
+
* Geolonia のロゴ画像を含み、`https://geolonia.com/` へのリンクが設定された要素を組み立てて返します。
|
|
484
|
+
*
|
|
485
|
+
* @returns このコントロールのコンテナとなる `HTMLDivElement`。
|
|
486
|
+
*/
|
|
453
487
|
onAdd() {
|
|
454
488
|
this.container = document.createElement("div");
|
|
455
489
|
this.container.className = "maplibregl-ctrl";
|
|
@@ -470,9 +504,22 @@ var GeoloniaControl = class {
|
|
|
470
504
|
this.container.appendChild(link);
|
|
471
505
|
return this.container;
|
|
472
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* コントロールの DOM 要素を地図から除去します。
|
|
509
|
+
*
|
|
510
|
+
* `IControl` の実装として、`Map.removeControl` で地図から取り除かれた際に MapLibre から呼び出されます。
|
|
511
|
+
* `onAdd` で生成したコンテナを親ノードから削除します。
|
|
512
|
+
*/
|
|
473
513
|
onRemove() {
|
|
474
514
|
this.container.parentNode?.removeChild(this.container);
|
|
475
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* このコントロールの既定の表示位置を返します。
|
|
518
|
+
*
|
|
519
|
+
* `Map.addControl` で位置を明示しなかった場合に使用されます。
|
|
520
|
+
*
|
|
521
|
+
* @returns 既定の表示位置 `"bottom-left"`。
|
|
522
|
+
*/
|
|
476
523
|
getDefaultPosition() {
|
|
477
524
|
return "bottom-left";
|
|
478
525
|
}
|
|
@@ -492,6 +539,19 @@ var MARKER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 67">
|
|
|
492
539
|
</svg>`;
|
|
493
540
|
var DEFAULT_COLOR = "#E4402F";
|
|
494
541
|
var GeoloniaMarker = class extends import_maplibre_gl2.default.Marker {
|
|
542
|
+
/**
|
|
543
|
+
* Geolonia マーカーを作成します。
|
|
544
|
+
*
|
|
545
|
+
* `options.element` が指定されていない場合は、Geolonia デフォルトの SVG マーカー
|
|
546
|
+
* 要素を生成して `options.element` に設定し、`options.color`(未指定時は `#E4402F`)で
|
|
547
|
+
* マーカーの色を適用したうえで、`options.offset` を `[0, -15]` に設定します。
|
|
548
|
+
* `options.element` が指定されている場合は、これらの処理を行わず指定された要素を
|
|
549
|
+
* そのまま使用します。
|
|
550
|
+
*
|
|
551
|
+
* @param options `maplibregl.Marker` の `MarkerOptions` です。`element` を省略すると
|
|
552
|
+
* Geolonia デフォルトのマーカーが生成され、`color` でその色を指定できます。
|
|
553
|
+
* 省略した場合は空のオブジェクトが使われます。
|
|
554
|
+
*/
|
|
495
555
|
constructor(options = {}) {
|
|
496
556
|
if (!options.element) {
|
|
497
557
|
const markerElement = document.createElement("div");
|
|
@@ -531,31 +591,83 @@ var Keyring = class {
|
|
|
531
591
|
__privateAdd(this, _stage, "dev");
|
|
532
592
|
__privateAdd(this, _isGeoloniaStyle, true);
|
|
533
593
|
}
|
|
594
|
+
/**
|
|
595
|
+
* 現在設定されている API キーを返します。
|
|
596
|
+
*
|
|
597
|
+
* 未設定の場合は空文字列を返します。
|
|
598
|
+
*
|
|
599
|
+
* @returns API キーの文字列を返します。
|
|
600
|
+
*/
|
|
534
601
|
get apiKey() {
|
|
535
602
|
return __privateGet(this, _apiKey);
|
|
536
603
|
}
|
|
604
|
+
/**
|
|
605
|
+
* 現在設定されているステージを返します。
|
|
606
|
+
*
|
|
607
|
+
* 初期値は `"dev"` です。
|
|
608
|
+
*
|
|
609
|
+
* @returns ステージを表す文字列を返します。
|
|
610
|
+
*/
|
|
537
611
|
get stage() {
|
|
538
612
|
return __privateGet(this, _stage);
|
|
539
613
|
}
|
|
614
|
+
/**
|
|
615
|
+
* 現在のスタイルが Geolonia スタイル(API キーが必要なスタイル)かどうかを返します。
|
|
616
|
+
*
|
|
617
|
+
* @returns Geolonia スタイルの場合は `true`、それ以外の場合は `false` を返します。
|
|
618
|
+
*/
|
|
540
619
|
get isGeoloniaStyle() {
|
|
541
620
|
return __privateGet(this, _isGeoloniaStyle);
|
|
542
621
|
}
|
|
622
|
+
/**
|
|
623
|
+
* 現在のスタイルが Geolonia スタイルかどうかを設定します。
|
|
624
|
+
*
|
|
625
|
+
* @param value Geolonia スタイルとして扱う場合は `true`、それ以外の場合は `false` を指定します。
|
|
626
|
+
*/
|
|
543
627
|
set isGeoloniaStyle(value) {
|
|
544
628
|
__privateSet(this, _isGeoloniaStyle, value);
|
|
545
629
|
}
|
|
630
|
+
/**
|
|
631
|
+
* API キーを設定します。
|
|
632
|
+
*
|
|
633
|
+
* @param key 設定する API キーの文字列を指定します。
|
|
634
|
+
*/
|
|
546
635
|
setApiKey(key) {
|
|
547
636
|
__privateSet(this, _apiKey, key);
|
|
548
637
|
}
|
|
638
|
+
/**
|
|
639
|
+
* ステージを設定します。
|
|
640
|
+
*
|
|
641
|
+
* @param stage 設定するステージの文字列を指定します。
|
|
642
|
+
*/
|
|
549
643
|
setStage(stage) {
|
|
550
644
|
__privateSet(this, _stage, stage);
|
|
551
645
|
}
|
|
646
|
+
/**
|
|
647
|
+
* API キー、ステージ、Geolonia スタイル判定をすべて初期状態に戻します。
|
|
648
|
+
*
|
|
649
|
+
* API キーは空文字列、ステージは `"dev"`、Geolonia スタイル判定は `true` にリセットされます。
|
|
650
|
+
*/
|
|
552
651
|
reset() {
|
|
553
652
|
__privateSet(this, _apiKey, "");
|
|
554
653
|
__privateSet(this, _stage, "dev");
|
|
555
654
|
__privateSet(this, _isGeoloniaStyle, true);
|
|
556
655
|
}
|
|
557
656
|
/**
|
|
558
|
-
*
|
|
657
|
+
* 与えられたスタイルが Geolonia スタイル(API キーが必要なスタイル)かどうかを判定します。
|
|
658
|
+
*
|
|
659
|
+
* 判定は次のロジックで行われます。
|
|
660
|
+
*
|
|
661
|
+
* - 空文字列(未指定)の場合は `true` を返します。
|
|
662
|
+
* - `https://cdn.geolonia.com/style/` または `https://api.geolonia.com/` で始まる URL の場合は `true` を返します。
|
|
663
|
+
* - 上記以外で `http://` または `https://` で始まる外部 URL の場合は `false` を返します。
|
|
664
|
+
* - `geolonia://` で始まる場合は Geolonia 独自プロトコルのため `true` を返します。
|
|
665
|
+
* - それ以外のプロトコル(`xxx://` 形式)で始まる場合は `false` を返します。
|
|
666
|
+
* - `.json` で終わる場合は `false` を返します。
|
|
667
|
+
* - 上記のいずれにも該当しない場合は、`geolonia/basic` のような Geolonia の論理名とみなして `true` を返します。
|
|
668
|
+
*
|
|
669
|
+
* @param style 判定対象のスタイル(URL、プロトコル付き文字列、または論理名)を指定します。
|
|
670
|
+
* @returns Geolonia スタイルの場合は `true`、それ以外の場合は `false` を返します。
|
|
559
671
|
*/
|
|
560
672
|
isGeoloniaStyleCheck(style) {
|
|
561
673
|
if (!style || style === "") {
|
|
@@ -718,6 +830,16 @@ var template = {
|
|
|
718
830
|
features: []
|
|
719
831
|
};
|
|
720
832
|
var SimpleStyle = class {
|
|
833
|
+
/**
|
|
834
|
+
* SimpleStyle を作成します。
|
|
835
|
+
*
|
|
836
|
+
* `geojson` に URL 文字列を渡した場合は、その URL から GeoJSON を非同期に取得します。
|
|
837
|
+
* 取得の完了は `_loadingPromise` で待つことができます。
|
|
838
|
+
*
|
|
839
|
+
* @param geojson 表示する GeoJSON です。{@link FeatureCollection} または GeoJSON を返す URL 文字列を指定します。
|
|
840
|
+
* @param options 表示オプションです。指定した項目のみが既定値を上書きします。既定値は
|
|
841
|
+
* `id: "geolonia-simple-style"`、`cluster: true`、`heatmap: false`、`clusterColor: "#ff0000"` です。
|
|
842
|
+
*/
|
|
721
843
|
constructor(geojson, options) {
|
|
722
844
|
this.callFitBounds = false;
|
|
723
845
|
this._eventHandlers = [];
|
|
@@ -731,6 +853,16 @@ var SimpleStyle = class {
|
|
|
731
853
|
...options
|
|
732
854
|
};
|
|
733
855
|
}
|
|
856
|
+
/**
|
|
857
|
+
* 表示中のデータを新しい GeoJSON で差し替えます。
|
|
858
|
+
*
|
|
859
|
+
* フィーチャーをポイントとそれ以外(ポリゴン、ライン)に振り分け、
|
|
860
|
+
* それぞれ対応するソースの内容を更新します。レイヤー自体の追加は行わないため、
|
|
861
|
+
* あらかじめ {@link SimpleStyle.addTo | addTo} で地図に追加されている必要があります。
|
|
862
|
+
*
|
|
863
|
+
* @param geojson 差し替える {@link FeatureCollection} です。
|
|
864
|
+
* @returns メソッドチェーンのための `this` を返します。
|
|
865
|
+
*/
|
|
734
866
|
updateData(geojson) {
|
|
735
867
|
this.setGeoJSON(geojson);
|
|
736
868
|
const features = this.geojson.features;
|
|
@@ -752,6 +884,24 @@ var SimpleStyle = class {
|
|
|
752
884
|
);
|
|
753
885
|
return this;
|
|
754
886
|
}
|
|
887
|
+
/**
|
|
888
|
+
* 地図にソースとレイヤーを追加して GeoJSON を表示します。
|
|
889
|
+
*
|
|
890
|
+
* ポリゴンとラインのソース、ポイント用のソース(クラスタリング設定付き)を追加し、
|
|
891
|
+
* ポリゴンとラインのラベル用シンボルレイヤーを配置したうえで、
|
|
892
|
+
* {@link SimpleStyle.setPolygonGeometries | setPolygonGeometries}、
|
|
893
|
+
* {@link SimpleStyle.setLineGeometries | setLineGeometries}、
|
|
894
|
+
* {@link SimpleStyle.setPointGeometries | setPointGeometries}、
|
|
895
|
+
* {@link SimpleStyle.setCluster | setCluster} を呼び出して各ジオメトリのレイヤーを設定します。
|
|
896
|
+
*
|
|
897
|
+
* @param map 表示先の地図です。
|
|
898
|
+
* @returns メソッドチェーンのための `this` を返します。
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```typescript
|
|
902
|
+
* new SimpleStyle(geojson).addTo(map);
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
755
905
|
addTo(map) {
|
|
756
906
|
this.map = map;
|
|
757
907
|
const features = this.geojson.features;
|
|
@@ -829,6 +979,17 @@ var SimpleStyle = class {
|
|
|
829
979
|
this.setCluster();
|
|
830
980
|
return this;
|
|
831
981
|
}
|
|
982
|
+
/**
|
|
983
|
+
* データ全体の範囲に地図をフィットさせます。
|
|
984
|
+
*
|
|
985
|
+
* 現在の GeoJSON のフィーチャーからバウンディングボックスを算出し、そこへ地図を移動します。
|
|
986
|
+
* フィーチャーが存在しない場合は何もしません。データを URL から取得中に呼び出した場合は、
|
|
987
|
+
* フィット要求を保持しておき、取得完了後に自動でフィットします。
|
|
988
|
+
*
|
|
989
|
+
* @param options `map.fitBounds` に渡すオプションです。既定値は `duration: 3000`、`padding: 30` で、
|
|
990
|
+
* 指定した項目のみがこれらを上書きします。
|
|
991
|
+
* @returns メソッドチェーンのための `this` を返します。
|
|
992
|
+
*/
|
|
832
993
|
fitBounds(options = {}) {
|
|
833
994
|
this.callFitBounds = true;
|
|
834
995
|
const _options = {
|
|
@@ -845,7 +1006,12 @@ var SimpleStyle = class {
|
|
|
845
1006
|
return this;
|
|
846
1007
|
}
|
|
847
1008
|
/**
|
|
848
|
-
*
|
|
1009
|
+
* ポリゴンの塗りレイヤーを設定します。
|
|
1010
|
+
*
|
|
1011
|
+
* `$type` が `Polygon` のフィーチャーを対象に塗りレイヤーを追加し、
|
|
1012
|
+
* `fill`、`fill-opacity`、`stroke`(輪郭色)の各 simplestyle プロパティを反映します。
|
|
1013
|
+
* あわせて {@link SimpleStyle.setPopup | setPopup} でこのレイヤーにポップアップを設定します。
|
|
1014
|
+
* 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
849
1015
|
*/
|
|
850
1016
|
setPolygonGeometries() {
|
|
851
1017
|
this.map.addLayer({
|
|
@@ -862,7 +1028,12 @@ var SimpleStyle = class {
|
|
|
862
1028
|
this.setPopup(this.map, `${this.options.id}-polygon`);
|
|
863
1029
|
}
|
|
864
1030
|
/**
|
|
865
|
-
*
|
|
1031
|
+
* ラインのレイヤーを設定します。
|
|
1032
|
+
*
|
|
1033
|
+
* `$type` が `LineString` のフィーチャーを対象にラインレイヤーを追加し、
|
|
1034
|
+
* `stroke-width`(線幅)、`stroke`(線色)、`stroke-opacity`(不透明度)の各 simplestyle プロパティを反映します。
|
|
1035
|
+
* 線端と結合は丸めて描画します。あわせて {@link SimpleStyle.setPopup | setPopup} でこのレイヤーにポップアップを設定します。
|
|
1036
|
+
* 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
866
1037
|
*/
|
|
867
1038
|
setLineGeometries() {
|
|
868
1039
|
this.map.addLayer({
|
|
@@ -883,7 +1054,15 @@ var SimpleStyle = class {
|
|
|
883
1054
|
this.setPopup(this.map, `${this.options.id}-linestring`);
|
|
884
1055
|
}
|
|
885
1056
|
/**
|
|
886
|
-
*
|
|
1057
|
+
* ポイントのレイヤーを設定します。
|
|
1058
|
+
*
|
|
1059
|
+
* クラスターに属さないポイントを対象に、2 種類のレイヤーを追加します。
|
|
1060
|
+
* `marker-symbol` を持たないポイントには円レイヤーを、
|
|
1061
|
+
* `marker-symbol` を持つポイントにはアイコンとラベルのシンボルレイヤーを使います。
|
|
1062
|
+
* `marker-size`(`small`、`large`、その他)に応じて円の半径やラベルのオフセットを変え、
|
|
1063
|
+
* `marker-color`、`stroke`、`title`、`text-color` などの simplestyle プロパティを反映します。
|
|
1064
|
+
* あわせて円レイヤーとシンボルレイヤーの双方に {@link SimpleStyle.setPopup | setPopup} でポップアップを設定します。
|
|
1065
|
+
* 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
887
1066
|
*/
|
|
888
1067
|
setPointGeometries() {
|
|
889
1068
|
this.map.addLayer({
|
|
@@ -943,6 +1122,17 @@ var SimpleStyle = class {
|
|
|
943
1122
|
this.setPopup(this.map, `${this.options.id}-circle-points`);
|
|
944
1123
|
this.setPopup(this.map, `${this.options.id}-symbol-points`);
|
|
945
1124
|
}
|
|
1125
|
+
/**
|
|
1126
|
+
* 指定したレイヤーにクリックでポップアップを表示するイベントハンドラーを設定します。
|
|
1127
|
+
*
|
|
1128
|
+
* クリックされたフィーチャーが `description` プロパティを持つ場合、その中心座標に
|
|
1129
|
+
* サニタイズ済みの HTML を表示するポップアップを追加します。あわせてホバー時に
|
|
1130
|
+
* カーソルを変えるハンドラーも設定します。登録したハンドラーは `_eventHandlers` に記録され、
|
|
1131
|
+
* {@link SimpleStyle.remove | remove} でまとめて解除されます。
|
|
1132
|
+
*
|
|
1133
|
+
* @param map ポップアップを表示する地図です。
|
|
1134
|
+
* @param source ハンドラーを設定する対象のレイヤー ID です。
|
|
1135
|
+
*/
|
|
946
1136
|
async setPopup(map, source) {
|
|
947
1137
|
const clickHandler = async (e) => {
|
|
948
1138
|
if (!e.features?.[0]) return;
|
|
@@ -971,7 +1161,15 @@ var SimpleStyle = class {
|
|
|
971
1161
|
);
|
|
972
1162
|
}
|
|
973
1163
|
/**
|
|
974
|
-
*
|
|
1164
|
+
* クラスタリング用のレイヤーを設定します。
|
|
1165
|
+
*
|
|
1166
|
+
* `point_count` を持つクラスターを対象に、クラスターを表す円レイヤーと、
|
|
1167
|
+
* 件数(`point_count_abbreviated`)を表示するラベルのシンボルレイヤーを追加します。
|
|
1168
|
+
* 円の色は `clusterColor` オプションを使います。クラスターをクリックすると、
|
|
1169
|
+
* そのクラスターが展開するズームレベルまで地図を移動します。あわせてホバー時に
|
|
1170
|
+
* カーソルを変えるハンドラーも設定します。登録したハンドラーは `_eventHandlers` に記録され、
|
|
1171
|
+
* {@link SimpleStyle.remove | remove} でまとめて解除されます。通常は
|
|
1172
|
+
* {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
975
1173
|
*/
|
|
976
1174
|
setCluster() {
|
|
977
1175
|
this.map.addLayer({
|
|
@@ -1036,6 +1234,15 @@ var SimpleStyle = class {
|
|
|
1036
1234
|
}
|
|
1037
1235
|
);
|
|
1038
1236
|
}
|
|
1237
|
+
/**
|
|
1238
|
+
* 追加したソース、レイヤー、イベントハンドラーを地図から除去します。
|
|
1239
|
+
*
|
|
1240
|
+
* {@link SimpleStyle.setPopup | setPopup} や {@link SimpleStyle.setCluster | setCluster}
|
|
1241
|
+
* で登録したイベントハンドラーをすべて解除し、ポリゴン、ライン、ポイント、クラスターの各レイヤーと、
|
|
1242
|
+
* それらのソースを削除します。カーソルのスタイルも元に戻します。まだ地図に追加されていない場合は何もしません。
|
|
1243
|
+
*
|
|
1244
|
+
* @returns メソッドチェーンのための `this` を返します。
|
|
1245
|
+
*/
|
|
1039
1246
|
remove() {
|
|
1040
1247
|
if (!this.map) return this;
|
|
1041
1248
|
const id = this.options.id;
|
|
@@ -1066,6 +1273,18 @@ var SimpleStyle = class {
|
|
|
1066
1273
|
this.map.getCanvas().style.cursor = "";
|
|
1067
1274
|
return this;
|
|
1068
1275
|
}
|
|
1276
|
+
/**
|
|
1277
|
+
* 内部で保持する GeoJSON を設定します。
|
|
1278
|
+
*
|
|
1279
|
+
* `geojson` が URL 文字列の場合は、いったん空のデータを設定したうえで、その URL から GeoJSON を
|
|
1280
|
+
* 非同期に取得します。取得中の Promise は `_loadingPromise` に保持され、取得完了後に
|
|
1281
|
+
* {@link SimpleStyle.updateData | updateData} で表示を更新します。フィット要求が保留されていれば
|
|
1282
|
+
* あわせてフィットします。応答が 2xx 以外の場合は空のデータとして扱い、通信や JSON の解析で
|
|
1283
|
+
* 例外が発生した場合はエラーをコンソールに出力します。
|
|
1284
|
+
* `geojson` が {@link FeatureCollection} の場合は、そのまま内部データとして設定します。
|
|
1285
|
+
*
|
|
1286
|
+
* @param geojson 設定する {@link FeatureCollection} または GeoJSON を返す URL 文字列です。
|
|
1287
|
+
*/
|
|
1069
1288
|
setGeoJSON(geojson) {
|
|
1070
1289
|
if (typeof geojson === "string" && isURL(geojson)) {
|
|
1071
1290
|
this.geojson = template;
|
|
@@ -1098,10 +1317,32 @@ var textHaloColor2 = "#FFFFFF";
|
|
|
1098
1317
|
var backgroundColor2 = "rgba(255, 0, 0, 0.4)";
|
|
1099
1318
|
var strokeColor2 = "#FFFFFF";
|
|
1100
1319
|
var SimpleStyleVector = class {
|
|
1320
|
+
/**
|
|
1321
|
+
* @param url 表示するベクトルタイルソースの TileJSON(tiles.json)URL です。
|
|
1322
|
+
*/
|
|
1101
1323
|
constructor(url) {
|
|
1102
1324
|
this.url = url;
|
|
1103
1325
|
this.sourceName = "vt-geolonia-simple-style";
|
|
1104
1326
|
}
|
|
1327
|
+
/**
|
|
1328
|
+
* 地図にベクトルタイルソースと各レイヤーを追加し、simplestyle の規約に沿って表示します。
|
|
1329
|
+
*
|
|
1330
|
+
* ソースを追加したうえで、ポリゴン(塗り潰しとラベル)、ライン(線とラベル)、
|
|
1331
|
+
* ポイント(円、アイコン、ラベル)の各レイヤーを設定します。あわせて、ポリゴンの塗り潰し、
|
|
1332
|
+
* ラインの線、ポイントの円とアイコンの各レイヤーにクリック時のポップアップを登録します
|
|
1333
|
+
* (ポリゴンやラインのラベル用シンボルレイヤーには登録しません)。
|
|
1334
|
+
*
|
|
1335
|
+
* 地図コンテナの `data-lng` および `data-lat` 属性がいずれも指定されていない場合は、
|
|
1336
|
+
* ソースの読み込み完了を待って、そのソースの `bounds` に一度だけ地図の表示範囲を合わせます
|
|
1337
|
+
* (`padding` は 30、アニメーションなし)。
|
|
1338
|
+
*
|
|
1339
|
+
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1340
|
+
*
|
|
1341
|
+
* @example
|
|
1342
|
+
* ```typescript
|
|
1343
|
+
* new SimpleStyleVector(url).addTo(map);
|
|
1344
|
+
* ```
|
|
1345
|
+
*/
|
|
1105
1346
|
addTo(map) {
|
|
1106
1347
|
const container = map.getContainer();
|
|
1107
1348
|
if (!container.dataset || !container.dataset.lng && !container.dataset.lat) {
|
|
@@ -1184,9 +1425,14 @@ var SimpleStyleVector = class {
|
|
|
1184
1425
|
this.setPointGeometries(map);
|
|
1185
1426
|
}
|
|
1186
1427
|
/**
|
|
1187
|
-
*
|
|
1428
|
+
* ポリゴンジオメトリ用のレイヤーを設定します。
|
|
1429
|
+
*
|
|
1430
|
+
* `$type` が `Polygon` のフィーチャーに対して塗り潰しレイヤー(`fill` タイプ)を追加します。
|
|
1431
|
+
* 塗り色はフィーチャーの `fill` プロパティ、不透明度は `fill-opacity`、
|
|
1432
|
+
* 外周線の色は `stroke` プロパティを用い、いずれも未指定の場合は既定値を適用します。
|
|
1433
|
+
* あわせて、このポリゴンレイヤーにクリック時のポップアップを登録します。
|
|
1188
1434
|
*
|
|
1189
|
-
* @param map
|
|
1435
|
+
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1190
1436
|
*/
|
|
1191
1437
|
setPolygonGeometries(map) {
|
|
1192
1438
|
map.addLayer({
|
|
@@ -1204,9 +1450,15 @@ var SimpleStyleVector = class {
|
|
|
1204
1450
|
this.setPopup(map, "vt-geolonia-simple-style-polygon");
|
|
1205
1451
|
}
|
|
1206
1452
|
/**
|
|
1207
|
-
*
|
|
1453
|
+
* ラインジオメトリ用のレイヤーを設定します。
|
|
1208
1454
|
*
|
|
1209
|
-
*
|
|
1455
|
+
* `$type` が `LineString` のフィーチャーに対して線レイヤー(`line` タイプ)を追加します。
|
|
1456
|
+
* 線幅はフィーチャーの `stroke-width` プロパティ、線色は `stroke`、
|
|
1457
|
+
* 不透明度は `stroke-opacity` を用い、いずれも未指定の場合は既定値を適用します。
|
|
1458
|
+
* 線の端点と結合部はいずれも丸め(`round`)で描画します。
|
|
1459
|
+
* あわせて、このラインレイヤーにクリック時のポップアップを登録します。
|
|
1460
|
+
*
|
|
1461
|
+
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1210
1462
|
*/
|
|
1211
1463
|
setLineGeometries(map) {
|
|
1212
1464
|
map.addLayer({
|
|
@@ -1228,9 +1480,16 @@ var SimpleStyleVector = class {
|
|
|
1228
1480
|
this.setPopup(map, "vt-geolonia-simple-style-linestring");
|
|
1229
1481
|
}
|
|
1230
1482
|
/**
|
|
1231
|
-
*
|
|
1483
|
+
* ポイントジオメトリ用のレイヤーを設定します。
|
|
1484
|
+
*
|
|
1485
|
+
* 2 つのレイヤーを追加します。1 つは `marker-symbol` を持たないポイント向けの円レイヤー
|
|
1486
|
+
* (`circle` タイプ)で、半径はフィーチャーの `marker-size`(`small` は 7、`large` は 13、
|
|
1487
|
+
* それ以外は 9)に応じて変化し、色は `marker-color`、外周線は `stroke` 系プロパティを用います。
|
|
1488
|
+
* もう 1 つはすべてのポイント向けのシンボルレイヤー(`symbol` タイプ)で、`marker-symbol` を
|
|
1489
|
+
* アイコン画像として、`title` をラベルとして表示します。ラベルの位置は `marker-size` に応じて調整します。
|
|
1490
|
+
* あわせて、円レイヤーとシンボルレイヤーの両方にクリック時のポップアップを登録します。
|
|
1232
1491
|
*
|
|
1233
|
-
* @param map
|
|
1492
|
+
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1234
1493
|
*/
|
|
1235
1494
|
setPointGeometries(map) {
|
|
1236
1495
|
map.addLayer({
|
|
@@ -1291,6 +1550,19 @@ var SimpleStyleVector = class {
|
|
|
1291
1550
|
this.setPopup(map, "vt-circle-simple-style-points");
|
|
1292
1551
|
this.setPopup(map, "vt-geolonia-simple-style-points");
|
|
1293
1552
|
}
|
|
1553
|
+
/**
|
|
1554
|
+
* 指定したレイヤーにクリック時のポップアップ表示を設定します。
|
|
1555
|
+
*
|
|
1556
|
+
* 対象レイヤーのフィーチャーがクリックされると、そのフィーチャーの中心座標
|
|
1557
|
+
* (`@turf/center` で算出)にポップアップを表示します。ポップアップの内容は、
|
|
1558
|
+
* フィーチャーの `description` プロパティをサニタイズした HTML です。`description` を
|
|
1559
|
+
* 持たないフィーチャーではポップアップを表示しません。あわせて、`description` を持つ
|
|
1560
|
+
* フィーチャーにマウスが乗ったときはカーソルをポインターに変更し、離れたときに元へ戻します。
|
|
1561
|
+
*
|
|
1562
|
+
* @param map イベントを登録する対象の地図インスタンスです。
|
|
1563
|
+
* @param source ポップアップを設定する対象のレイヤー ID です。
|
|
1564
|
+
* @returns イベントリスナーの登録が完了すると解決する Promise です。
|
|
1565
|
+
*/
|
|
1294
1566
|
async setPopup(map, source) {
|
|
1295
1567
|
map.on("click", source, async (e) => {
|
|
1296
1568
|
if (!e.features?.[0]) return;
|
|
@@ -1423,6 +1695,36 @@ function ensurePMTiles() {
|
|
|
1423
1695
|
import_maplibre_gl5.default.addProtocol("pmtiles", protocol.tile);
|
|
1424
1696
|
}
|
|
1425
1697
|
var GeoloniaMap = class extends import_maplibre_gl5.default.Map {
|
|
1698
|
+
/**
|
|
1699
|
+
* 地図を生成します。
|
|
1700
|
+
*
|
|
1701
|
+
* `apiKey` や `stage` が指定されていればキーリングに設定し、スタイル
|
|
1702
|
+
* (既定は `"geolonia/basic-v2"`)を実際の style.json の URL に解決してから
|
|
1703
|
+
* MapLibre GL JS の `Map` を初期化します。あわせて Geolonia のロゴ、出典表示、
|
|
1704
|
+
* ナビゲーションなどのコントロールを追加し、読み込み完了後にはローディング表示の
|
|
1705
|
+
* 除去、デフォルトマーカーの配置、ジェスチャ操作やスタイル拡張の適用を行います。
|
|
1706
|
+
*
|
|
1707
|
+
* `arg` にコンテナを直接指定する後方互換の形式では、そのコンテナの `data-*`
|
|
1708
|
+
* 属性から設定を読み込みます。指定したコンテナに既に地図が生成済みの場合は、
|
|
1709
|
+
* 新規生成せず既存のインスタンスを返します。
|
|
1710
|
+
*
|
|
1711
|
+
* @param arg 地図の設定です。{@link GeoloniaMapOptions} オブジェクトのほか、
|
|
1712
|
+
* 後方互換としてコンテナを指す CSS セレクタ文字列や `HTMLElement` も指定できます。
|
|
1713
|
+
* @throws コンテナ要素が見つからない場合に `Error` を投げます。
|
|
1714
|
+
* @throws Geolonia のスタイルを API キーなしで使おうとした場合に `Error` を投げます。
|
|
1715
|
+
* @throws MapLibre GL JS の `Map` の初期化に失敗した場合、コンテナにエラー表示を
|
|
1716
|
+
* 行ったうえで、その例外を再スローします。
|
|
1717
|
+
*
|
|
1718
|
+
* @example
|
|
1719
|
+
* ```typescript
|
|
1720
|
+
* const map = new GeoloniaMap({
|
|
1721
|
+
* container: "#map",
|
|
1722
|
+
* apiKey: "YOUR-API-KEY",
|
|
1723
|
+
* center: [139.7671, 35.6812],
|
|
1724
|
+
* zoom: 14,
|
|
1725
|
+
* });
|
|
1726
|
+
* ```
|
|
1727
|
+
*/
|
|
1426
1728
|
// biome-ignore lint/correctness/noUnreachableSuper: intentional singleton pattern - returns existing map instance before super()
|
|
1427
1729
|
constructor(arg) {
|
|
1428
1730
|
const options = normalizeConstructorArg(arg);
|
|
@@ -1673,6 +1975,28 @@ var GeoloniaMap = class extends import_maplibre_gl5.default.Map {
|
|
|
1673
1975
|
container.geoloniaMap = this;
|
|
1674
1976
|
return this;
|
|
1675
1977
|
}
|
|
1978
|
+
/**
|
|
1979
|
+
* 地図のスタイルを差し替えます。
|
|
1980
|
+
*
|
|
1981
|
+
* `style` が文字列の場合は、Geolonia のスタイル論理名(`"geolonia/basic-v2"`
|
|
1982
|
+
* など)、style.json の URL、相対パスのいずれかとして解釈し、実際の URL に
|
|
1983
|
+
* 解決してから適用します。解決の際の言語はブラウザ言語に従い、API キーは
|
|
1984
|
+
* キーリングに設定済みの値を使います。`StyleSpecification` オブジェクトを
|
|
1985
|
+
* 直接渡した場合はそのまま適用します。
|
|
1986
|
+
*
|
|
1987
|
+
* @param style 新しいスタイルです。スタイル論理名や URL などの文字列、または
|
|
1988
|
+
* `StyleSpecification` オブジェクトを指定します。
|
|
1989
|
+
* @param options MapLibre GL JS に渡すスタイル差し替えオプションです。
|
|
1990
|
+
* 既定は空のオブジェクトです。
|
|
1991
|
+
* @returns メソッドチェーンのために自身を返します。
|
|
1992
|
+
* @throws Geolonia のスタイルを API キーなしで使おうとした場合に `Error` を投げます。
|
|
1993
|
+
*
|
|
1994
|
+
* @example
|
|
1995
|
+
* ```typescript
|
|
1996
|
+
* const map = new GeoloniaMap({ container: "#map", apiKey: "YOUR-API-KEY" });
|
|
1997
|
+
* map.setStyle("geolonia/gsi");
|
|
1998
|
+
* ```
|
|
1999
|
+
*/
|
|
1676
2000
|
setStyle(style, options = {}) {
|
|
1677
2001
|
if (style !== null && typeof style === "string") {
|
|
1678
2002
|
style = getStyle(style, { lang: getLang(), apiKey: keyring.apiKey });
|
|
@@ -1681,11 +2005,45 @@ var GeoloniaMap = class extends import_maplibre_gl5.default.Map {
|
|
|
1681
2005
|
super.setStyle.call(this, style, options);
|
|
1682
2006
|
return this;
|
|
1683
2007
|
}
|
|
2008
|
+
/**
|
|
2009
|
+
* 地図を破棄し、関連するリソースやイベントリスナーを解放します。
|
|
2010
|
+
*
|
|
2011
|
+
* MapLibre GL JS の破棄処理に加えて、コンテナ要素に保持している地図インスタンスへの
|
|
2012
|
+
* 参照(`geoloniaMap`)も削除します。これにより、同じコンテナで再度
|
|
2013
|
+
* {@link GeoloniaMap} を生成した際に、破棄済みのインスタンスが返されることを防ぎます。
|
|
2014
|
+
*
|
|
2015
|
+
* @example
|
|
2016
|
+
* ```typescript
|
|
2017
|
+
* const map = new GeoloniaMap({ container: "#map", apiKey: "YOUR-API-KEY" });
|
|
2018
|
+
* // 不要になったら破棄します
|
|
2019
|
+
* map.remove();
|
|
2020
|
+
* ```
|
|
2021
|
+
*/
|
|
1684
2022
|
remove() {
|
|
1685
2023
|
const container = this.getContainer();
|
|
1686
2024
|
super.remove.call(this);
|
|
1687
2025
|
delete container.geoloniaMap;
|
|
1688
2026
|
}
|
|
2027
|
+
/**
|
|
2028
|
+
* 画像を読み込みます。
|
|
2029
|
+
*
|
|
2030
|
+
* `callback` を渡した場合は後方互換のコールバック形式で結果を受け取り、戻り値は
|
|
2031
|
+
* `undefined` になります。`callback` を省略した場合は `Promise` を返します。
|
|
2032
|
+
*
|
|
2033
|
+
* @param url 読み込む画像の URL です。
|
|
2034
|
+
* @param callback 省略可能です。指定した場合はコールバック形式で結果を受け取ります。
|
|
2035
|
+
* @returns `callback` を省略した場合は、読み込んだ画像を含むレスポンスに解決される
|
|
2036
|
+
* `Promise` を返します。`callback` を指定した場合は `undefined` を返します。
|
|
2037
|
+
*
|
|
2038
|
+
* @example
|
|
2039
|
+
* ```typescript
|
|
2040
|
+
* const map = new GeoloniaMap({ container: "#map", apiKey: "YOUR-API-KEY" });
|
|
2041
|
+
* map.on("load", async () => {
|
|
2042
|
+
* const image = await map.loadImage("https://example.com/marker.png");
|
|
2043
|
+
* map.addImage("custom-marker", image.data);
|
|
2044
|
+
* });
|
|
2045
|
+
* ```
|
|
2046
|
+
*/
|
|
1689
2047
|
loadImage(url, callback) {
|
|
1690
2048
|
const promise = super.loadImage(url);
|
|
1691
2049
|
if (callback) {
|
|
@@ -1697,7 +2055,7 @@ var GeoloniaMap = class extends import_maplibre_gl5.default.Map {
|
|
|
1697
2055
|
};
|
|
1698
2056
|
|
|
1699
2057
|
// src/version.ts
|
|
1700
|
-
var VERSION = "0.
|
|
2058
|
+
var VERSION = "0.4.3";
|
|
1701
2059
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1702
2060
|
0 && (module.exports = {
|
|
1703
2061
|
CustomAttributionControl,
|