角度Google Maps自定义缩放图标

时间:2018-10-18 08:44:58

标签: angular google-maps

我正在使用AGM(角度6),无法找到将放大/缩小图标更改为自定义图标的方法。 AGM本身没有这种选择,应该使用纯JS完成吗?如果是这样,由于控件没有ID或其他类型的标识,该怎么做才能最好?

1 个答案:

答案 0 :(得分:0)

不要考虑覆盖Google Maps控件,而要考虑创建自己的控件并将其粘贴在地图上此处提到的位置:

https://developers.google.com/maps/documentation/javascript/controls#CustomControls

文档很容易说明。从那里得到示例并修改了底部,因此您有了主意

      function CenterControl(controlDiv, map) {

        // Set CSS for the control border.
        var controlUI = document.createElement('div');
        controlUI.style.backgroundColor = '#fff';
        controlUI.style.border = '2px solid #fff';
        controlUI.style.borderRadius = '3px';
        controlUI.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)';
        controlUI.style.cursor = 'pointer';
        controlUI.style.marginBottom = '22px';
        controlUI.style.textAlign = 'center';
        controlUI.title = 'Click to recenter the map';
        controlDiv.appendChild(controlUI);

        // Set CSS for the control interior.
        var controlText = document.createElement('div');
        controlText.style.color = 'rgb(25,25,25)';
        controlText.style.fontFamily = 'Roboto,Arial,sans-serif';
        controlText.style.fontSize = '16px';
        controlText.style.lineHeight = '38px';
        controlText.style.paddingLeft = '5px';
        controlText.style.paddingRight = '5px';
        controlText.innerHTML = 'Center Map';
        controlUI.appendChild(controlText);

        // Setup the click event listeners: simply set the map to Chicago.
        controlUI.addEventListener('click', function() {

          map.setZoom(map.getZoom() + 1 )
          //you would create another div for zoom -1 and call the function from there
          }
      }