Function setCenterMarkerCondition

  • 十字マーカー(センターマーカー)の表示オプションを設定する — 詳細な使用例

    地図の中心に常に表示される十字マーカー(センターマーカー)を設定します。 住所入力フォームと組み合わせた「ドラッグで位置を選択する」UIや、 中心座標をリアルタイムに取得するインタラクションに使います。

    Returns void

    Warning

    • setCenterMarkerCondition は一度に一条件のみ有効です。再設定すると上書きされます。
    • clearCenterMarkerCondition でマーカーを非表示にできます。
    • センターマーカーは地図のビューポート中心に固定されたアイコンです。LatLng は不要です。
    • CenterMarkerConditionicon ではなく、color / accentColor / width / length / position を指定します。

    Example: 緑系の十字マーカーを target に表示し、必要時に表示/非表示を切り替える

    import * as GIA from '@ntj/gaia';

    const centerMarkerCondition = new GIA.value.CenterMarkerCondition({
    color: GIA.value.Color.fromColorCodeSixHex('006400') ?? GIA.value.Color.black(),
    width: 2,
    length: 10,
    position: 'target',
    });

    map.setCenterMarkerCondition(centerMarkerCondition);

    // 地図移動完了時に中心座標を取得
    map.addEventListener('moveend', () => {
    const center = map.getCenter();
    console.log('現在の中心:', center.lat, center.lng);
    });

    // 表示を外す
    map.clearCenterMarkerCondition();

    // 必要なタイミングで再表示
    map.setCenterMarkerCondition(centerMarkerCondition);

    See