結論
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])するコードが組み込まれがちなので、メモとして残しておこうと思いました。