0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【備忘録】OpenLayersでのattribution, rotate, zoomのデフォルト設定への介入方法

0
Posted at

結論

import {Map, View} from 'ol';
import {defaults as defaultControls} from 'ol/control';

const map = new Map({
    target: "map",
    layers: [ /*略*/ ],
    controls: defaultControls({
        attributionOptions: {
            collapsible: true,
            collapsed: false,
            tipLabel: "出典"
        }, 
        zoomOptions: {
            zoomInTipLabel: "詳細",
            zoomOutTipLabel: "広域"
        }
    }),
    view: new View({
        center: fromLonLat([ /*略*/, /*略*/ ]),
        extent: [...fromLonLat([ /*略*/, /*略*/ ]), ...fromLonLat([ /*略*/, /*略*/ ])],
        zoom: 10,
        minZoom: 8,
        maxZoom: 16,
    })
});

MapOptionsオブジェクトのメンバーとしてcontrolを与える際に、
ol/control/defaultsをdefaultControlsと名付けて、
attributionOptions, rotateOptions, zoomOptionsを与えればいいです。

公式サイトのattributions - Examplesにある2つの例では、どちらも、defaultControlsに {attribution: false}を与えてから、.extend([attribution])などと、自前attributionを加える動きになっていますが、自前attributionを管理する手間が余計にかかってます。

なぜ、今更?

生成AIに調べさせると、どうしても公式サイトのExamplesに引っ張られて、defaultControls({attribution: false}).extend([attribution])するコードが組み込まれがちなので、メモとして残しておこうと思いました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?