代码
import * as mapvthree from '@baidumap/mapv-three';

mapvthree.BaiduMapConfig.ak = '您的密钥';

const engine = new mapvthree.Engine(document.getElementById('map'), {
  map: {
    provider: new mapvthree.BaiduVectorTileProvider(),
    center: [120.145, 30.248],
    range: 3600,
    pitch: 0,
  },
  widgets: {
    copyright: {
      enabled: true,
      copyrights: [
        {
          id: 'example',
          content: '西湖 · 示例场景',
        },
      ],
    },
  },
});

const copyright = engine.widgets.copyright;
const toggle = document.getElementById('toggle-source');
const source = {id: 'source', content: '数据来源:百度矢量地图'};

toggle.addEventListener('click', () => {
  const visible = Boolean(copyright.getCopyright(source.id));
  if (visible) {
    copyright.removeCopyright(source.id);
  } else {
    copyright.addCopyright(source);
  }
  toggle.setAttribute('aria-pressed', String(!visible));
  toggle.textContent = visible ? '显示数据来源' : '隐藏数据来源';
});

用 copyrights 设置版权条目。点击按钮,在运行时添加或移除演示数据来源。

预览