@geolonia/maps-core 0.4.1 → 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 +489 -21
- package/dist/npm/index.d.cts +682 -42
- package/dist/npm/index.d.ts +682 -42
- package/dist/npm/index.js +498 -36
- package/package.json +9 -3
package/dist/npm/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
8
|
|
|
9
9
|
// src/lib/maplibre-util.ts
|
|
10
|
-
import
|
|
10
|
+
import maplibregl from "maplibre-gl";
|
|
11
11
|
var _docStyle, _userSelect, _selectProp, _transformProp;
|
|
12
12
|
var _DOM = class _DOM {
|
|
13
13
|
static testProp(props) {
|
|
@@ -58,7 +58,7 @@ var _DOM = class _DOM {
|
|
|
58
58
|
}
|
|
59
59
|
static mousePos(el, e) {
|
|
60
60
|
const rect = el.getBoundingClientRect();
|
|
61
|
-
return new Point(
|
|
61
|
+
return new maplibregl.Point(
|
|
62
62
|
e.clientX - rect.left - el.clientLeft,
|
|
63
63
|
e.clientY - rect.top - el.clientTop
|
|
64
64
|
);
|
|
@@ -68,7 +68,7 @@ var _DOM = class _DOM {
|
|
|
68
68
|
const points = [];
|
|
69
69
|
for (let i = 0; i < touches.length; i++) {
|
|
70
70
|
points.push(
|
|
71
|
-
new Point(
|
|
71
|
+
new maplibregl.Point(
|
|
72
72
|
touches[i].clientX - rect.left - el.clientLeft,
|
|
73
73
|
touches[i].clientY - rect.top - el.clientTop
|
|
74
74
|
)
|
|
@@ -227,6 +227,11 @@ var ATTRIBUTION_CSS = `
|
|
|
227
227
|
}
|
|
228
228
|
`;
|
|
229
229
|
var CustomAttributionControl = class {
|
|
230
|
+
/**
|
|
231
|
+
* コントロールを生成します。
|
|
232
|
+
*
|
|
233
|
+
* @param options 帰属表示の挙動を指定するオプションです。省略した場合は空のオブジェクトが使われます。
|
|
234
|
+
*/
|
|
230
235
|
constructor(options = {}) {
|
|
231
236
|
this.options = options;
|
|
232
237
|
bindAll(
|
|
@@ -239,9 +244,24 @@ var CustomAttributionControl = class {
|
|
|
239
244
|
this
|
|
240
245
|
);
|
|
241
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* このコントロールの既定の表示位置を返します。
|
|
249
|
+
*
|
|
250
|
+
* @returns 既定の表示位置である `"bottom-right"` を返します。
|
|
251
|
+
*/
|
|
242
252
|
getDefaultPosition() {
|
|
243
253
|
return "bottom-right";
|
|
244
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* コントロールが地図に追加されるときに呼び出されます。
|
|
257
|
+
*
|
|
258
|
+
* Shadow DOM を持つコンテナ要素を生成し、その内部に帰属表示用の要素と CSS を組み立てます。
|
|
259
|
+
* あわせて帰属表示の内容を初期化し、地図の各種イベント(`styledata`、`sourcedata`、`terrain`、
|
|
260
|
+
* `resize`、`drag`)や印刷メディアクエリの変化を監視するリスナーを登録します。
|
|
261
|
+
*
|
|
262
|
+
* @param map このコントロールを追加する対象の地図です。
|
|
263
|
+
* @returns 地図に挿入するコントロールのルート要素を返します。
|
|
264
|
+
*/
|
|
245
265
|
onAdd(map) {
|
|
246
266
|
this._map = map;
|
|
247
267
|
this._compact = this.options.compact;
|
|
@@ -284,6 +304,12 @@ var CustomAttributionControl = class {
|
|
|
284
304
|
this.printQuery.addEventListener("change", this.onMediaPrintChange);
|
|
285
305
|
return this._container;
|
|
286
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* コントロールが地図から取り除かれるときに呼び出されます。
|
|
309
|
+
*
|
|
310
|
+
* 生成したコンテナ要素を DOM から削除し、`onAdd` で登録した地図のイベントリスナーと
|
|
311
|
+
* 印刷メディアクエリのリスナーを解除したうえで、内部で保持している状態を破棄します。
|
|
312
|
+
*/
|
|
287
313
|
onRemove() {
|
|
288
314
|
if (this._container) {
|
|
289
315
|
DOM.remove(this._container);
|
|
@@ -405,6 +431,14 @@ var attribution_default = CustomAttributionControl;
|
|
|
405
431
|
|
|
406
432
|
// src/lib/controls/geolonia-logo.ts
|
|
407
433
|
var GeoloniaControl = class {
|
|
434
|
+
/**
|
|
435
|
+
* コントロールの DOM 要素を生成して返します。
|
|
436
|
+
*
|
|
437
|
+
* `IControl` の実装として、`Map.addControl` で地図に追加された際に MapLibre から呼び出されます。
|
|
438
|
+
* Geolonia のロゴ画像を含み、`https://geolonia.com/` へのリンクが設定された要素を組み立てて返します。
|
|
439
|
+
*
|
|
440
|
+
* @returns このコントロールのコンテナとなる `HTMLDivElement`。
|
|
441
|
+
*/
|
|
408
442
|
onAdd() {
|
|
409
443
|
this.container = document.createElement("div");
|
|
410
444
|
this.container.className = "maplibregl-ctrl";
|
|
@@ -425,26 +459,33 @@ var GeoloniaControl = class {
|
|
|
425
459
|
this.container.appendChild(link);
|
|
426
460
|
return this.container;
|
|
427
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* コントロールの DOM 要素を地図から除去します。
|
|
464
|
+
*
|
|
465
|
+
* `IControl` の実装として、`Map.removeControl` で地図から取り除かれた際に MapLibre から呼び出されます。
|
|
466
|
+
* `onAdd` で生成したコンテナを親ノードから削除します。
|
|
467
|
+
*/
|
|
428
468
|
onRemove() {
|
|
429
469
|
this.container.parentNode?.removeChild(this.container);
|
|
430
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* このコントロールの既定の表示位置を返します。
|
|
473
|
+
*
|
|
474
|
+
* `Map.addControl` で位置を明示しなかった場合に使用されます。
|
|
475
|
+
*
|
|
476
|
+
* @returns 既定の表示位置 `"bottom-left"`。
|
|
477
|
+
*/
|
|
431
478
|
getDefaultPosition() {
|
|
432
479
|
return "bottom-left";
|
|
433
480
|
}
|
|
434
481
|
};
|
|
435
482
|
|
|
436
483
|
// src/lib/geolonia-map.ts
|
|
437
|
-
import
|
|
438
|
-
FullscreenControl,
|
|
439
|
-
GeolocateControl,
|
|
440
|
-
NavigationControl,
|
|
441
|
-
Popup,
|
|
442
|
-
ScaleControl
|
|
443
|
-
} from "maplibre-gl";
|
|
484
|
+
import maplibregl5 from "maplibre-gl";
|
|
444
485
|
import { Protocol } from "pmtiles";
|
|
445
486
|
|
|
446
487
|
// src/lib/geolonia-marker.ts
|
|
447
|
-
import
|
|
488
|
+
import maplibregl2 from "maplibre-gl";
|
|
448
489
|
import tinycolor from "tinycolor2";
|
|
449
490
|
var MARKER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 67">
|
|
450
491
|
<path class="left" d="M26 0C11.664 0 0 11.663 0 26c0 22.14 26 41 26 41V26h0C26 11.663 26 0 26 0z" fill="#E4402F"/>
|
|
@@ -452,7 +493,20 @@ var MARKER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 67">
|
|
|
452
493
|
<circle cx="26" cy="26" r="9" fill="#FFF"/>
|
|
453
494
|
</svg>`;
|
|
454
495
|
var DEFAULT_COLOR = "#E4402F";
|
|
455
|
-
var GeoloniaMarker = class extends
|
|
496
|
+
var GeoloniaMarker = class extends maplibregl2.Marker {
|
|
497
|
+
/**
|
|
498
|
+
* Geolonia マーカーを作成します。
|
|
499
|
+
*
|
|
500
|
+
* `options.element` が指定されていない場合は、Geolonia デフォルトの SVG マーカー
|
|
501
|
+
* 要素を生成して `options.element` に設定し、`options.color`(未指定時は `#E4402F`)で
|
|
502
|
+
* マーカーの色を適用したうえで、`options.offset` を `[0, -15]` に設定します。
|
|
503
|
+
* `options.element` が指定されている場合は、これらの処理を行わず指定された要素を
|
|
504
|
+
* そのまま使用します。
|
|
505
|
+
*
|
|
506
|
+
* @param options `maplibregl.Marker` の `MarkerOptions` です。`element` を省略すると
|
|
507
|
+
* Geolonia デフォルトのマーカーが生成され、`color` でその色を指定できます。
|
|
508
|
+
* 省略した場合は空のオブジェクトが使われます。
|
|
509
|
+
*/
|
|
456
510
|
constructor(options = {}) {
|
|
457
511
|
if (!options.element) {
|
|
458
512
|
const markerElement = document.createElement("div");
|
|
@@ -482,7 +536,7 @@ var GeoloniaMarker = class extends maplibregl.Marker {
|
|
|
482
536
|
// src/lib/simplestyle.ts
|
|
483
537
|
import bbox from "@turf/bbox";
|
|
484
538
|
import turfCenter from "@turf/center";
|
|
485
|
-
import
|
|
539
|
+
import maplibregl3 from "maplibre-gl";
|
|
486
540
|
|
|
487
541
|
// src/lib/keyring.ts
|
|
488
542
|
var _apiKey, _stage, _isGeoloniaStyle;
|
|
@@ -492,31 +546,83 @@ var Keyring = class {
|
|
|
492
546
|
__privateAdd(this, _stage, "dev");
|
|
493
547
|
__privateAdd(this, _isGeoloniaStyle, true);
|
|
494
548
|
}
|
|
549
|
+
/**
|
|
550
|
+
* 現在設定されている API キーを返します。
|
|
551
|
+
*
|
|
552
|
+
* 未設定の場合は空文字列を返します。
|
|
553
|
+
*
|
|
554
|
+
* @returns API キーの文字列を返します。
|
|
555
|
+
*/
|
|
495
556
|
get apiKey() {
|
|
496
557
|
return __privateGet(this, _apiKey);
|
|
497
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* 現在設定されているステージを返します。
|
|
561
|
+
*
|
|
562
|
+
* 初期値は `"dev"` です。
|
|
563
|
+
*
|
|
564
|
+
* @returns ステージを表す文字列を返します。
|
|
565
|
+
*/
|
|
498
566
|
get stage() {
|
|
499
567
|
return __privateGet(this, _stage);
|
|
500
568
|
}
|
|
569
|
+
/**
|
|
570
|
+
* 現在のスタイルが Geolonia スタイル(API キーが必要なスタイル)かどうかを返します。
|
|
571
|
+
*
|
|
572
|
+
* @returns Geolonia スタイルの場合は `true`、それ以外の場合は `false` を返します。
|
|
573
|
+
*/
|
|
501
574
|
get isGeoloniaStyle() {
|
|
502
575
|
return __privateGet(this, _isGeoloniaStyle);
|
|
503
576
|
}
|
|
577
|
+
/**
|
|
578
|
+
* 現在のスタイルが Geolonia スタイルかどうかを設定します。
|
|
579
|
+
*
|
|
580
|
+
* @param value Geolonia スタイルとして扱う場合は `true`、それ以外の場合は `false` を指定します。
|
|
581
|
+
*/
|
|
504
582
|
set isGeoloniaStyle(value) {
|
|
505
583
|
__privateSet(this, _isGeoloniaStyle, value);
|
|
506
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* API キーを設定します。
|
|
587
|
+
*
|
|
588
|
+
* @param key 設定する API キーの文字列を指定します。
|
|
589
|
+
*/
|
|
507
590
|
setApiKey(key) {
|
|
508
591
|
__privateSet(this, _apiKey, key);
|
|
509
592
|
}
|
|
593
|
+
/**
|
|
594
|
+
* ステージを設定します。
|
|
595
|
+
*
|
|
596
|
+
* @param stage 設定するステージの文字列を指定します。
|
|
597
|
+
*/
|
|
510
598
|
setStage(stage) {
|
|
511
599
|
__privateSet(this, _stage, stage);
|
|
512
600
|
}
|
|
601
|
+
/**
|
|
602
|
+
* API キー、ステージ、Geolonia スタイル判定をすべて初期状態に戻します。
|
|
603
|
+
*
|
|
604
|
+
* API キーは空文字列、ステージは `"dev"`、Geolonia スタイル判定は `true` にリセットされます。
|
|
605
|
+
*/
|
|
513
606
|
reset() {
|
|
514
607
|
__privateSet(this, _apiKey, "");
|
|
515
608
|
__privateSet(this, _stage, "dev");
|
|
516
609
|
__privateSet(this, _isGeoloniaStyle, true);
|
|
517
610
|
}
|
|
518
611
|
/**
|
|
519
|
-
*
|
|
612
|
+
* 与えられたスタイルが Geolonia スタイル(API キーが必要なスタイル)かどうかを判定します。
|
|
613
|
+
*
|
|
614
|
+
* 判定は次のロジックで行われます。
|
|
615
|
+
*
|
|
616
|
+
* - 空文字列(未指定)の場合は `true` を返します。
|
|
617
|
+
* - `https://cdn.geolonia.com/style/` または `https://api.geolonia.com/` で始まる URL の場合は `true` を返します。
|
|
618
|
+
* - 上記以外で `http://` または `https://` で始まる外部 URL の場合は `false` を返します。
|
|
619
|
+
* - `geolonia://` で始まる場合は Geolonia 独自プロトコルのため `true` を返します。
|
|
620
|
+
* - それ以外のプロトコル(`xxx://` 形式)で始まる場合は `false` を返します。
|
|
621
|
+
* - `.json` で終わる場合は `false` を返します。
|
|
622
|
+
* - 上記のいずれにも該当しない場合は、`geolonia/basic` のような Geolonia の論理名とみなして `true` を返します。
|
|
623
|
+
*
|
|
624
|
+
* @param style 判定対象のスタイル(URL、プロトコル付き文字列、または論理名)を指定します。
|
|
625
|
+
* @returns Geolonia スタイルの場合は `true`、それ以外の場合は `false` を返します。
|
|
520
626
|
*/
|
|
521
627
|
isGeoloniaStyleCheck(style) {
|
|
522
628
|
if (!style || style === "") {
|
|
@@ -679,6 +785,16 @@ var template = {
|
|
|
679
785
|
features: []
|
|
680
786
|
};
|
|
681
787
|
var SimpleStyle = class {
|
|
788
|
+
/**
|
|
789
|
+
* SimpleStyle を作成します。
|
|
790
|
+
*
|
|
791
|
+
* `geojson` に URL 文字列を渡した場合は、その URL から GeoJSON を非同期に取得します。
|
|
792
|
+
* 取得の完了は `_loadingPromise` で待つことができます。
|
|
793
|
+
*
|
|
794
|
+
* @param geojson 表示する GeoJSON です。{@link FeatureCollection} または GeoJSON を返す URL 文字列を指定します。
|
|
795
|
+
* @param options 表示オプションです。指定した項目のみが既定値を上書きします。既定値は
|
|
796
|
+
* `id: "geolonia-simple-style"`、`cluster: true`、`heatmap: false`、`clusterColor: "#ff0000"` です。
|
|
797
|
+
*/
|
|
682
798
|
constructor(geojson, options) {
|
|
683
799
|
this.callFitBounds = false;
|
|
684
800
|
this._eventHandlers = [];
|
|
@@ -692,6 +808,16 @@ var SimpleStyle = class {
|
|
|
692
808
|
...options
|
|
693
809
|
};
|
|
694
810
|
}
|
|
811
|
+
/**
|
|
812
|
+
* 表示中のデータを新しい GeoJSON で差し替えます。
|
|
813
|
+
*
|
|
814
|
+
* フィーチャーをポイントとそれ以外(ポリゴン、ライン)に振り分け、
|
|
815
|
+
* それぞれ対応するソースの内容を更新します。レイヤー自体の追加は行わないため、
|
|
816
|
+
* あらかじめ {@link SimpleStyle.addTo | addTo} で地図に追加されている必要があります。
|
|
817
|
+
*
|
|
818
|
+
* @param geojson 差し替える {@link FeatureCollection} です。
|
|
819
|
+
* @returns メソッドチェーンのための `this` を返します。
|
|
820
|
+
*/
|
|
695
821
|
updateData(geojson) {
|
|
696
822
|
this.setGeoJSON(geojson);
|
|
697
823
|
const features = this.geojson.features;
|
|
@@ -713,6 +839,24 @@ var SimpleStyle = class {
|
|
|
713
839
|
);
|
|
714
840
|
return this;
|
|
715
841
|
}
|
|
842
|
+
/**
|
|
843
|
+
* 地図にソースとレイヤーを追加して GeoJSON を表示します。
|
|
844
|
+
*
|
|
845
|
+
* ポリゴンとラインのソース、ポイント用のソース(クラスタリング設定付き)を追加し、
|
|
846
|
+
* ポリゴンとラインのラベル用シンボルレイヤーを配置したうえで、
|
|
847
|
+
* {@link SimpleStyle.setPolygonGeometries | setPolygonGeometries}、
|
|
848
|
+
* {@link SimpleStyle.setLineGeometries | setLineGeometries}、
|
|
849
|
+
* {@link SimpleStyle.setPointGeometries | setPointGeometries}、
|
|
850
|
+
* {@link SimpleStyle.setCluster | setCluster} を呼び出して各ジオメトリのレイヤーを設定します。
|
|
851
|
+
*
|
|
852
|
+
* @param map 表示先の地図です。
|
|
853
|
+
* @returns メソッドチェーンのための `this` を返します。
|
|
854
|
+
*
|
|
855
|
+
* @example
|
|
856
|
+
* ```typescript
|
|
857
|
+
* new SimpleStyle(geojson).addTo(map);
|
|
858
|
+
* ```
|
|
859
|
+
*/
|
|
716
860
|
addTo(map) {
|
|
717
861
|
this.map = map;
|
|
718
862
|
const features = this.geojson.features;
|
|
@@ -790,6 +934,17 @@ var SimpleStyle = class {
|
|
|
790
934
|
this.setCluster();
|
|
791
935
|
return this;
|
|
792
936
|
}
|
|
937
|
+
/**
|
|
938
|
+
* データ全体の範囲に地図をフィットさせます。
|
|
939
|
+
*
|
|
940
|
+
* 現在の GeoJSON のフィーチャーからバウンディングボックスを算出し、そこへ地図を移動します。
|
|
941
|
+
* フィーチャーが存在しない場合は何もしません。データを URL から取得中に呼び出した場合は、
|
|
942
|
+
* フィット要求を保持しておき、取得完了後に自動でフィットします。
|
|
943
|
+
*
|
|
944
|
+
* @param options `map.fitBounds` に渡すオプションです。既定値は `duration: 3000`、`padding: 30` で、
|
|
945
|
+
* 指定した項目のみがこれらを上書きします。
|
|
946
|
+
* @returns メソッドチェーンのための `this` を返します。
|
|
947
|
+
*/
|
|
793
948
|
fitBounds(options = {}) {
|
|
794
949
|
this.callFitBounds = true;
|
|
795
950
|
const _options = {
|
|
@@ -806,7 +961,12 @@ var SimpleStyle = class {
|
|
|
806
961
|
return this;
|
|
807
962
|
}
|
|
808
963
|
/**
|
|
809
|
-
*
|
|
964
|
+
* ポリゴンの塗りレイヤーを設定します。
|
|
965
|
+
*
|
|
966
|
+
* `$type` が `Polygon` のフィーチャーを対象に塗りレイヤーを追加し、
|
|
967
|
+
* `fill`、`fill-opacity`、`stroke`(輪郭色)の各 simplestyle プロパティを反映します。
|
|
968
|
+
* あわせて {@link SimpleStyle.setPopup | setPopup} でこのレイヤーにポップアップを設定します。
|
|
969
|
+
* 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
810
970
|
*/
|
|
811
971
|
setPolygonGeometries() {
|
|
812
972
|
this.map.addLayer({
|
|
@@ -823,7 +983,12 @@ var SimpleStyle = class {
|
|
|
823
983
|
this.setPopup(this.map, `${this.options.id}-polygon`);
|
|
824
984
|
}
|
|
825
985
|
/**
|
|
826
|
-
*
|
|
986
|
+
* ラインのレイヤーを設定します。
|
|
987
|
+
*
|
|
988
|
+
* `$type` が `LineString` のフィーチャーを対象にラインレイヤーを追加し、
|
|
989
|
+
* `stroke-width`(線幅)、`stroke`(線色)、`stroke-opacity`(不透明度)の各 simplestyle プロパティを反映します。
|
|
990
|
+
* 線端と結合は丸めて描画します。あわせて {@link SimpleStyle.setPopup | setPopup} でこのレイヤーにポップアップを設定します。
|
|
991
|
+
* 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
827
992
|
*/
|
|
828
993
|
setLineGeometries() {
|
|
829
994
|
this.map.addLayer({
|
|
@@ -844,7 +1009,15 @@ var SimpleStyle = class {
|
|
|
844
1009
|
this.setPopup(this.map, `${this.options.id}-linestring`);
|
|
845
1010
|
}
|
|
846
1011
|
/**
|
|
847
|
-
*
|
|
1012
|
+
* ポイントのレイヤーを設定します。
|
|
1013
|
+
*
|
|
1014
|
+
* クラスターに属さないポイントを対象に、2 種類のレイヤーを追加します。
|
|
1015
|
+
* `marker-symbol` を持たないポイントには円レイヤーを、
|
|
1016
|
+
* `marker-symbol` を持つポイントにはアイコンとラベルのシンボルレイヤーを使います。
|
|
1017
|
+
* `marker-size`(`small`、`large`、その他)に応じて円の半径やラベルのオフセットを変え、
|
|
1018
|
+
* `marker-color`、`stroke`、`title`、`text-color` などの simplestyle プロパティを反映します。
|
|
1019
|
+
* あわせて円レイヤーとシンボルレイヤーの双方に {@link SimpleStyle.setPopup | setPopup} でポップアップを設定します。
|
|
1020
|
+
* 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
848
1021
|
*/
|
|
849
1022
|
setPointGeometries() {
|
|
850
1023
|
this.map.addLayer({
|
|
@@ -904,6 +1077,17 @@ var SimpleStyle = class {
|
|
|
904
1077
|
this.setPopup(this.map, `${this.options.id}-circle-points`);
|
|
905
1078
|
this.setPopup(this.map, `${this.options.id}-symbol-points`);
|
|
906
1079
|
}
|
|
1080
|
+
/**
|
|
1081
|
+
* 指定したレイヤーにクリックでポップアップを表示するイベントハンドラーを設定します。
|
|
1082
|
+
*
|
|
1083
|
+
* クリックされたフィーチャーが `description` プロパティを持つ場合、その中心座標に
|
|
1084
|
+
* サニタイズ済みの HTML を表示するポップアップを追加します。あわせてホバー時に
|
|
1085
|
+
* カーソルを変えるハンドラーも設定します。登録したハンドラーは `_eventHandlers` に記録され、
|
|
1086
|
+
* {@link SimpleStyle.remove | remove} でまとめて解除されます。
|
|
1087
|
+
*
|
|
1088
|
+
* @param map ポップアップを表示する地図です。
|
|
1089
|
+
* @param source ハンドラーを設定する対象のレイヤー ID です。
|
|
1090
|
+
*/
|
|
907
1091
|
async setPopup(map, source) {
|
|
908
1092
|
const clickHandler = async (e) => {
|
|
909
1093
|
if (!e.features?.[0]) return;
|
|
@@ -911,7 +1095,7 @@ var SimpleStyle = class {
|
|
|
911
1095
|
const description = e.features[0].properties?.description;
|
|
912
1096
|
if (description) {
|
|
913
1097
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
914
|
-
new
|
|
1098
|
+
new maplibregl3.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
915
1099
|
}
|
|
916
1100
|
};
|
|
917
1101
|
const mouseEnterHandler = (e) => {
|
|
@@ -932,7 +1116,15 @@ var SimpleStyle = class {
|
|
|
932
1116
|
);
|
|
933
1117
|
}
|
|
934
1118
|
/**
|
|
935
|
-
*
|
|
1119
|
+
* クラスタリング用のレイヤーを設定します。
|
|
1120
|
+
*
|
|
1121
|
+
* `point_count` を持つクラスターを対象に、クラスターを表す円レイヤーと、
|
|
1122
|
+
* 件数(`point_count_abbreviated`)を表示するラベルのシンボルレイヤーを追加します。
|
|
1123
|
+
* 円の色は `clusterColor` オプションを使います。クラスターをクリックすると、
|
|
1124
|
+
* そのクラスターが展開するズームレベルまで地図を移動します。あわせてホバー時に
|
|
1125
|
+
* カーソルを変えるハンドラーも設定します。登録したハンドラーは `_eventHandlers` に記録され、
|
|
1126
|
+
* {@link SimpleStyle.remove | remove} でまとめて解除されます。通常は
|
|
1127
|
+
* {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
936
1128
|
*/
|
|
937
1129
|
setCluster() {
|
|
938
1130
|
this.map.addLayer({
|
|
@@ -997,6 +1189,15 @@ var SimpleStyle = class {
|
|
|
997
1189
|
}
|
|
998
1190
|
);
|
|
999
1191
|
}
|
|
1192
|
+
/**
|
|
1193
|
+
* 追加したソース、レイヤー、イベントハンドラーを地図から除去します。
|
|
1194
|
+
*
|
|
1195
|
+
* {@link SimpleStyle.setPopup | setPopup} や {@link SimpleStyle.setCluster | setCluster}
|
|
1196
|
+
* で登録したイベントハンドラーをすべて解除し、ポリゴン、ライン、ポイント、クラスターの各レイヤーと、
|
|
1197
|
+
* それらのソースを削除します。カーソルのスタイルも元に戻します。まだ地図に追加されていない場合は何もしません。
|
|
1198
|
+
*
|
|
1199
|
+
* @returns メソッドチェーンのための `this` を返します。
|
|
1200
|
+
*/
|
|
1000
1201
|
remove() {
|
|
1001
1202
|
if (!this.map) return this;
|
|
1002
1203
|
const id = this.options.id;
|
|
@@ -1027,6 +1228,18 @@ var SimpleStyle = class {
|
|
|
1027
1228
|
this.map.getCanvas().style.cursor = "";
|
|
1028
1229
|
return this;
|
|
1029
1230
|
}
|
|
1231
|
+
/**
|
|
1232
|
+
* 内部で保持する GeoJSON を設定します。
|
|
1233
|
+
*
|
|
1234
|
+
* `geojson` が URL 文字列の場合は、いったん空のデータを設定したうえで、その URL から GeoJSON を
|
|
1235
|
+
* 非同期に取得します。取得中の Promise は `_loadingPromise` に保持され、取得完了後に
|
|
1236
|
+
* {@link SimpleStyle.updateData | updateData} で表示を更新します。フィット要求が保留されていれば
|
|
1237
|
+
* あわせてフィットします。応答が 2xx 以外の場合は空のデータとして扱い、通信や JSON の解析で
|
|
1238
|
+
* 例外が発生した場合はエラーをコンソールに出力します。
|
|
1239
|
+
* `geojson` が {@link FeatureCollection} の場合は、そのまま内部データとして設定します。
|
|
1240
|
+
*
|
|
1241
|
+
* @param geojson 設定する {@link FeatureCollection} または GeoJSON を返す URL 文字列です。
|
|
1242
|
+
*/
|
|
1030
1243
|
setGeoJSON(geojson) {
|
|
1031
1244
|
if (typeof geojson === "string" && isURL(geojson)) {
|
|
1032
1245
|
this.geojson = template;
|
|
@@ -1053,16 +1266,38 @@ var SimpleStyle = class {
|
|
|
1053
1266
|
|
|
1054
1267
|
// src/lib/simplestyle-vector.ts
|
|
1055
1268
|
import turfCenter2 from "@turf/center";
|
|
1056
|
-
import
|
|
1269
|
+
import maplibregl4 from "maplibre-gl";
|
|
1057
1270
|
var textColor2 = "#000000";
|
|
1058
1271
|
var textHaloColor2 = "#FFFFFF";
|
|
1059
1272
|
var backgroundColor2 = "rgba(255, 0, 0, 0.4)";
|
|
1060
1273
|
var strokeColor2 = "#FFFFFF";
|
|
1061
1274
|
var SimpleStyleVector = class {
|
|
1275
|
+
/**
|
|
1276
|
+
* @param url 表示するベクトルタイルソースの TileJSON(tiles.json)URL です。
|
|
1277
|
+
*/
|
|
1062
1278
|
constructor(url) {
|
|
1063
1279
|
this.url = url;
|
|
1064
1280
|
this.sourceName = "vt-geolonia-simple-style";
|
|
1065
1281
|
}
|
|
1282
|
+
/**
|
|
1283
|
+
* 地図にベクトルタイルソースと各レイヤーを追加し、simplestyle の規約に沿って表示します。
|
|
1284
|
+
*
|
|
1285
|
+
* ソースを追加したうえで、ポリゴン(塗り潰しとラベル)、ライン(線とラベル)、
|
|
1286
|
+
* ポイント(円、アイコン、ラベル)の各レイヤーを設定します。あわせて、ポリゴンの塗り潰し、
|
|
1287
|
+
* ラインの線、ポイントの円とアイコンの各レイヤーにクリック時のポップアップを登録します
|
|
1288
|
+
* (ポリゴンやラインのラベル用シンボルレイヤーには登録しません)。
|
|
1289
|
+
*
|
|
1290
|
+
* 地図コンテナの `data-lng` および `data-lat` 属性がいずれも指定されていない場合は、
|
|
1291
|
+
* ソースの読み込み完了を待って、そのソースの `bounds` に一度だけ地図の表示範囲を合わせます
|
|
1292
|
+
* (`padding` は 30、アニメーションなし)。
|
|
1293
|
+
*
|
|
1294
|
+
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1295
|
+
*
|
|
1296
|
+
* @example
|
|
1297
|
+
* ```typescript
|
|
1298
|
+
* new SimpleStyleVector(url).addTo(map);
|
|
1299
|
+
* ```
|
|
1300
|
+
*/
|
|
1066
1301
|
addTo(map) {
|
|
1067
1302
|
const container = map.getContainer();
|
|
1068
1303
|
if (!container.dataset || !container.dataset.lng && !container.dataset.lat) {
|
|
@@ -1145,9 +1380,14 @@ var SimpleStyleVector = class {
|
|
|
1145
1380
|
this.setPointGeometries(map);
|
|
1146
1381
|
}
|
|
1147
1382
|
/**
|
|
1148
|
-
*
|
|
1383
|
+
* ポリゴンジオメトリ用のレイヤーを設定します。
|
|
1149
1384
|
*
|
|
1150
|
-
*
|
|
1385
|
+
* `$type` が `Polygon` のフィーチャーに対して塗り潰しレイヤー(`fill` タイプ)を追加します。
|
|
1386
|
+
* 塗り色はフィーチャーの `fill` プロパティ、不透明度は `fill-opacity`、
|
|
1387
|
+
* 外周線の色は `stroke` プロパティを用い、いずれも未指定の場合は既定値を適用します。
|
|
1388
|
+
* あわせて、このポリゴンレイヤーにクリック時のポップアップを登録します。
|
|
1389
|
+
*
|
|
1390
|
+
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1151
1391
|
*/
|
|
1152
1392
|
setPolygonGeometries(map) {
|
|
1153
1393
|
map.addLayer({
|
|
@@ -1165,9 +1405,15 @@ var SimpleStyleVector = class {
|
|
|
1165
1405
|
this.setPopup(map, "vt-geolonia-simple-style-polygon");
|
|
1166
1406
|
}
|
|
1167
1407
|
/**
|
|
1168
|
-
*
|
|
1408
|
+
* ラインジオメトリ用のレイヤーを設定します。
|
|
1409
|
+
*
|
|
1410
|
+
* `$type` が `LineString` のフィーチャーに対して線レイヤー(`line` タイプ)を追加します。
|
|
1411
|
+
* 線幅はフィーチャーの `stroke-width` プロパティ、線色は `stroke`、
|
|
1412
|
+
* 不透明度は `stroke-opacity` を用い、いずれも未指定の場合は既定値を適用します。
|
|
1413
|
+
* 線の端点と結合部はいずれも丸め(`round`)で描画します。
|
|
1414
|
+
* あわせて、このラインレイヤーにクリック時のポップアップを登録します。
|
|
1169
1415
|
*
|
|
1170
|
-
* @param map
|
|
1416
|
+
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1171
1417
|
*/
|
|
1172
1418
|
setLineGeometries(map) {
|
|
1173
1419
|
map.addLayer({
|
|
@@ -1189,9 +1435,16 @@ var SimpleStyleVector = class {
|
|
|
1189
1435
|
this.setPopup(map, "vt-geolonia-simple-style-linestring");
|
|
1190
1436
|
}
|
|
1191
1437
|
/**
|
|
1192
|
-
*
|
|
1438
|
+
* ポイントジオメトリ用のレイヤーを設定します。
|
|
1193
1439
|
*
|
|
1194
|
-
*
|
|
1440
|
+
* 2 つのレイヤーを追加します。1 つは `marker-symbol` を持たないポイント向けの円レイヤー
|
|
1441
|
+
* (`circle` タイプ)で、半径はフィーチャーの `marker-size`(`small` は 7、`large` は 13、
|
|
1442
|
+
* それ以外は 9)に応じて変化し、色は `marker-color`、外周線は `stroke` 系プロパティを用います。
|
|
1443
|
+
* もう 1 つはすべてのポイント向けのシンボルレイヤー(`symbol` タイプ)で、`marker-symbol` を
|
|
1444
|
+
* アイコン画像として、`title` をラベルとして表示します。ラベルの位置は `marker-size` に応じて調整します。
|
|
1445
|
+
* あわせて、円レイヤーとシンボルレイヤーの両方にクリック時のポップアップを登録します。
|
|
1446
|
+
*
|
|
1447
|
+
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1195
1448
|
*/
|
|
1196
1449
|
setPointGeometries(map) {
|
|
1197
1450
|
map.addLayer({
|
|
@@ -1252,6 +1505,19 @@ var SimpleStyleVector = class {
|
|
|
1252
1505
|
this.setPopup(map, "vt-circle-simple-style-points");
|
|
1253
1506
|
this.setPopup(map, "vt-geolonia-simple-style-points");
|
|
1254
1507
|
}
|
|
1508
|
+
/**
|
|
1509
|
+
* 指定したレイヤーにクリック時のポップアップ表示を設定します。
|
|
1510
|
+
*
|
|
1511
|
+
* 対象レイヤーのフィーチャーがクリックされると、そのフィーチャーの中心座標
|
|
1512
|
+
* (`@turf/center` で算出)にポップアップを表示します。ポップアップの内容は、
|
|
1513
|
+
* フィーチャーの `description` プロパティをサニタイズした HTML です。`description` を
|
|
1514
|
+
* 持たないフィーチャーではポップアップを表示しません。あわせて、`description` を持つ
|
|
1515
|
+
* フィーチャーにマウスが乗ったときはカーソルをポインターに変更し、離れたときに元へ戻します。
|
|
1516
|
+
*
|
|
1517
|
+
* @param map イベントを登録する対象の地図インスタンスです。
|
|
1518
|
+
* @param source ポップアップを設定する対象のレイヤー ID です。
|
|
1519
|
+
* @returns イベントリスナーの登録が完了すると解決する Promise です。
|
|
1520
|
+
*/
|
|
1255
1521
|
async setPopup(map, source) {
|
|
1256
1522
|
map.on("click", source, async (e) => {
|
|
1257
1523
|
if (!e.features?.[0]) return;
|
|
@@ -1259,7 +1525,7 @@ var SimpleStyleVector = class {
|
|
|
1259
1525
|
const description = e.features[0].properties?.description;
|
|
1260
1526
|
if (description) {
|
|
1261
1527
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
1262
|
-
new
|
|
1528
|
+
new maplibregl4.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
1263
1529
|
}
|
|
1264
1530
|
});
|
|
1265
1531
|
map.on("mouseenter", source, (e) => {
|
|
@@ -1274,17 +1540,149 @@ var SimpleStyleVector = class {
|
|
|
1274
1540
|
};
|
|
1275
1541
|
var simplestyle_vector_default = SimpleStyleVector;
|
|
1276
1542
|
|
|
1543
|
+
// src/lib/legacy-options.ts
|
|
1544
|
+
var CONTROL_POSITIONS = [
|
|
1545
|
+
"top-right",
|
|
1546
|
+
"bottom-right",
|
|
1547
|
+
"bottom-left",
|
|
1548
|
+
"top-left"
|
|
1549
|
+
];
|
|
1550
|
+
function toControlAttr(value) {
|
|
1551
|
+
const v = value.toLowerCase();
|
|
1552
|
+
if (CONTROL_POSITIONS.includes(v)) {
|
|
1553
|
+
return v;
|
|
1554
|
+
}
|
|
1555
|
+
return v === "on";
|
|
1556
|
+
}
|
|
1557
|
+
function isCssSelector(value) {
|
|
1558
|
+
if (/^https?:\/\//.test(value) || /^\.?\.?\//.test(value)) {
|
|
1559
|
+
return null;
|
|
1560
|
+
}
|
|
1561
|
+
try {
|
|
1562
|
+
return document.querySelector(value);
|
|
1563
|
+
} catch {
|
|
1564
|
+
return null;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
function resolveGeojson(value) {
|
|
1568
|
+
const el = isCssSelector(value);
|
|
1569
|
+
if (el?.textContent) {
|
|
1570
|
+
return JSON.parse(el.textContent);
|
|
1571
|
+
}
|
|
1572
|
+
return value;
|
|
1573
|
+
}
|
|
1574
|
+
function isDomElement(o) {
|
|
1575
|
+
return typeof HTMLElement !== "undefined" ? o instanceof HTMLElement : !!o && typeof o === "object" && o.nodeType === 1;
|
|
1576
|
+
}
|
|
1577
|
+
function optionsFromContainer(container) {
|
|
1578
|
+
const ds = container.dataset;
|
|
1579
|
+
const options = {
|
|
1580
|
+
container,
|
|
1581
|
+
bearing: Number.parseFloat(ds.bearing ?? "") || 0,
|
|
1582
|
+
pitch: Number.parseFloat(ds.pitch ?? "") || 0,
|
|
1583
|
+
zoom: Number.parseFloat(ds.zoom ?? "") || 0,
|
|
1584
|
+
hash: ds.hash === "on",
|
|
1585
|
+
marker: (ds.marker ?? "on") === "on",
|
|
1586
|
+
markerColor: ds.markerColor ?? "#E4402F",
|
|
1587
|
+
openPopup: ds.openPopup === "on",
|
|
1588
|
+
loader: ds.loader !== "off",
|
|
1589
|
+
gestureHandling: ds.gestureHandling !== "off",
|
|
1590
|
+
navigationControl: toControlAttr(ds.navigationControl ?? "on"),
|
|
1591
|
+
geolocateControl: toControlAttr(ds.geolocateControl ?? "off"),
|
|
1592
|
+
fullscreenControl: toControlAttr(ds.fullscreenControl ?? "off"),
|
|
1593
|
+
scaleControl: toControlAttr(ds.scaleControl ?? "off"),
|
|
1594
|
+
geoloniaControl: toControlAttr(ds.geoloniaControl ?? "on"),
|
|
1595
|
+
cluster: (ds.cluster ?? "on") === "on",
|
|
1596
|
+
clusterColor: ds.clusterColor ?? "#ff0000",
|
|
1597
|
+
"3d": ds["3d"] === "on"
|
|
1598
|
+
};
|
|
1599
|
+
if (ds.style) options.style = ds.style;
|
|
1600
|
+
if (ds.lang !== void 0) {
|
|
1601
|
+
options.lang = ds.lang;
|
|
1602
|
+
}
|
|
1603
|
+
if (ds.key) options.apiKey = ds.key;
|
|
1604
|
+
if (ds.stage) options.stage = ds.stage;
|
|
1605
|
+
const hasLat = ds.lat !== void 0 && ds.lat !== "";
|
|
1606
|
+
const hasLng = ds.lng !== void 0 && ds.lng !== "";
|
|
1607
|
+
if (hasLat && hasLng) {
|
|
1608
|
+
options.center = [
|
|
1609
|
+
Number.parseFloat(ds.lng),
|
|
1610
|
+
Number.parseFloat(ds.lat)
|
|
1611
|
+
];
|
|
1612
|
+
}
|
|
1613
|
+
if (ds.customMarker) options.customMarker = ds.customMarker;
|
|
1614
|
+
if (ds.customMarkerOffset) {
|
|
1615
|
+
const [x, y] = ds.customMarkerOffset.split(",").map((n) => Number(n.trim()));
|
|
1616
|
+
options.customMarkerOffset = [x || 0, y || 0];
|
|
1617
|
+
}
|
|
1618
|
+
if (ds.geojson) options.geojson = resolveGeojson(ds.geojson);
|
|
1619
|
+
if (ds.simpleVector) options.simpleVector = ds.simpleVector;
|
|
1620
|
+
if (ds.minZoom !== void 0 && ds.minZoom !== "" && (Number(ds.minZoom) === 0 || Number(ds.minZoom))) {
|
|
1621
|
+
options.minZoom = Number(ds.minZoom);
|
|
1622
|
+
}
|
|
1623
|
+
if (ds.maxZoom !== void 0 && ds.maxZoom !== "" && (Number(ds.maxZoom) === 0 || Number(ds.maxZoom))) {
|
|
1624
|
+
options.maxZoom = Number(ds.maxZoom);
|
|
1625
|
+
}
|
|
1626
|
+
return options;
|
|
1627
|
+
}
|
|
1628
|
+
function normalizeConstructorArg(arg) {
|
|
1629
|
+
if (typeof arg === "string") {
|
|
1630
|
+
const el = document.querySelector(arg) || document.getElementById(arg);
|
|
1631
|
+
if (!el) {
|
|
1632
|
+
throw new Error(
|
|
1633
|
+
`[Geolonia] No HTML elements found matching \`${arg}\`. Please ensure the map container element exists.`
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
return optionsFromContainer(el);
|
|
1637
|
+
}
|
|
1638
|
+
if (isDomElement(arg)) {
|
|
1639
|
+
return optionsFromContainer(arg);
|
|
1640
|
+
}
|
|
1641
|
+
return arg;
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1277
1644
|
// src/lib/geolonia-map.ts
|
|
1278
1645
|
var pmtilesRegistered = false;
|
|
1279
1646
|
function ensurePMTiles() {
|
|
1280
1647
|
if (pmtilesRegistered) return;
|
|
1281
1648
|
pmtilesRegistered = true;
|
|
1282
1649
|
const protocol = new Protocol();
|
|
1283
|
-
|
|
1650
|
+
maplibregl5.addProtocol("pmtiles", protocol.tile);
|
|
1284
1651
|
}
|
|
1285
|
-
var GeoloniaMap = class extends
|
|
1652
|
+
var GeoloniaMap = class extends maplibregl5.Map {
|
|
1653
|
+
/**
|
|
1654
|
+
* 地図を生成します。
|
|
1655
|
+
*
|
|
1656
|
+
* `apiKey` や `stage` が指定されていればキーリングに設定し、スタイル
|
|
1657
|
+
* (既定は `"geolonia/basic-v2"`)を実際の style.json の URL に解決してから
|
|
1658
|
+
* MapLibre GL JS の `Map` を初期化します。あわせて Geolonia のロゴ、出典表示、
|
|
1659
|
+
* ナビゲーションなどのコントロールを追加し、読み込み完了後にはローディング表示の
|
|
1660
|
+
* 除去、デフォルトマーカーの配置、ジェスチャ操作やスタイル拡張の適用を行います。
|
|
1661
|
+
*
|
|
1662
|
+
* `arg` にコンテナを直接指定する後方互換の形式では、そのコンテナの `data-*`
|
|
1663
|
+
* 属性から設定を読み込みます。指定したコンテナに既に地図が生成済みの場合は、
|
|
1664
|
+
* 新規生成せず既存のインスタンスを返します。
|
|
1665
|
+
*
|
|
1666
|
+
* @param arg 地図の設定です。{@link GeoloniaMapOptions} オブジェクトのほか、
|
|
1667
|
+
* 後方互換としてコンテナを指す CSS セレクタ文字列や `HTMLElement` も指定できます。
|
|
1668
|
+
* @throws コンテナ要素が見つからない場合に `Error` を投げます。
|
|
1669
|
+
* @throws Geolonia のスタイルを API キーなしで使おうとした場合に `Error` を投げます。
|
|
1670
|
+
* @throws MapLibre GL JS の `Map` の初期化に失敗した場合、コンテナにエラー表示を
|
|
1671
|
+
* 行ったうえで、その例外を再スローします。
|
|
1672
|
+
*
|
|
1673
|
+
* @example
|
|
1674
|
+
* ```typescript
|
|
1675
|
+
* const map = new GeoloniaMap({
|
|
1676
|
+
* container: "#map",
|
|
1677
|
+
* apiKey: "YOUR-API-KEY",
|
|
1678
|
+
* center: [139.7671, 35.6812],
|
|
1679
|
+
* zoom: 14,
|
|
1680
|
+
* });
|
|
1681
|
+
* ```
|
|
1682
|
+
*/
|
|
1286
1683
|
// biome-ignore lint/correctness/noUnreachableSuper: intentional singleton pattern - returns existing map instance before super()
|
|
1287
|
-
constructor(
|
|
1684
|
+
constructor(arg) {
|
|
1685
|
+
const options = normalizeConstructorArg(arg);
|
|
1288
1686
|
ensurePMTiles();
|
|
1289
1687
|
if (options.apiKey) {
|
|
1290
1688
|
keyring.setApiKey(options.apiKey);
|
|
@@ -1412,24 +1810,30 @@ var GeoloniaMap = class extends maplibregl4.Map {
|
|
|
1412
1810
|
const fullscreen = parseControlOption(options.fullscreenControl ?? false);
|
|
1413
1811
|
if (fullscreen.enabled) {
|
|
1414
1812
|
this.addControl(
|
|
1415
|
-
new FullscreenControl(),
|
|
1813
|
+
new maplibregl5.FullscreenControl(),
|
|
1416
1814
|
fullscreen.position
|
|
1417
1815
|
);
|
|
1418
1816
|
}
|
|
1419
1817
|
const nav = parseControlOption(options.navigationControl ?? true);
|
|
1420
1818
|
if (nav.enabled) {
|
|
1421
|
-
this.addControl(
|
|
1819
|
+
this.addControl(
|
|
1820
|
+
new maplibregl5.NavigationControl(),
|
|
1821
|
+
nav.position
|
|
1822
|
+
);
|
|
1422
1823
|
}
|
|
1423
1824
|
const geolocate = parseControlOption(options.geolocateControl ?? false);
|
|
1424
1825
|
if (geolocate.enabled) {
|
|
1425
1826
|
this.addControl(
|
|
1426
|
-
new GeolocateControl({}),
|
|
1827
|
+
new maplibregl5.GeolocateControl({}),
|
|
1427
1828
|
geolocate.position
|
|
1428
1829
|
);
|
|
1429
1830
|
}
|
|
1430
1831
|
const scale = parseControlOption(options.scaleControl ?? false);
|
|
1431
1832
|
if (scale.enabled) {
|
|
1432
|
-
this.addControl(
|
|
1833
|
+
this.addControl(
|
|
1834
|
+
new maplibregl5.ScaleControl({}),
|
|
1835
|
+
scale.position
|
|
1836
|
+
);
|
|
1433
1837
|
}
|
|
1434
1838
|
this.on("load", (event) => {
|
|
1435
1839
|
const map = event.target;
|
|
@@ -1472,7 +1876,9 @@ var GeoloniaMap = class extends maplibregl4.Map {
|
|
|
1472
1876
|
}
|
|
1473
1877
|
const content = container.dataset?.popupContent;
|
|
1474
1878
|
if (content) {
|
|
1475
|
-
const popup = new Popup({ offset: [0, -25] }).setHTML(
|
|
1879
|
+
const popup = new maplibregl5.Popup({ offset: [0, -25] }).setHTML(
|
|
1880
|
+
content
|
|
1881
|
+
);
|
|
1476
1882
|
marker.setPopup(popup);
|
|
1477
1883
|
if (options.openPopup) {
|
|
1478
1884
|
marker.togglePopup();
|
|
@@ -1524,6 +1930,28 @@ var GeoloniaMap = class extends maplibregl4.Map {
|
|
|
1524
1930
|
container.geoloniaMap = this;
|
|
1525
1931
|
return this;
|
|
1526
1932
|
}
|
|
1933
|
+
/**
|
|
1934
|
+
* 地図のスタイルを差し替えます。
|
|
1935
|
+
*
|
|
1936
|
+
* `style` が文字列の場合は、Geolonia のスタイル論理名(`"geolonia/basic-v2"`
|
|
1937
|
+
* など)、style.json の URL、相対パスのいずれかとして解釈し、実際の URL に
|
|
1938
|
+
* 解決してから適用します。解決の際の言語はブラウザ言語に従い、API キーは
|
|
1939
|
+
* キーリングに設定済みの値を使います。`StyleSpecification` オブジェクトを
|
|
1940
|
+
* 直接渡した場合はそのまま適用します。
|
|
1941
|
+
*
|
|
1942
|
+
* @param style 新しいスタイルです。スタイル論理名や URL などの文字列、または
|
|
1943
|
+
* `StyleSpecification` オブジェクトを指定します。
|
|
1944
|
+
* @param options MapLibre GL JS に渡すスタイル差し替えオプションです。
|
|
1945
|
+
* 既定は空のオブジェクトです。
|
|
1946
|
+
* @returns メソッドチェーンのために自身を返します。
|
|
1947
|
+
* @throws Geolonia のスタイルを API キーなしで使おうとした場合に `Error` を投げます。
|
|
1948
|
+
*
|
|
1949
|
+
* @example
|
|
1950
|
+
* ```typescript
|
|
1951
|
+
* const map = new GeoloniaMap({ container: "#map", apiKey: "YOUR-API-KEY" });
|
|
1952
|
+
* map.setStyle("geolonia/gsi");
|
|
1953
|
+
* ```
|
|
1954
|
+
*/
|
|
1527
1955
|
setStyle(style, options = {}) {
|
|
1528
1956
|
if (style !== null && typeof style === "string") {
|
|
1529
1957
|
style = getStyle(style, { lang: getLang(), apiKey: keyring.apiKey });
|
|
@@ -1532,11 +1960,45 @@ var GeoloniaMap = class extends maplibregl4.Map {
|
|
|
1532
1960
|
super.setStyle.call(this, style, options);
|
|
1533
1961
|
return this;
|
|
1534
1962
|
}
|
|
1963
|
+
/**
|
|
1964
|
+
* 地図を破棄し、関連するリソースやイベントリスナーを解放します。
|
|
1965
|
+
*
|
|
1966
|
+
* MapLibre GL JS の破棄処理に加えて、コンテナ要素に保持している地図インスタンスへの
|
|
1967
|
+
* 参照(`geoloniaMap`)も削除します。これにより、同じコンテナで再度
|
|
1968
|
+
* {@link GeoloniaMap} を生成した際に、破棄済みのインスタンスが返されることを防ぎます。
|
|
1969
|
+
*
|
|
1970
|
+
* @example
|
|
1971
|
+
* ```typescript
|
|
1972
|
+
* const map = new GeoloniaMap({ container: "#map", apiKey: "YOUR-API-KEY" });
|
|
1973
|
+
* // 不要になったら破棄します
|
|
1974
|
+
* map.remove();
|
|
1975
|
+
* ```
|
|
1976
|
+
*/
|
|
1535
1977
|
remove() {
|
|
1536
1978
|
const container = this.getContainer();
|
|
1537
1979
|
super.remove.call(this);
|
|
1538
1980
|
delete container.geoloniaMap;
|
|
1539
1981
|
}
|
|
1982
|
+
/**
|
|
1983
|
+
* 画像を読み込みます。
|
|
1984
|
+
*
|
|
1985
|
+
* `callback` を渡した場合は後方互換のコールバック形式で結果を受け取り、戻り値は
|
|
1986
|
+
* `undefined` になります。`callback` を省略した場合は `Promise` を返します。
|
|
1987
|
+
*
|
|
1988
|
+
* @param url 読み込む画像の URL です。
|
|
1989
|
+
* @param callback 省略可能です。指定した場合はコールバック形式で結果を受け取ります。
|
|
1990
|
+
* @returns `callback` を省略した場合は、読み込んだ画像を含むレスポンスに解決される
|
|
1991
|
+
* `Promise` を返します。`callback` を指定した場合は `undefined` を返します。
|
|
1992
|
+
*
|
|
1993
|
+
* @example
|
|
1994
|
+
* ```typescript
|
|
1995
|
+
* const map = new GeoloniaMap({ container: "#map", apiKey: "YOUR-API-KEY" });
|
|
1996
|
+
* map.on("load", async () => {
|
|
1997
|
+
* const image = await map.loadImage("https://example.com/marker.png");
|
|
1998
|
+
* map.addImage("custom-marker", image.data);
|
|
1999
|
+
* });
|
|
2000
|
+
* ```
|
|
2001
|
+
*/
|
|
1540
2002
|
loadImage(url, callback) {
|
|
1541
2003
|
const promise = super.loadImage(url);
|
|
1542
2004
|
if (callback) {
|
|
@@ -1548,7 +2010,7 @@ var GeoloniaMap = class extends maplibregl4.Map {
|
|
|
1548
2010
|
};
|
|
1549
2011
|
|
|
1550
2012
|
// src/version.ts
|
|
1551
|
-
var VERSION = "0.
|
|
2013
|
+
var VERSION = "0.4.3";
|
|
1552
2014
|
export {
|
|
1553
2015
|
attribution_default as CustomAttributionControl,
|
|
1554
2016
|
GeoloniaControl,
|