簡體   English   中英

如何以編程方式擴展/折疊歸因?

[英]How to expand/collapse attributions programmatically?

我添加了一個圖例作為圖例,可以手動對其進行擴展或折疊,但是如何通過編程實現呢?

找到該按鈕,然后單擊它。

var fireClick = function(node) {
  if (typeof MouseEvent === 'function') {
    var mevt = new MouseEvent('click', {
      view: win,
      bubbles: false,
      cancelable: true
    });
    node.dispatchEvent(mevt);
  } else if ( doc.createEvent ) {
    // Fallback
    var evt = doc.createEvent('MouseEvents');
    evt.initEvent('click', false, false);
    node.dispatchEvent(evt);
  } else if (doc.createEventObject) {
    node.fireEvent('onclick') ;
  } else if (typeof node.onclick === 'function' ) {
    node.onclick();
  }
};

var map_element = document.getElementById('map');
var button = map_element.querySelector('div.ol-attribution button');

fireClick(button);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM