Function destroy

  • new Map(id, settings) による地図インスタンスの生成と破棄 — 詳細な使用例

    Returns void

    Warning

    • target に渡す要素は、呼び出し時点で DOM に存在している必要があります。
    • destroy() を呼ぶと以降のメソッド呼び出しは無効になります。
    • AccessInformation を使うコンストラクタは非推奨です。サービスID文字列を使う形式を使用してください。
    • デフォルトでは本番環境からconfigを取得しますが、GIA.config.endpointで取得先を検証環境に変更できます。

    Example: 最小構成で地図を表示する

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

    GIA.config.endpoint = 'https://mapscript.cld.dev.navitime.co.jp/gaia/';

    const map = new GIA.Map('YOUR_SERVICE_ID', {
    target: '#map',
    center: new GIA.value.LatLng(35.6895, 139.6917),
    zoomLevel: 12,
    options: {
    antialias: true,
    }
    });

    Example: 特別な理由がない限りウィンドウリサイズ・回転と傾きにも対応させる

    map.setMapRotationEnabled(true);
    map.setMapTiltEnabled(true);
    map.setMaxTilt(45);

    const target = document.querySelector('#map');
    const resizeMapEvent = () => {
    const height = target.clientHeight;
    const width = target.clientWidth;
    map.setClientSize(new GIA.value.Size(height, width));
    };
    window.addEventListener("resize", resizeMapEvent);
    window.addEventListener("orientationchange", resizeMapEvent);

    Example: ページ離脱時にリソースを解放する

    window.addEventListener('beforeunload', () => {
    map.destroy();
    });

    See

    destroy